1.极限计算
syms x
limit((x^3 + 1)/(x^4 + 2))//求趋近于0是函数极限
ans =1/2
limit(x + 5,3)//求函数x+5趋近于3是函数极限
ans =8
limit(sqrt(x^2+x)-x,inf)//求趋近于正无穷函数极限
ans =1/2
(1)左极限和右极限
syms x;
f = (x - 3)/abs(x - 3);
ezplot(f,[-1,5])//绘图便于观察
a = limit(f,x,3,‘left’)//求趋近于3的左极限
a =-1
b = limit(f,x,3,‘right’)//求趋近于3的右极限
b =1
(2)获得渐近线
y =1/(x(x - 1))
渐近线非常清楚——函数在 x=0 和 x=1 变化非常快速
syms x
f = 1/(x*(x-1));
ezplot(f)//绘制图像
g = x*(x-1);//将分母赋值给g
s = solve(g);//求解函数g
s = 0
1
ezplot(1/g)//绘制函数f图像
hold on//开启同一坐标轴绘制
plot(double(s(1))*[1 1], [-1 2],‘–’)//绘制渐近线s(1)
plot(double(s(2))*[1 1], [-1 2],‘–’)//绘制渐近线s(1)
hold off//关闭同一坐标绘制
2.导数计算
syms x t
f = x^2;
diff(f)//对函数f求导
ans = 2*x
syms t
f = texp(-3t);
diff(f,2)//对函数f求二阶导数
ans =-6exp(-3t)+9texp(-3*t)
3.dsolve命令
当使用 dsolve 时,导数用 D 指示,更高阶的导数我们能过在 D 后面带上阶数数字来表示。
y’’ + 2y’ = 5sin7x
我们将写成:‘D2y + 2Dy = 5sin(7x)’
4.常微分方程(ODE)求解
s = dsolve('Dy=ay’)//求解微分方程Dy=ay
s =C1exp(at)
C1 = 2; a = 4;
f = subs(s)//参数代入
f =2exp(4t)
dsolve(‘D2y - y = 0’,‘y(0) = -1’,‘Dy(0) = 2’) //求解二阶微分方程
ans =-3/2exp(-t)+1/2exp(t)
微分方程渐近线求解举例:
s = dsolve(‘Dy = y^2’,‘y(0) = 1’)
s =-1/(t-1)
渐近线落在:
d = -1/s
d =t-1
roots = solve(d)
roots =1
现在我们绘制并保留:
ezplot(s);//绘制函数s
hold on//开启同一坐标绘制图像
现在绘制渐近线:
plot(double(roots)*[1 1], [-2 2],‘–’)//渐近线绘制
hold off//关闭同一坐标绘制图像
5.方程组和相平面图
s = dsolve(‘DX = Y’,‘DY = -X’,‘X(0)= -1’,‘Y(0)=2’);//求解微分方程组
s.X
ans =-cos(t)+2*sin(t)
s.Y
ans =sin(t)+2*cos(t)
ezplot(s.X) ;//绘制s.X图像
hold on
ezplot(s.Y);//绘制s.Y图像
hold off
ezplot(s.X),set(findobj(‘Type’,‘line’),‘Color’,‘r’);//将曲线用红色绘制
hold on
ezplot(s.Y)
h=get(gca,‘children’);//返回当前图形对象的句柄
set(h(1),‘linestyle’,‘–’);//将图像的线形改为–