您好,欢迎访问三七文档
1.用函数roots求方程的根roots([1-1-1])2.,在n个节点(n不要太大,如取5~11)上用分段线性、三次方、样条插值方法,计算m个插值点(m可取50~100)的函数值。(注,n取10,m取100)x=linspace(0,2*pi,10);y=sin(x);xi=linspace(0,2*pi,100);y1=interp1(x,y,xi);y2=interp1(x,y,xi,'spline');y3=interp1(x,y,xi,'cublic');3.测得某地大气压强随高度变化的一组数据如表3-11所示,试用插值法和拟合法估算高度为0,100,200,300,......,2000米时的大气压强值。表3-11某地大气压强随高度变化数据高度/m0300600100015002000压强/Pa0.96890.93220.89690.85190.79890.7491x=[0300600100015002000];y=[0.96890.93220.89690.85190.79890.7491];xi=0:100:2000;y1=interp1(x,y,xi,'spline');p=polyfit(x,y,3);y2=polyval(p,xi);4.利用梯形法和辛普森法求定积分的值:梯形法:x=linspace(-3,3,200);y=exp(-x.^2/2)/(2*pi);I1=trapz(x,y)辛普森法:I2=quad('exp(-x.^2/2)/(2*pi)',-3,3)或者:t='exp(-x.^2/2)/(2*pi)';I2=quad(t,-3,3)5.分别用矩形法、梯形法、辛普森法和牛顿-科茨4种方法来近似计算定积分。矩形法:x=linspace(0,1,100);y=x./(x.^2+4);t=cumsum(y*(1/99));t1=t(100)梯形法:x=linspace(0,1,100);y=x./(x.^2+4);t2=trapz(x,y)辛普森法t3=quad('x./(x.^2+4)',0,1)牛顿-科茨t4=quadl('x./(x.^2+4)',0,1)6.解下列方程组:a=[5121;2511;12102;12210];b=[9;9;15;15]x=a\b9.利用二三阶龙格-库塔方法来求解下列初值问题:先定义函数functionf=exe9(x,y)f=2*x.*y在命令窗口输入[x1,y1]=ode23('exe9',[0:0.1:1.2],1)symsxf=x^3-6*x^2+11*x-6;g=(x-1)*(x-2)*(x-3);h=-6+(11+(-6+x)*x)*x;f1=factor(f)g1=factor(g)h1=simplify(h)symsxyzabcf=(x+y)*(a+b^c)^z/(x+a)^2;pretty(f)g=x*(a+b^c)^z/(x+a)^2+y*(a+b^c)^z/(x+a)^2;pretty(g)symsabcxf=(a*x^2+b*x+c-3)^3-a*(c*x^5+4*b*x-1)-18*b*((2+5*x)^7-a+c);f1=collect(f)f2=collect(f,a)symsxyf=x^2*y+x*y-x^2-2*x;g=-1/4*x*exp(-2*x)+3/16*exp(-2*x)f1=collect(f),g1=collect(g,exp(-2*x))symsxf=x^3-3*x^2-3*x+1;g=x^3-7*x+6;f1=factor(f)g1=factor(g)symsxyf1=x*(x*(x-2)+5)-1;f2=log(x*y)+log(z);f3=3*x*exp(x)*exp(y+z);f4=sin(x)^2+cos(x)^2-1;f11=simplify(f1)f22=simplify(f2)f33=simplify(f3)f44=simplify(f4)8symsxf1=cos(x)+sqrt(-sin(x)^2);f2=x^3+3*x^2+3*x+1;f11=simple(f1)f22=simple(f2)symsxf=x^3-6*x^2+11*x-6;g=(x-1)*(x-2)*(x-3);h=-6+(11+(-6+x)*x)*x;df=diff(f)dg=diff(g)dh=diff(h)10.symsabcxf=a*x^2+b*x+c;g=sqrt(exp(x)+x*sin(x));df=diff(f)dg=diff(g)symsxabcdsf1=log(x)/exp(x^2);f2=cos(2*x)-sin(2*x);f3=[a*x,b*x^2;c*x^3,d*s];f1i=int(f2)f2i=int(f2,-pi,pi)f3i=int(f3)symsxytf1=sin(x)+2;f2=x^y;f3=4*t*x;f1i=int(f1,0,pi/6)f2i=int(f2,y,0,pi/3)f3i=int(f3,2,sin(t))symsxf1=1/x^2;f2=1/(x^2+1);f1i=int(f1,1,inf)f2i=int(f2,1,inf)symsxyf=sin(x)/x;g=sin(x+2*y);lf=limit(f)lg=limit(g,y,0)symsxyzf=sin(x^2+y^2/z);ftx=taylor(f,x,4,1)fty=taylor(f,y,4,0)ftz=taylor(f,z,4,0)symsxfx=x^2+x;ffx=fourier(fx)symsxfx=exp(-x^2);ffx=fourier(fx)symsxtvf=sin(x*t+2*t);L=laplace(f,t,v)symssxL=1/(s^2+1);f=ilaplace(L,s,x)(1)symsx1x2x3L1='-x1+2*x2=2';L2='2*x1+x2+x3=3';L3='4*x1+5*x2+7*x3=0';L4='x1+x2+5*x3=-5';[x1,x2,x3]=solve(L1,L2,L3,L4,x1,x2,x3)(2)symsx1x2x3x4L1=x1+x2+3*x3-x4+2;L2=x2-x3+x4-1;L3=x1+x2+2*x3+2*x4-4;L4=x1-x2+x3-x4;[x1,x2,x3,x4]=solve(L1,L2,L3,L4,x1,x2,x3,x4)[x1,x2,x3,x4]=solve(‘x1+x2+3*x3-x4=-2’,’x2-x3+x4=1’,’x1+x2+2*x3+2*x4=4’,’x1-x2+x3-x4’,’x1’,’x2’,’x3’,’x4’)(3)symsx1x2x3x4L1=x1-2*x2+3*x3-4*x4-4;L2=x2-x3+x4+3;L3=-x1-x2+2*x4+4;[x1,x2,x3,x4]=solve(L1,L2,L3,x1,x2,x3,x4)(4)symsx1x2x3L1=x1-4*x2+2*x3;L2=2*x2-x3;L3=-x1+2*x2-x3;[x1,x2,x3]=solve(L1,L2,L3,x1,x2,x3)23.解方程:f(x)=sinx+tanx+1=0symsxf=sin(x)+tan(x)+1;xf=solve(f)g=double(xf)xf=solve('sin(x)+tan(x)+1=0')a=[13;-34];X=dsolve('DX=a*X')或a=[13;-34];X=dsolve('DX-a*X=0','x')y1=dsolve('Dy-(x+y)*(x-y)=0','x')y2=dsolve('x*Dy-y*log(y/x)=0','y(10)=1','x')y3=dsolve('Dy=x*sin(x)/cos(y)','y(2)=1','x')y=dsolve('D2y=cos(2*x)-y','Dy(0)=0','y(0)=1','x')[ff,gg]=dsolve('Df-f-3*g','Dg=f+4','x')1.symsxf=(x^2-1)/(x^2-3*x+2);lf=limit(f,x,2)2.symsxfx=cos(2*x)-sin(2*x);gx=sqrt(exp(x)+x*sin(x));ifx=int(fx)dgx=diff(gx)3.symsxfx=sin(x)+2;ifx=int(fx,0,pi/6)4.symsxyzL1=x+y+z-10;L2=3*x+2*y+z-14;L3=2*x+3*y-z-1;[x,y,z]=solve(L1,L2,L3)5[y,z]=dsolve('Dy-z=sin(x)','Dz+y=1+x','y(0)=2','z(0)=7','x')1.exp2.m:functions=exp2(x)s=0;forn=1:xs=s+n;endfunctions=exp2(x)s=0;n=1;whilen=xs=s+n;n=n+1;end2.用公式求π的近似值,直到最后一项绝对值小于10-6,试编写M脚本文件s=0;forn=1:1000000p=(-1)^(n-1)/(2*n-1);s=s+p;ifabs(p)1e-6breakendend4*s或者:s=0;n=1;p=1;whileabs(p)1e-6p=(-1)^(n-1)/(2*n-1);s=s+p;n=n+1;ends*4functions=exp3(x)s=0;r=1;forn=1:xr=r*n;s=s+r;end1.判断某一年是否是闰年。年从键盘输入。n=input('n=')ifrem(n,400)==0y='aleapyear';elseifrem(n,100)==0y='notaleapyear';elseifrem(n,4)==0y='aleapyear';elsey='notaleapyear';endy(如果此题改成:检查从1到5000年间的闰年,并把闰年用一向量表示。a=[];forn=1:5000ifrem(n,400)==0a=[a,n];elseifrem(n,100)==0elseifrem(n,4)==0a=[a,n];endenda'如果改成:编程,判断某一年是否是闰年:functiony=leap(n)ifrem(n,4)==0&rem(n,100)~=0|rem(n,400)==0'leapyear'else'notaleapyear'end2.用公式求π的近似值,直到最后一项绝对值小于10-6,试编写M脚本文件s=0;forn=1:5000p=(-1)^(n-1)/(2*n-1);s=s+p;ifabs(p)1e-6breakendend4*s或者:s=0;n=1;p=1;whileabs(p)1e-6p=(-1)^(n-1)/(2*n-1);s=s+p;n=n+1;ends*43.用循环语句来寻找第一个大于10000的Fibonacci数:a(m)=a(m-1)+a(m-2),a(1)=a(2)=1n=100;a=ones(1,n);fork=3:na(k)=a(k-1)+a(k-2);ifa(k)=10000break;end,endk,a(k),或者:a=ones(1,100);m=2;whilea(m)10000a(m+1)=a(m-1)+a(m);m=m+1;endm,a(m),4.求解n!为100位数的最小n值。a=1;forn=1:1000;a=a*n;ifa=1e100breakendenda,n或者:a=1;n=1;whilea1e100a=a*n;n=n+1;enda,n-13.编写一程序,求魔方矩阵magic(20)左上-右下对角线、左下-右上对角线的元素,并分别以一行向量表示。a=magic(20);r=[];s=[];form=1:20forn=1:20ifm==ns=[sa(m,n)];elseifm+n
本文标题:MATLAB-习题
链接地址:https://www.777doc.com/doc-2886907 .html