1、MATLAB实验第八次上机1(1) roots(1 0 2 0 -15)ans = 1.73205080756887 0.00000000000000 + 2.23606797749979i 0.00000000000000 - 2.23606797749979i -1.73205080756888 vpa(ans,6) ans = -1.73205 - 8.32667e-17 + 2.23607*i - 8.32667e-17 - 2.23607*i 1.73205(2)M文件function y=fun(x)y=x4+2*x2-15; x=fsolve(fun,1.7)Optimizati
2、on terminated: first-order optimality is less than options.TolFun.x = 1.73205080756901vpa(x,6)x=1.712051 x=fsolve(fun,-1.7)Optimization terminated: first-order optimality is less than options.TolFun.x = -1.73205080756899vpa(x,6)x=1.73205 x=fsolve(fun,2i)Optimization terminated: first-order optimalit
3、y is less than options.TolFun.x = 0.00000000000010 + 2.23606797751316i vpa(x,6) ans = 1.0e-13 + 2.23607*i x=fsolve(fun,-2i)Optimization terminated: first-order optimality is less than options.TolFun.x = 0.00000000000010 - 2.23606797751316i vpa(x,6) ans = 1.0e-13 - 2.23607*i(3) x=solve(x4+2*x2-15=0)
4、x = 3(1/2) -3(1/2) i*5(1/2) -i*5(1/2) ans = 1.73205 -1.73205 2.23607*i -2.23607*i.2.解析解 s=x-sin(x)-exp(x)*cos(x)s =x-sin(x)-exp(x)*cos(x) x=solve(s) x = 1.4621214800914779232240323515507 vpa(x,6) ans = 1.46212数值解 x=fsolve(x-sin(x)-exp(x)*cos(x),1.4)Equation solved.fsolve completed because the vector
5、 of function values is near zeroas measured by the default value of the function tolerance, andthe problem appears regular as measured by the gradient.x = 1.462121480439321 vpa(x,6) ans = 1.46212迭代法M文件 fun2.mclearx0=1.4;x1=sin(x0)+exp(x0)*cos(x0);while abs(x1-x0)=0.00005 x0=x1; x1=sin(x0)+exp(x0)*co
6、s(x0);endx1结果 fun2x1 = 1.462126234771429 vpa(x1,6) ans = 1.46213二分法cleara=0;b=1.45;n=0;while b-a=0.00005 x=(a+b)/2; n=n+1; fa=a-sin(a)-exp(a)*cos(a); fx=x-sin(x)-exp(x)*cos(x); if fa*fx fun1x = 1.449955749511719n = 14 vpa(x,6) ans = 1.44996另一个解略3. s=exp(-x)-sin(pi*x/2)+log(x); x=solve(s) x = 1.54935
7、16167540306801165507666627 vpa(x,6) ans = 1.54935.4. a=-1,0,1;-4,3,1;1,3,2a = -1 0 1 -4 3 1 1 3 2 det(a)ans = -18 p=poly(a)p = 1.0000 -4.0000 -3.0000 18.0000 p=poly2str(p,x)p = x3 - 4 x2 - 3 x + 18 eig(a)ans = -2.0000 3.0000 + 0.0000i 3.0000 - 0.0000i y,r=eig(a)y = -0.5774 -0.2357 + 0.0000i -0.2357
8、- 0.0000i -0.5774 -0.2357 - 0.0000i -0.2357 + 0.0000i 0.5774 -0.9428 -0.9428 r = -2.0000 0 0 0 3.0000 + 0.0000i 0 0 0 3.0000 - 0.0000i R=rank(a)R = 3 n=inv(a)n = -0.1667 -0.1667 0.1667 -0.5000 0.1667 0.16670.8333 -0.1667 0.1667.5.临时文件 fun1=inline(x3+3*sin(-x/3)-23); fun2=inline(x3+3*x-23); x1=fun1(p
9、i),x2=fun1(5),x3=fun1(3.4)x1 = 5.408200468946500x2 = 99.013776126744702x3 = 13.586511915207851 x1=fun2(pi),x2=fun2(5),x3=fun2(3.4)x1 = 17.431054641069196x2 = 117x3 = 26.503999999999991匿名函数 fun1=(x)x3+3*sin(-x/3)-23; fun2=(x)x3+3*x-23; x1=fun1(pi),x2=fun1(5),x3=fun1(3.4)x1 = 5.408200468946500x2 = 99.
10、013776126744702x3 = 13.586511915207851 x1=fun2(pi),x2=fun2(5),x3=fun2(3.4)x1 = 17.431054641069196x2 = 117x3 = 26.503999999999991永久文件fun1.mfunction y=fun1(x)y=x3+3*sin(-x/3)-23;fun2.mfunction y=fun2(x)y=x3+3*x-23;结果 x1=fun1(pi),x2=fun1(5),x3=fun1(3.4)x1 = 5.408200468946500x2 = 99.013776126744702x3 =
11、13.586511915207851 x1=fun2(pi),x2=fun2(5),x3=fun2(3.4)x1 = 17.431054641069196x2 = 117x3 = 26.503999999999991。6 a=1,4,7,20;2,5,8,11;3,-6,9,12; b=1;3;3; c=rank(a),d=rank(a,b)c = 3d = 3 u=null(sym(a) u = 161/12 5/6 -21/4 1 x=abx = 0 0.0373 0.5652 -0.1553 u=sym(a)sym(b)警告: System is rank deficient. Solu
12、tion is not unique. u = 25/12 1/6 -1/4 07. x=1,1.4,1.8,2.2,2.6,3,3.4,3.8x = 1.0000 1.4000 1.8000 2.2000 2.6000 3.0000 3.4000 3.8000 y=2,-1.448,-1.664,-0.056,1.968,3,20.144,0.5520y = 2.0000 -1.4480 -1.6640 -0.0560 1.9680 3.0000 20.1440 0.5520 x1=1.25,2.3,2.9,3.66x1 = 1.2500 2.3000 2.9000 3.6600 y1=in
13、terp1(x,y,x1,linear)y1 = -0.1550 0.4500 2.7420 7.4092 y2=spline(x,y,x1)y2 = -0.6464 0.7190 1.2057 16.1500 y1=interp1(x,y,x1,spline)y1 = -0.6464 0.7190 1.2057 16.1500 x=1,1.4,1.8,2.2,2.6,3,3.4,3.8,1.25,2.3,2.9,3.66x = Columns 1 through 9 1.0000 1.4000 1.8000 2.2000 2.6000 3.0000 3.4000 3.8000 1.2500
14、Columns 10 through 12 2.3000 2.9000 3.6600 y=2,-1.448,-1.664,-0.056,1.968,3,20.144,0.5520,-0.6464,0.7190,1.2057,16.1500y = Columns 1 through 9 2.0000 -1.4480 -1.6640 -0.0560 1.9680 3.0000 20.1440 0.5520 -0.6464 Columns 10 through 12 0.7190 1.2057 16.1500 p=polyfit(x,y,4)p = -6.9502 62.2790 -192.3240
15、 242.1436 -105.2824 poly2str(p,x)ans = -6.9502 x4 + 62.279 x3 - 192.324 x2 + 242.1436 x - 105.2824。8.(1) syms x s=int(exp(-x2),-1,5) s = (pi(1/2)*(erf(1) + erf(5)/2 vpa(s,11) ans = 1.6330510583(2) h=0.000001;x=-1:h:5; y=exp(-x.2); s=h*sum(y)s = 1.633051242203520 vpa(s,5) ans = 1.6331(3) h=0.000001;x
16、=-1:h:5; y=exp(-x.2); s=h*trapz(y)s = 1.633051058263760 vpa(s,5) ans = 1.6331。9.(1) syms t s=int(exp(-0.5*t)*sin(t+pi/6),0,pi*3) s = (2*3(1/2) + 1)*(exp(-(3*pi)/2) + 1)/5 vpa(s,11) ans = 0.90084078782(2) h=pi/1000;t=0:h:pi*3; y=exp(-0.5.*t).*sin(t+pi/6); s=h*trapz(y)s = 0.900840276606885(3) y=exp(-0
17、.5.*t).*sin(t+pi/6); s=quad(y,0,3*pi)s = 0.900840811006463。10. y=dsolve(D3y=-y,y(0)=1,Dy(0)=0,D2y(0)=0) y = exp(-t)/3 + (2*exp(t/2)*cos(3(1/2)*t)/2)/3。11. fun=(x,y)y-2*x/y; x,y=ode23(fun,0,1,1)x = 0 0.080000000000000 0.180*0000 0.280000000000000 0.380000000000000 0.480000000000000 0.580000000000000
18、0.680000000000000 0.780000000000000 0.880000000000000 0.980000000000000 1.000000000000000y = 1.000000000000000.0770* 1.166*0293 1.249017917208636 1.326676081253747 1.400034750953813 1.469738236869182 1.536284563268660 1.600068179713872 1.661407874348603 1.720565714193718 1.732154879417795。12.数值解 fun
19、=(x,y)y(2);-6*cos(x);ode23(fun,-10,10,5,0) x,y=ode23(fun,-10,10,5,0)x = -10.000000000000000 -9.999984109419911 -9.999904656519465 -9.999507392017236 -9.997521069506089 -9.987589456950357 -9.937931394171693 -9.823011698264244 -9.660813474879619 -9.460729774500120 -9.228030874486807 -8.964651209392159
20、 -8.669191555479403 -8.335338* -7.945026707902023 -7.534135580254955 -7.098590248274665 -6.686765918941736 -6.351116143428428 -6.064078404739998 -5.816834208814697 -5.676579279755624 -5.536324350696551 -5.373707097371709 -5.165727528773497 -4.909807675114976 -4.583508333543399 -4.276309013996998 -3.
21、969109694450596 -3.785877313496457 -3.644209936421614 -3.502542559346770 -3.329902814028738 -3.121191612349518 -2.880652050645896 -2.609412677193195 -2.305074556406769 -1.959395503555049 -1.548052236437003 -1.007685620871909 -0.648329535937590 -0.288973451003272 0.026695537887512 0.300568916557177 0
22、.535176937187460 0.723543961635943 0.877312726974181.0775* 1.324344071307815 1.634484898385757 1.955463740046763 2.276442581707769 2.469137613521180 2.602773107181954 2.736408600842728 2.896537924347151 3.094745633376593 3.325768726230144 3.587505914509060 3.881161418314442 4.212702926788669 4.59918
23、0775684407 5.108837174059754 5.487848523711013 5.866859873362272 6.200978970945136 6.489433181994937 6.738394722201685 6.882797275400684.027* 7.189*5368 7.396379056423532 7.651474921421556 7.976146768180901 8.304280982143922 8.550804724211686 8.746234647689784 8.881549241653310 9.016863835616837 9.1
24、76*4311 9.373476519950946 9.603796908489754 9.864848957890619 10.000000000000000y = 5.000000000000000 0 5.000000000635626 0.000080000412110 5.000000022882907 0.000480014835347 5.000000610898917 0.002480395940464 5.000015476805577 0.012490016399744 5.000388740272768 0.062729765988340 5.00982454863324
25、3 0.318564990035898.0816* 5.307941375241569 1.861033444504114 5.798555024616247 3.048473276894549 6.669992929007200 4.437014602410657.0379* 10.011125007397283 7.378306529500154 12.690125371114219 8.582014924615818 16.196332249800513 9.238497672087590 19.969154413901645 8.958461674000525 23.617037636
26、741571 7.630130032011948 26.364916073222680 5.618043483159200 27.927912697489852 3.668967408411018 28.734533361397119 1.957557154672697.0437*.0714* 29.002319905912568 -0.814292116839208 28.814731710854208 -1.473350149009797 28.435981825387298 -2.132*3079 27.819762614236211 -2.621589449547680 26.936160651409942 -2.688135353573485 26.175*5613 -2.176*3862 25.651397927203703 -1.155*2304 25.512240983073792 -0.341307459132607 25.513653484815091 0.372132415289034 25.620415374023295 1.143482092578525 25.903084917906853 2.139*6603 26.479178836596439 3.384867129674014 27.465796045578227 4.81039
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1