中南大学材料学院MATLAB题库答案30版(共57页)_第1页
中南大学材料学院MATLAB题库答案30版(共57页)_第2页
中南大学材料学院MATLAB题库答案30版(共57页)_第3页
中南大学材料学院MATLAB题库答案30版(共57页)_第4页
中南大学材料学院MATLAB题库答案30版(共57页)_第5页
已阅读5页,还剩58页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、P.28 ex 2.1 数值变量(binling)的运算 format short e clear muw0=1.785e-3; a=0.03368; b=0.000221; t=0:20:80; muw=muw0./(1+a*t+b*t.2)muw = 1.7850e-003 1.0131e-003 6.6092e-004 4.6772e-004 3.4940e-004p.31 ex 2.2 数值(shz)驻足和字符串转换 a=1:5; b=num2str(a); aa = 1 2 3 4 5 bb =1 2 3 4 5 b*2ans =98 64 64 100 64 64 102 64 6

2、4 104 64 64 106P.44 ex 2.9 比较用左除和右除分别求解恰定方程(线性方程组如果方程数等于未知数个数,叫做恰定方程组,如果方程多于未知数,叫做超定方程组,反之称为(chn wi)欠定。换个角度说,系数矩阵如果是方阵,就是恰定方程组)的解见课本P.48 ex 2.14 计算矩阵的指数 并比较不同函数的结果 b=magic(3); expm(b)ans = 1.0e+006 * 1.0898 1.0896 1.0897 1.0896 1.0897 1.0897 1.0896 1.0897 1.0897 expmdemo2(b)ans = 1.0e+006 * 1.0898 1

3、.0896 1.0897 1.0896 1.0897 1.0897 1.0896 1.0897 1.0897 expm1(b)ans = 1.0e+003 * 2.9800 0.0017 0.4024 0.0191 0.1474 1.0956 0.0536 8.1021 0.0064 expmdemo3(b)ans = 1.0e+006 * 1.0898 1.0896 1.0897 1.0896 1.0897 1.08971.0896 1.0897 1.0897P50 ex 2.18 计算(j sun)矩阵(j zhn)的特征值条件数 a=rand(3)a = 0.9649 0.9572 0.

4、1419 0.1576 0.4854 0.4218 0.9706 0.8003 0.9157 V,D,s=condeig(a)V = 0.4913 0.6696 0.6696 0.3158 -0.4476 + 0.2831i -0.4476 - 0.2831i 0.8117 -0.2332 - 0.4655i -0.2332 + 0.4655iD = 1.8146 0 0 0 0.2757 + 0.3061i 0 0 0 0.2757 - 0.3061is = 1.1792 1.2366 1.2366P62 ex 2.29矩阵(j zhn)的抽取、三角(snjio)抽取 a=pascal(4)

5、a = 1 1 1 1 1 2 3 4 1 3 6 10 1 4 10 20 diag(a,-2)ans = 1 4 v=diag(diag(a)v = 1 0 0 0 0 2 0 0 0 0 6 0 0 0 0 20%diag简单(jindn)来说就是抽取矩阵各对角线上的元素,如上是抽取(chu q)主对角线以下第二条对角线之元素(yun s),其另一功能是建立对角矩阵 tril(a)ans = 1 0 0 0 1 2 0 0 1 3 6 0 1 4 10 20 triu(a)ans = 1 1 1 1 0 2 3 4 0 0 6 10 0 0 0 20%triu&tril用法与diag非常

6、类似,用途是提取下、上三角矩阵P62 ex2.30 建立多项式之伴随矩阵这道题有点凌乱了.求解释P64 ex 2.31 数组的幂运算 a=2 1 -3 -1;3 1 0 7;-1 2 4 -2;1 0 -1 5; a3ans = 32 -28 -101 34 99 -12 -151 239 -1 49 93 8 51 -17 -98 139 a.3ans = 8 1 -27 -1 27 1 0 343 -1 8 64 -8 1 0 -1 125P66 ex 2.32 数组之逻辑运算 a=1:3;4:6;7:9; b=0 1 0;1 0 1;0 0 1; x=5;y=ones(3)*5; x a

7、b=a&bab = 0 1 0 1 0 1 0 0 1%此处为与运算,就是同真才为真(同为非零数) bans = 1 0 1 0 1 0 1 1 0%逻辑非运算,即全都非,真变假假变真;还有逻辑或运算,看下面即懂: a|bans = 1 1 1 1 1 1 1 1 1%总结多项式运算的函数:poly: Polynomial with specified roots特征多项式的生成p=poly(a)a为n阶特征矩阵,所得一般为n阶特征多项式;poly2sym数值2符号;polyval 求多项式的值;roots 求多项式的根;conv 多项式的乘法(向量之卷积)conv(p,d);polyder

8、多项式微分;polyfit 多项式拟合。P71 ex 2.41 多项式拟合(n h),用5阶多项式对正弦(zhngxin)函数进行(jnxng)最小二乘拟合 x=0:pi/20:pi/2; y=sin(x); a=polyfit(x,y,5); x1=0:pi/30:pi*2; y1=sin(x1); y2=a(1)*x1.5+a(2)*x1.4+a(3)*x1.2+a(4)*x1.2+a(5)*x1+a(6); plot(x,y,b-,x1,y2,r*) legend(原曲线,拟合曲线) axis(0,7,-1.2,4) axis(0,7,-1.2,1.5) %调整坐标轴显示范围 2.符号运

9、算命名和基本运算法则P 79 符号矩阵的运算 A=sym(a,b;c,d) A = a, b c, d syms a b c d B=a,b;c,d B = a, b c, d B-A ans = 0, 0 0, 0 A/B ans = 1, 0 0, 1 A2 ans = a2 + b*c, a*b + b*d a*c + c*d, d2 + b*c A.2 ans = a2, b2 c2, d2 det(A) ans = a*d - b*c %行列式 inv(A) ans = d/(a*d - b*c), -b/(a*d - b*c) -c/(a*d - b*c), a/(a*d - b*

10、c) %逆 rank(A) ans = 2%秩%SUMMARY 矩阵(j zhn)的分解:奇异(qy)值分解 U,S,V=svd(A);特征值分解(fnji)V,D=eig(A);正交分解Q,R=qr(A);三角分解L,U=lu(A);P88 ex 3.7 利用函数gradient绘制一个矢量图 x,y=meshgrid(-2:.2:2,-2:.2:2); z=x.*exp(-x.2-y.2); px,py=gradient(z,.2,.2); contour(z),%等高线绘制(huzh)函数 hold on quiver(px,py)%矢量图绘制(huzh)函数 %绘图(hu t)SUMM

11、ARY 1.二维plot 不解释;fplot:绘制y=f(x)图形 fplot(fname,lims,s);ezplot:绘制隐函数图形 help吧;极坐标polar,对数坐标semilogx,semilogy,loglog;bar 条形图,pie饼状图;hist 直方图 有些疑惑!;grid on/off:控制是否画网格线。box on/off: 控制是否加边框线。hold on/off 控制是否刷新当前轴及图形%2.三维:plot3; meshgrid函数:产生平面区域内的网格坐标矩阵;mesh 画格子;surf 面;figure(n)开窗户;subplot:割图。3.二维图形函数运用P9

12、8 基本绘图命令 y=rand(100,1); plot(y) x=rand(100,1); z=x+y.*i; plot(z) P101 ex4.1 绘制带有显示属性的二维属性 x=1:0.1*pi:2*pi; y=sin(x); z=cos(x); plot(x,y,-k,x,z,-.rd) P104 ex4.5 条状图和矢量图 x=1:10; y=rand(10,1); bar(x,y) x=0:0.1*pi:2*pi; x=0:0.1*pi:2*pi; y=x.*sin(x); feather(x,y) P104 ex4.6 函数图形绘制 lim=0,2*pi,-1,1; fplot(

13、sin(x),cos(x),lim) P105 ex 4.7 绘制饼状图 x=2,4,6,8; pie(x,math,english,chinese,music) 4.三维图形(txng)函数应用P107 ex4.9 绘制(huzh)三维螺旋线 x=0:pi/50:10*pi; y=sin(x);z=cos(x); plot3(x,y,z) P107 ex 4.10 绘制参数(cnsh)为矩阵的三维图 x,y=meshgrid(-2:0.1:2,-2:0.1:2); z=x.*exp(-x.2-y.2); plot3(x,y,z) P109 ex 4.11 使用mesh函数绘制三维面图 x=-

14、8:0.5:8;y=x; a=ones(size(y)*x; b=y*ones(size(x); c=sqrt(a.2+b.2)+eps; z=sin(c)./c; mesh(z) P110 ex4.13 meshc函数绘制的三维面图 X,Y=meshgrid(-4:0.5:4); Z=sqrt(X.2+Y.2); meshc(Z) P111 ex 4.16 绘制三维饼状图 clear x=2,4,6,8; pie(x) pie(x,0,0,1,0) pie3(x,0,0,1,0) pie3(x,0,0,1,1) P113 ex 4.19 绘制如图柱面图 x=0:pi/20:pi*3; r=5

15、+cos(x); a,b,c=cylinder(r,30); mesh(a,b,c) P113 ex 4.20 绘制(huzh)地球表面的气温分布示意图 a,b,c=sphere(40); t=abs(c); surf(a,b,c,t); axis(equal) axis(square) colormap(hot) 5.图形控制命令(mng lng)P118 ex 4.24 坐标标注(bio zh)函数应用 x=1:0.1*pi:2*pi; y=sin(x);plot(x,y) xlabel(x(0-2pi) ylabel(y=sin(x) title(正弦函数,FontSize)Error

16、using title (line 29)Incorrect number of input argumentsError in title (line 23) h = title(gca,varargin:); title(正弦函数,FontSize,12) title(正弦函数,FontSize,12,FontWeight,bold) %课本上不知由于版本问题还是什么,与2011b不同,最后尝试用Bold成功解决 ADD 已解决,用单引号引起bold即可Undefined function or variable bold. title(正弦函数,FontSize,12,FontWeigh

17、t,Bold)Undefined function or variable Bold. title(正弦函数,FontSize,12,FontWeight,Bold) title(正弦函数,FontSize,12,FontWeight,Bold,FontName,隶书) P123 ex 4.30 在同一张途中绘制几个三角函数图 x=0:0.1*pi:2*pi; y=sin(x); z=cos(x); plot(x,y,-*) hold on plot (x,z,-o) plot(x,y+z,-+) legend(sin(x),cos(x),sin(x)+cos(x),0) P124 ex 4.

18、31 在4个子图中绘制不同的三角函数 x=0:0.1*pi:2*pi; subplot(2,2,1); plot(x,sin(x),-*) title(sin(x) subplot(2,2,2) plot(x,cos(x),-o) title(cos(x) subplot(2,2,3) plot(x,sin(x).*cos(x),-x) title(sin(x)*cos(x) subplot(2,2,4) plot(x,sin(x)+cos(x),-h) title(sin(x)+cos() title(sin(x)+cos(x) % SUMMARY interp1:1-D data inte

19、rpolation (table lookup) % yi = interp1(x,Y,xi,method,extrap) method:nearest/linear/echip(hermite)/spline,etcP222 ex 7.3 正弦曲线的插值实例(shl) x=0:0.05:10; y=sin(x); xi=0:.125:10; yi=interp1(x,y,xi);%一维插值 plot(x,y,*,xi,yi)P227 例7.7二次拟合(n h) x=0.5:0.5:3.0; y=1.75 2.45 3.81 4.80 8.00 8.60; a=polyfit(x,y,2)%用

20、最小二乘法(chngf)拟合a = 0.4900 1.2501 0.8560 x1=0.5:0.05:3.0; y1=a(1)*x1.2+a(2)*x1+a(3);%拟合(n h)出的函数 plot(x1,y1,-or,x,y,-+b)P228 例7.8拟合(n h),用求解(qi ji)矩阵的方法解,求解超定方程 xi=19:6:44xi = 19 25 31 37 43 yi=19.0 32.3 49.0 73.3 98.8; format short a=polyfit(xi,yi,2)a = 0.0635 -0.5932 7.2811 x1=19:.1:44; y1=a(1)*x1.2

21、+a(2)*x1+a(2);%此处发生了一点错误,将a(3)误输为a(2),后面会有改正 plot(x1,y1,-x) plot(x1,y1,-) x2=xi.2;%采用(ciyng)求解矩阵的方法来求解此拟合(n h)问题(wnt) x2=ones(5,1),x2x2 = 1 361 1 625 1 961 1 1369 1 1849 ab=x2yiab = -1.3522 0.0540 y3=ab(1)+ab(2)*x1.2; hold on;plot(x1,y3,-g) y1=a(1)*x1.2+a(2)*x1+a(3); plot(x1,y1,-)%从图中可以看出,两种拟合方法较为吻合

22、P233 例7.10 分别用矩形和梯形公式求积分 y=inline(exp(-0.5*t).*sin(t+pi/6);%内联函数 d=pi/1000; t=0:d:3*pi; nt=length(t)nt = 3001 y1=y(t); sc=cumsum(y1)*d; scf=sc(nt)scf = 0.9016 format long scfscf = 0.901618619310013%矩形(jxng)方法 z=trapz(y1)*dz = 0.900840276606885%梯形(txng)方法(fngf)P237 ex7.11 采用自适应Simpson公式求积分 f=inline(x

23、./(x.2+4); quad(f,0,1)ans = 0.111571765994935P237 ex 7.12 用quadl求积分 f=inline(exp(-x/2); f1=quadl(f,1,3)f1 = 0.7668 f2=quad(f,1,3,1e-10)f2 =0.7668 format long e f1f1 = 7.668009991284686e-001 f2f2 =7.668009991284349e-001P237 7.12 quadl gauss-labatto 求积分(jfn) quadl(exp(-x/2),1,3)ans = 0.7668%求线性方程组的方法(

24、fngf)一般有两种:左除求法和linsolve求法P246 ex 7.17 求线性方程组 a=rand(4,4);%生成(shn chn)随机矩阵 b=rand(4,1); x=abx = 1.728190838792039e+001 8.395388076704506e-001 -1.590669694986821e+0011.088276299038511e+000%此处与书上不同,为生成的随机矩阵%SUMMARY矩阵左除 AB =A-1* B 等效于A*X=B求X inv(A) 注:.数组左除 A.B Bij/Aij ; /:矩阵右除 A/B =A*B-1 等效于X*B=A求X for

25、mat short x1=linsolve(a,b)%SUMMARY用linsolve求解线性方程;用solve use for linear function/fzero求解非线性方程;Dsolve Ordinary differential equation and system solver,用dsolve求解微分方程;fsolve Solve system of nonlinear equations, x,fval = fsolve(myfun,x0,options) % Call solverx1 = 17.2819 0.8395 -15.9067 1.0883P246 ex 7.

26、18 对矩阵(j zhn)进行(jnxng)LU分解(fnji) A=ones(4,4)A = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 l,u=lu(A)l = 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1u = 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 l*uans = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1P265 ex 7.39 求方程组之符号解 x1,x2=solve(x1-0.7*sin(x1)-0.2*cos(x2)=0,x2-0.7*cos(x1)+0.2*sin(x2)=0) x1 = 0.

27、52652262191818418730769280519209 x2 = 0.50791971903684924497183722688768 x1=solve(x1-0.7*sin(x1)-0.2*cos(x2)=0,x2-0.7*cos(x1)+0.2*sin(x2)=0)x1 = x1: 1x1 sym x2: 1x1 sym x1.x1 ans = 0.52652262191818418730769280519209 x1.x2 ans = 0.50791971903684924497183722688768%方法(fngf)一:用solve求符号解,注意(zh y)使用x1,x2方

28、式(fngsh)调用才可求得具体数值 另有不动点迭代法和newton法,见课本p263editfc.mfunction f=fc(x)f(1)=x(1)-0.7*sin(x(1)-0.2*cos(x(2);f(2)=x(2)-0.7*cos(x(1)+0.2*sin(x(2);f=f(1) f(2);%编写m文件 x0=0.5 0.5; fsolve(fc,x0)Equation solved.fsolve completed because the vector of function values is near zeroas measured by the default value o

29、f the function tolerance, andthe problem appears regular as measured by the gradient.ans = 0.5265 0.5079%用fsolve求解(qi ji),显然(xinrn)麻烦(m fan)很多P273 ex 7.42 微分方程数值解f=inline(-y+x+1); x,y=ode23(f,0,1,1)x = 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000y = 1.0000 1.0048 1.0187 1.

30、0408 1.0703 1.1065 1.1488 1.1966 1.2493 1.3066 1.3679 plot(x,y)%ode、euler等方法都是数值法求解微分方程 x1,y1=ode45(f,0,1,1); plot(x,y,-*r,x1,y1,-o)P273 ex 7.45 R-K法求解(qi ji)微分方程(wi fn fn chn) f=inline(-2*y+2*x.2+2*x)f = Inline function: f(x,y) = -2*y+2*x.2+2*x x,y=ode23(f,0,.5,1);%此处定义域可再取大一些(yxi) plot(x,y)P274 ex

31、 7.46 求解刚性方程fgang.mfunction f=fgang(x,y)f=-2 0;998 -999*y+2*sin(x);999*(cos(x)-sin(x); ode23(fgang,0 10,2,3); %此题略神奇,记下吧%自己做的命令function f=rk15s(x,y)f=zeros(2,1);f(1)=-2*y(1)+y(2)+2*sin(x);f(2)=998*y(1)-999*y(2)+999*(cos(x)-sin(x); ode15s(rk15s,0 10,2,3)P275 ex 7.47 求常微分方程(wi fn fn chn)符号(fho)解 a=dso

32、lve(Dy=y+sin(t),y(pi/2)=0) a = exp(t)/(2*exp(pi/2) - sin(t)/2 - cos(t)/2%subs 代入数值(shz)至函数p307 ex 9.21 检验三台机器生产的铝合金报班有无显著性差异(方差分析) x=.236 .238 .248 .245 .243;.257 .253 .255 .254 .261;.258 .264 .259 .267 .262; a=anova1(x)a = 1.3431e-005 %anova1为单因素试验的方差分析,此处a的大小,是原假设均值相等的几率P308 9.22 用三种(sn zhn)火箭推进器、

33、四种燃料(rnlio)做射程实验,每种推进器和燃料(rnlio)的组合各发射火箭两次,考察推进器和燃料对射程是否有显著影响 A=58.2 56.2 65.3;52.6 41.2 60.8;49.1 54.1 51.6;42.8 50.5 48.4;60.1 70.9 39.2;58.3 73.2 40.7;75.8 58.2 48.7;.71.5 51 41.4; anova2(A,2)ans = 0.0035 0.0260 0.0001%见课本,课本中直接输入为8x3的矩阵,使用anova2来求解,题目中的两次发射表现在anova(a,2)中的数字2,意为:行列对所拥有的观察点数,即题中所说

34、的发射几次火箭。返回值有三个,老师讲是:第一个:第一种影响因子的原假设均值相等的几率;第二种同理;第三种是二者之乘积P309 ex 9.23 回归分析,研究温度对产品得率之影响,做y=a+bx型之回归%其实就是拟合 x=100:10:190; y=45 51 54 61 66 70 74 78 85 89; a,b=polyfit(x,y,1)a = 0.4830 -2.7394b = R: 2x2 double df: 8 normr: 2.6878 f=a(1)*x+a(2); plot(x,y,or,x,f,-g)操作题 43 积分(jfn)的符号(fho)法和数值法 syms x in

35、t(log10(1+x),0,1) ans = (log(4) - 1)/log(10) double(ans)ans =0.1678%符号(fho)法,使用int语句积分,功能强大 f=inline(log10(x+1); quad(f,0,1)ans = 0.1678%用quad语句对于简单的积分十分方便 x=0:.01:1; f=log10(x+1); ff=trapz(x,f)ff = 0.1678%用trapz梯形(txng)积分,用quad进行自适应(shyng)辛卜生法,用quad8进行(jnxng)Neton-cotes法,gauss-labatto:quadl,二重积分 I=

36、dblquad(fname,xmin,xmax,ymin,ymax,tol ,trace),三重积分:I = triplequad(fun,xmin,xmax,ymin,ymax,zmin,zmax,tol)操作题 44多阶常微分 用ode23、ode45、ode113求y.mfunction y=y(x,y)dy=zeros(3,1)dy(1)=y(2)dy(2)=y(3)dy(3)=2*y(3)/x3+3*y(2)/x3+3*exp(2*x)/x3x23,y23=ode23(y,1,10,1 10 30);x45,y45=ode45(y,1,10,1 10 30);x113,y113=od

37、e113(y,1,10,1 10 30);plot(x23,y23,-xb,x45,y45,-+g,x113,y113,-or)操作题45 求方程的根 fzero(x.2+x-1,0.5)ans = 0.6180%fzero: Find root of continuous function of one variable. 格式(g shi):x = fzero(fun,x0);x0可以(ky)是某个数值(shz),也可以是定义域;roots是求多项式的,也可以用来求本题 c=1 1 -1; roots(c)ans = -1.6180 0.6180操作题 46 求梯度和法向量%数值法求梯度,

38、使用Fx=gradient(F)只显示FX/fx,fy=gradient(F) F=1 1.2 1.4 2.35;.06 3 4 2;-1 77.2 9 1.4; Fx,Fy=gradient(F)%二元多元函数求导一般用gradient和nx,ny,nz=surfnorm,gradient: Numerical gradient;surfnorm: Compute and display 3-D surface normal(法向量)Fx = 0.2000 0.2000 0.5750 0.9500 2.9400 1.9700 -0.5000 -2.0000 78.2000 5.0000 -3

39、7.9000 -7.6000Fy = -0.9400 1.8000 2.6000 -0.3500 -1.0000 38.0000 3.8000 -0.4750 -1.0600 74.2000 5.0000 -0.6000 Fx=gradient(F)Fx = 0.2000 0.2000 0.5750 0.9500 2.9400 1.9700 -0.5000 -2.0000 78.2000 5.0000 -37.9000 -7.6000 n=surfnorm(F)n = -0.1485 -0.0058 -0.3170 -0.7910 -0.9404 -0.0518 0.1262 0.9534 -

40、1.0000 -0.0452 0.9865 -0.9985%求法向量(xingling)用surfnorm操作题 47 add path,pathCan be used:1.addpath:Add folders to search path addpath(F:Download) Addmypath(1)F = -3ans = -32.pathtool: open Set Path dialog box to view and change search path3.genpath Generate path string p = genpath(fullfile(matlabroot,to

41、olbox,images)p =F:matric laboratarytoolboximages;F:matric laboratarytoolboximagescolorspaces;F:matric laboratarytoolboximagescolorspacesja;F:matric laboratarytoolboximagesicons;F:matric laboratarytoolboximagesimages;F:matric laboratarytoolboximagesimageseml;F:matric laboratarytoolboximagesimagesja;F

42、:matric laboratarytoolboximagesimdemos;F:matric laboratarytoolboximagesimdemosdemosearch;F:matric laboratarytoolboximagesimdemoshtml;F:matric laboratarytoolboximagesimdemoshtmlja;F:matric laboratarytoolboximagesimdemosja;F:matric laboratarytoolboximagesimdemosjademosearch;F:matric laboratarytoolboxi

43、magesimuitools;F:matric laboratarytoolboximagesimuitoolsja;F:matric laboratarytoolboximagesiptformats;F:matric laboratarytoolboximagesiptformatsja;F:matric laboratarytoolboximagesiptutils;F:matric laboratarytoolboximagesiptutilsja;操作题 48 求多项式的根并生成(shn chn)原多项式 p=1 21 20 0; roots(p)ans = 0 -20 -1%roo

44、ts: Polynomial roots, r = roots(c) returns a column vector whose elements are the roots of the polynomial c. f=poly2sym(p) f = x3 + 21*x2 + 20*x操作题 49 求极限(jxin)含参数(cnsh) syms x m n; a=limit(m./(1-x.m)-n./(1-x.n),x,1) a = (- n2/2 + n/2)/n - (- m2/2 + m/2)/m2.x=sym(x); a1=limit(x.3+x.2+x+1).3-sqrt(x.2

45、+x+1).*(log(exp(x)+x)./x),inf) a1 = Inf3. syms x y; a2=limit(3.x+9.x).(1/x),x,1./y) a2 = 3*(3(1/y) + 1)y4. a3=limit(sqrt(1./x+sqrt(1./x+sqrt(1./x)-sqrt(1./x-sqrt(1./x+sqrt(1./x),x,0,right) a3 = 1%求极限(jxin)使用limit即可,调用(dioyng)格式:limit(1/x, x, 0, right)%求积分(jfn)SUMMARY 符号法求积分:int :int(expr,var,a,b,Nam

46、e,Value),求定积分、不定积分皆可 quad/quadl/quad8数值法求积分:Numerically evaluate integral, adaptive Simpson quadrature 调用q = quad(fun,a,b,tol,trace);trapz:梯形积分:Trapezoidal numerical integration 调用:Z = trapz(X,Y),此处XY为数组操作题 50 求复杂函数的导数 diff(5*x3+3*x2-2*x+7)/(-4*x3+8*x+3),1) ans = (15*x2 + 6*x - 2)/(- 4*x3 + 8*x + 3)

47、 + (12*x2 - 8)*(5*x3 + 3*x2 - 2*x + 7)/(- 4*x3 + 8*x + 3)2%此式中不可有.等操作题 51 积分1. syms x f=(x+sin(x)/(1+cos(x) f = x + sin(x)/(cos(x) + 1) int(f) ans = x2/2 - log(cos(x) + 1)2. quad(sqrt(log(1./x),0,1)ans = 0.88623. syms x f=cos(x) x.2;2.x log(2+x); int(f) ans = sin(x), x3/3 2x/log(2), (log(x + 2) - 1)

48、*(x + 2)操作题52 taylor 幂级数展开(zhn ki)%taylor幂级数展开(zhn ki):Taylor series expansion:taylor(f,n,a) taylor(sin(x),3,1) ans = sin(1) - (sin(1)*(x - 1)2)/2 + cos(1)*(x - 1) vpa(ans) ans = 0.54030230586813971740093660744298*x - 0.42073549240394825332625116081515*(x - 1.0)2 + 0.30116867893975678925156571418732

49、操作题 53 非线性方程(fngchng)、求偏导 syms u v x y;u,v=solve(x*u+y*v=0,y*u+x*v=1,u,v) u = -y/(x2 - y2) v = x/(x2 - y2) diff(u,x) ans = (2*x*y)/(x2 - y2)2 diff(ans,y) ans = (2*x)/(x2 - y2)2 + (8*x*y2)/(x2 - y2)3操作题 54 微分方程(wi fn fn chn)%符号(fho)法 dsolve dsolve(D2y=cos(2*x)-y,y(0)=1,Dy(0)=0,x) ans = (5*cos(x)/3 +

50、sin(x)*(sin(3*x)/6 + sin(x)/2) - (2*cos(x)*(6*tan(x/2)2 - 3*tan(x/2)4 + 1)/(3*(tan(x/2)2 + 1)3) vpa(ans) ans = 1.6666666666666666666666666666667*cos(x) + sin(x)*(0.16666666666666666666666666666667*sin(3.0*x) + 0.5*sin(x) - (0.66666666666666666666666666666667*cos(x)*(6.0*tan(0.5*x)2 - 3.0*tan(0.5*x)4

51、 + 1.0)/(tan(0.5*x)2 + 1.0)3操作题 55 plotyy t=1:6t = 1 2 3 4 5 6 sr=2456 2032 1900 2450 2890 2280; ll=12.5 11.3 10.2 14.5 14.3 15.1; AX,H1,H2=plotyy(t,sr,t,ll)AX = 174.0037 190.0039H1 = 175.0079H2 = 191.0042 legend(销售收入,边际(binj)利润率)操作题 56 圆锥螺线(lu xin)的绘制%office2013 抽风(chu fng),把做的十多道题都搞没了,怒罢工.不妨取v=2 a

52、=pi/6 w=3 syms t v=2; a=pi/6; w=3; x=v*t*sin(a)*cos(w*t); y=v*t*sin(a)*sin(w*t); z=v*t*cos(w); ezplot3(x,y,z,0,10) %0,10为t的取值范围操作题 57 求函数的零点 f=inline(exp(x)-x-5)f = Inline function: f(x) = exp(x)-x-5 fzero(f,2) %初值点取在区间及区间附近都可以,据老师说最好取到区间内ans = 1.9368操作题 58 f=inline(1./(x-0.3).2+0.01)+1./(x-0.9).2+0

53、.04)-6)f = Inline function: f(x) = 1./(x-0.3).2+0.01)+1./(x-0.9).2+0.04)-6 fzero(f,1)ans =1.2995操作题 59.插值法求点 t=0:0.125:0.5; i=0 6.24 7.75 4.85 0; k=0:50; t1=0.01*k; i1=interp1(t,i,t1)i1 = Columns 1 through 10 0 0.4992 0.9984 1.4976 1.9968 2.4960 2.9952 3.4944 3.9936 4.4928 Columns 11 through 20 4.99

54、20 5.4912 5.9904 6.3004 6.4212 6.5420 6.6628 6.7836 6.9044 7.0252 Columns 21 through 30 7.1460 7.2668 7.3876 7.5084 7.6292 7.7500 7.5180 7.2860 7.0540 6.8220 Columns 31 through 40 6.5900 6.3580 6.1260 5.8940 5.6620 5.4300 5.1980 4.9660 4.6560 4.2680 Columns 41 through 50 3.8800 3.4920 3.1040 2.7160

55、2.3280 1.9400 1.5520 1.1640 0.7760 0.3880 Column 51 0操作题 60. 三次(sn c)hermite插值 x=-1:0.5:1; y=1./(1+25.*x.2); x1=-1:0.1:1; pchip(x,y,x1)ans = Columns 1 through 10 0.0385 0.0431 0.0564 0.0772 0.1048 0.1379 0.2504 0.4671 0.7137 0.9161 Columns 11 through 20 1.0000 0.9161 0.7137 0.4671 0.2504 0.1379 0.10

56、48 0.0772 0.0564 0.0431 Column 210.0385%此题用interp1(x,y,xi,p)亦可操作题 61. x=-1:0.5:1; %初值取步长多少不影响(yngxing)差值结果 y=1./(1+25.*x.2); x1=-1:0.1:1; spline(x,y,x1) %或者(huzh)interp1(x,y,x1,spline)ans = Columns 1 through 10 0.0385 -0.1817 -0.2520 -0.2023 -0.0623 0.1379 0.3687 0.6001 0.8024 0.9456 Columns 11 thro

57、ugh 20 1.0000 0.9456 0.8024 0.6001 0.3687 0.1379 -0.0623 -0.2023 -0.2520 -0.1817 Column 210.0385操作题 62. 线性插值 t=0 20 40 56 68 80 84 96 104 110; v=1 20 20 38 80 80 100 100 125 125; t1=0:5:110; interp1(t,v,t1)ans = Columns 1 through 10 1.0000 5.7500 10.5000 15.2500 20.0000 20.0000 20.0000 20.0000 20.00

58、00 25.6250 Columns 11 through 20 31.2500 36.8750 52.0000 69.5000 80.0000 80.0000 80.0000 100.0000 100.0000 100.0000 Columns 21 through 23 112.5000 125.0000 125.0000plot(t,v,+,t1,ans,o)操作题63. 插值SUMMARY x=0:0.5:5; x1=0:0.1:5; y=x.2; interp1(x,y,x1); %线性插值 interp1(x,y,x1,spline); %三次(sn c)样条插值 interp1(

59、x,y,x1,cubic); %三次(sn c)插值 interp1(x,y,x1,pchip); %hermit插值操作题 64 线性插值求点 D=18:2:30; S=9.9617724 9.9543645 9.9468069 9.9390950 9.9312245 9.9231915 9.9149925; interp1(S,D,9.935799)ans = 24.837557969633686%此种方法(fngf)可求某点处的数值,还有种实现方法见help example 3操作题 65 m=1:12; t=80.9 67.2 67.1 50.5 32 33.6 36.6 46.8 5

60、2.3 62 64.1 71.2; mi=1:.2:12; ti=interp1(m,t,mi,p); plot(m,t,-ok,mi,ti,-r)%使用(shyng)hermite插值,得到(d do)其图像可知该地在一年的五月份左右(zuyu)日照时间最短,到了十二月份到一月份,日照时间最长操作题 67 二维插值 x=1:4;y=1:4; h=6.36 6.97 6.23 4.77;6.98 7.12 6.31 4.78;6.83 6.73 5.99 4.12;6.61 6.25 5.53 3.34; xi=1:.1:4;yi=1:.1:4; hi=interp2(x,y,h,xi,yi,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论