資源描述:
《第八講、matlab符號運算》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、第八講MATLAB符號運算8.1設(shè)置符號變量8.2微分積分運算8.3方程求解8.4線性代數(shù)運算8.5其它命令1、設(shè)置符號變量(sym,syms)S=sym(‘A’)x=sym('x')symsarg1arg2...2、微分積分運算(1)微分diff(S,'v')(s對變量v求偏導(dǎo))diff(S,n)(對s求n次導(dǎo))diff(S,'v',n)(s對變量v求n次偏導(dǎo))例1:>>symsxa>>y=sin(a*x)/xy=sin(a*x)/x>>diff(y)ans=cos(a*x)*a/x-sin(a
2、*x)/x^2>>diff(y,2)ans=-sin(a*x)*a^2/x-2*cos(a*x)*a/x^2+2*sin(a*x)/x^3>>diff(y,a)ans=cos(a*x)>>diff(y,a,2)ans=-sin(a*x)*x(2)積分R=int(S)R=int(S,v)R=int(S,a,b)R=int(S,v,a,b)例2:>>symsxt>>y=exp(t*x)y=exp(t*x)>>int(y)ans=1/t*exp(t*x)>>int(y,t)ans=1/x*exp(t*x
3、)>>int(y,0,1)ans=(exp(t)-1)/t>>int(y,t,0,1)ans=(exp(x)-1)/x>>z=exp(-x^2)z=exp(-x^2)>>int(z)ans=1/2*pi^(1/2)*erf(x)>>int(z,0,inf)ans=1/2*pi^(1/2)>>int([xsin(x);cos(x)t*x^2])ans=[1/2*x^2,-cos(x)][sin(x),1/3*t*x^3](3)極限limit(F,x,a)limit(F,a)(x->a時F的極限)li
4、mit(F)(x->0時F的極限)limit(F,x,a,'right')limit(F,x,a,'left')例3:>>symsxah>>limit(sin(x)/x)ans=1>>limit(1/x,x,0,'left')ans=-Inf>>limit(1/x,x,0,'right')ans=Inf>>limit((sin(x+h)-sin(x))/h,h,0)ans=cos(x)(4)級數(shù)和symsum(s,t,a,b)s中t從a到b求和。例4:>>symsxn>>symsum(x^2,x,
5、1,n)ans=1/3*(n+1)^3-1/2*(n+1)^2+1/6*n+1/63、方程求解(1)代數(shù)方程(solve)g=solve(eq)g=solve(eq,var)g=solve(eq1,eq2,...,eqn)g=solve(eq1,eq2,...,eqn,var1,var2,...,varn)例5:solve('a*x^2+b*x+c')ans=[1/2/a*(-b+(b^2-4*a*c)^(1/2)),1/2/a*(-b-(b^2-4*a*c)^(1/2))]solve('a*x^
6、2+b*x+c','b')ans=-(a*x^2+c)/x>>S=solve('x+y=1','x-11*y=5')S=x:[1x1sym]y:[1x1sym]>>S.xans=4/3>>S.yans=-1/3>>A=solve('a*u^2+v^2','u-v=1','a^2-5*a+6')A=a:[4x1sym]u:[4x1sym]v:[4x1sym]>>A.aans=2233>>A.uans=1/3+1/3*i*2^(1/2)1/3-1/3*i*2^(1/2)1/4+1/4*i*3^(1/2
7、)1/4-1/4*i*3^(1/2)>>A.vans=-2/3+1/3*i*2^(1/2)-2/3-1/3*i*2^(1/2)-3/4+1/4*i*3^(1/2)-3/4-1/4*i*3^(1/2)(2)微分方程(dsolve)r=dsolve('eq1,eq2,...','cond1,cond2,...','v')r=dsolve('eq1','eq2',...,'cond1','cond2',...,'v')例6:>>dsolve('Dy=a*y')ans=C1*exp(a*t)>>dsolv
8、e('Dy=a*y','y(0)=b')ans=b*exp(a*t)>>dsolve('Df=f+sin(t)')ans=-1/2*cos(t)-1/2*sin(t)+exp(t)*C1>>dsolve('Df=f+sin(m)')ans=-sin(m)+exp(t)*C1>>dsolve('(Dy)^2+y^2=1','s')ans=1-1sin(s-C1)-sin(s-C1)>>dsolve('(Dy)^2+y^2=1')ans=1-1sin(t-C1)-sin(t-C1)>>