limit(function):求函数在0时候的极限值
>> limit((x^3+1)/(x^4+2))
ans =
1/2
注意:limit命令属于符号计算领域,因此需要使用syms命令知名使用的时那些符号变量
limit(function,a):计算变量在趋于a时的极限值
inf:正无穷
-inf:负无穷
>> limit((x^3+1)/(x^4+2),4)
ans =
65/258
>> limit((x^3+1)/(x^4+2),inf)
ans =
0
>> limit((x^3+1)/(x^4+2),-inf)
ans =
0
limit(function,x,a,'left'):左极限
limit(function,x,a,'right'):右极限
>> limit((x-3)/abs(x-3),x,3,'left')
ans =
-1
>> limit((x-3)/abs(x-3),x,3,'right')
ans =
1
渐近线:
>> syms x;
>> y=1/(x*(x-1));
>> ezplot(y)
>> g=x*(x-1);
>> s=solve(g)
s =
0
1
>> ezplot(1/g,'--')>> ezplot(1/g)
>> hold on
>> plot(double(s(1))*[1 1],[-1 2],'--')
>> hold on
plot(double(s(1))*[0 0],[-1 2],'--')
>> hold on
plot(double(s(2))*[1 1],[-1 2],'--')因为根存储在名为s的变量中,可以通过访问s(1)和s(2)来表达它们,范围s(2)*[1 1]表示绘制的x范围,[-1 2]表示绘制的y范围
diff(function):计算导数,默认计算一阶导数
diff(function,n):计算n阶导数
>> syms x t;
>> f=x^2;
>> g=sin(10*t);
>> diff(f)
ans =
2*x
>> diff(g)
ans =
10*cos(10*t)
>> diff(f,2)
ans =
2
diff返回计算导数的结果,因此我们可以将结果分配给以后可以使用的另外一个变量。
>> f=x^2;
>> g=diff(f)
g =
2*x
>> h=-g+2*x
h =
0
isequal(f1,f2):检验两个方程是否相等,是返回’1‘,否则返回’0‘
>> f=2*x;
>> g=2;
>> isequal(f,g)ans =
logical
0
pretty(function):可以使得到的表达式看起来更加漂亮
>> f=x^3-3*x^2+3*x;
>> ezplot(f)
>> g=diff(f)
g =
3*x^2 - 6*x + 3
>> pretty(g)
2
3 x - 6 x + 3>> s=solve(g)
s =
1
1
subs(function,c):当变量等于c时,函数function得到的值
求函数的极值
>> syms x;
>> f=x^4-2*x^3;
>> ezplot(f)
>> hold on
>> g=diff(f);
>> ezplot(g)
>> s=solve(g)
s =
0
0
3/2
>> h=diff(g)
h =
12*x^2 - 12*x
>> a=subs(h,s(1))
a =
0
>> a=subs(h,s(3))
a =
9
>> plot(double(s(1)),double(subs(f,s(1))),'ro')-------------在(3/2,f(3/2))处放一个小红圈
>> text(0.8,3.2,'local minimum')
dsolve('eqn):求解微分方程--返回具有一组任意常数的符号解
dsolve('eqn','cond1','cond2'):可以设置初始值
当使用dsolve时,导数用D表示
>> Df=-2*f+cos(t)
>> D2y+2Dy=5*sin(7*y)
diff(f,t):函数f对t求一阶导
>> syms y(t) a;
>> eqn=diff(y,t)==a*y;
>> s=dsolve(eqn)
s =
C1*exp(a*t)
假设我们要得到C1和a的不同值方程,可以通过subs来赋值
>> C1=2;a=4;
>> f=subs(s)
f =
2*exp(4*t)
初始条件输入
>> syms y(t) t;
eqn=diff(y,t)==(t/(t-5))*y;
>> cond=[y(0)==2];
>> s=dsolve(eqn,cond)
s =
-(2*exp(t + 5*log(t - 5)))/3125
解含有初始条件的二阶微分方程:
>> syms y(t) t;
eqn=diff(y,t,2)-y==0;
>> Dy=diff(y,t);
>> cond=[y(0)==-1,Dy(0)==2];
>> s=dsolve(eqn,cond)
s =
exp(t)/2 - (3*exp(-t))/2
>> syms y(t) t;
>> eqn=diff(y,t)==t+3;
>> cond=[y(0)==7];
>> s=dsolve(eqn,cond)
s =
(t*(t + 6))/2 + 7
>> ezplot(s,[0 10])
asymptotes:渐近线
>> syms y(t) t;
>> eqn=diff(y,t)==y^2;
>> cond=[y(0)==1];
>> s=dsolve(eqn,cond)
s =
-1/(t - 1)
>> ezplot(s)
>> hold on
>> q=diff(s)
q =
1/(t - 1)^2>> plot([1 1],[-2 2],'--')-------------绘制渐近线
>> syms f(x) x;
eqn=diff(f,x,2)-((sin(x))/x)*(1-2/x^2)-(2*cos(x))/x^2==0;
Df=diff(f,x);
>> cond=[f(0)==2,Df(0)==0];
>> s=dsolve(eqn,cond)
s =
3 - sin(x)/x>> ezplot(s,[-50,50])
>> syms y(t) t;
eqn=diff(y,t)==-y/sqrt(1-t^2);
s=dsolve(eqn)
s =
C1*exp(-asin(t))
>> C1=0;
>> s1=subs(s,'C1',0)
s1 =
0
>> ezplot(s1)
>> hold on
>> s2=subs(s,'C1',10)
s2 =
10*exp(-asin(t))
>> ezplot(s2,[-1,1])
>> hold on
>> s3=subs(s,'C1',20)
s3 =
20*exp(-asin(t))
>> ezplot(s3,[-1 1])
>> legend(s1,s2,s3)
错误使用 legend (第 272 行)
参数无效。有关详细信息,请键入 'help legend'。
>> legend('s1','s2','s3')
用for循环来表示三种不同的情况
>> syms y(t) t;
eqn=diff(y,t)==-y/sqrt(1-t^2);
s=dsolve(eqn)
s =
C1*exp(-asin(t))
>> for i=0:10:20
f=subs(s,'C1',i);
ezplot(f,[-1 1])
hold on
end
>> legend('s1','s2','s3')
for i=a:b:c
a是起始值,b是增量,c是最终值
>> syms y(t) t;
eqn=diff(y,t)==-2*t*y^2;
for i=0.2:0.2:2.0
cond=[y(0)==i];
s=dsolve(eqn,cond);
ezplot(s)
hold on
end