1,秦九韶算法,求出P(x=3)=2+4x+5x^2+2x^3的值clearall;x=3;n=3;a(1)=2;a(2)=4;a(3)=5;a(4)=2v(1)=a(n+1);fork=2:(n+1);v(k)=x*v(k-1)+a(n-k+2);endp=v(n+1)p=,1132,一次线型插值程序:利用100.121.求115的开方。clearall;x1=100;x2=121;y1=10;y2=11;x=115;l1=(x-x2)/(x1-x2);l2=(x-x1)/(x2-x1);p1=l1*y1+l2*y2p1=10.71433,分段插值程序,已知为S1(x)为(0,0),(1,1),(2,5)(3,8)上的分段一次插值,求S1(1.5).clearallx=[0123];y=[0158];n=length(x);a=1.5;fori=2:nif(x(i-1)=ax(i));endendH1=y(i-1)+(y(i)-y(i-1))/(x(i)-x(i-1))*(a-x(i-1))H1=3.50004)曲线拟合:用一个5次多项式在区间[0,2π]内逼近函数sin(x)。clearallX=linspace(0,2*pi,50);Y=sin(X);[P,S]=polyfit(X,Y,5)plot(X,Y,'k*',X,polyval(P,X),'k-')P=-0.00560.0874-0.39460.26850.87970.0102S=R:[6x6double]df:44normr:0.03375)求有理分式的导数clearallP=[3,5,0,-8,1,-5];Q=[10,5,0,0,6,0,0,7,-1,0,-100];[p,q]=polyder(P,Q)6)将以下数据按从小到大排序:4.35.75.21.89.4a=[4.35.75.21.89.4];b(1:100)=0;n=1;b(a*10)=1;fork=1:100a(n)=k/10;ifb(k)0a(n)=k/10;n=n+1;endendaa=1.80004.30005.20005.70009.400010.00007)用二分法求方程x3-x-1=0在[1,2]内的近似根,要求误差不超过10-3。clearalln=ceil(3*log2(10)-1);a=1;b=2;fork=0:nx=(a+b)/2;if(a^3-a-1)*(x^3-x-1)0a=x;endif(a^3-a-1)*(x^3-x-1)0b=x;endendxx=1.3252求dxxI104的估值8)梯形公式:clearalla=1;b=2;n=3;h=(b-a)/2;T=1;fori=1:n;u=(a+(i-1)*h)^4+(a+i*h)^4;T=T+h/2*u;endTT=21.54699)辛卜生公式:clearalla=1;b=2;n=3;h=(b-a)/2;T=1;fori=1:n;T=T+h/6*((a+(i-1)*h)^4+4*((a+(i-1)*h+h/2)^4)+(a+i*h)^4);endTT=20.332010)复化二点高斯公式,f(x)=2-x^2在区间[a,b]=[35],n=10clearall;f='2-x^2';f=inline(f);a=3;b=5;n=10;h=(b-a)/n;t=2*3^0.5;x(1)=a;s=0;fori=2:n+1x(i)=x(i-1)+h;c=(x(i)+x(i-1))/2;s=s+f(c-h/t)+f(c+h/t);ends=s*h/2;disp(s);-28.666711)牛顿插值clearallx0=0;x1=1;x2=2;y0=0;y1=1;y2=4;x=2;f11=(y1-y0)/(x1-x0);f12=(y2-y0)/(x2-x0);f22=(f12-f11)/(x2-x1);N2=y0+f11*(x-x0)+f22*(x-x1)*(x-x0)N2=412)复化矩形公式clearall;f='x^3';f=inline(f);a=2;b=5;n=10;h=(b-a)/n;x(1)=a;x(n+1)=b;s=0;fori=2:n+1x(i)=x(i-1)+h;s=s+f((x(i)+x(i-1))/2);ends=s*h;disp(s);152.013713)一步欧拉法,y'=3*x^2-5,clearall;f='3*x^2-5';f=inline(f);x0=0;y0=2;h=0.1;x=4;while(x0x)x1=x0+h;y1=y0+h*f(x0);x0=x1;y0=y1;enddisp(y0);43.620014)牛顿法,用牛顿法解方程0xexclearall;f='exp(x)-x';g='exp(x)-1';f=inline(f);g=inline(g);x0=0.5;n=2;i=1;while(i=n)x1=x0-f(x0)/g(x0);x0=x1;i=i+1;enddisp(x0);0.885815)求矩阵A的三种范数。clearallA=[17,0,1,0,15;23,5,7,14,16;4,0,13,0,22;10,12,19,21,3;11,18,25,2,19];a1=norm(A,1)a2=norm(A)ainf=norm(A,inf)a1=75a2=59.3617ainf=7516)用高斯-塞德尔公式求解方程组:1z2-yx103zy10x2z10y-xx0=0;y0=0;z0=0clearallx=0;y=0;z=0;a(1:3)=0;fork=1:10;x=(-0.1*y+0.2*z)+0.1;y=(-0.1*x)-(0.1*z)+0.3;z=(-0.1*x+0.1*y)+0.2;enda(1)=x;a(2)=y;a(3)=z;aa=0.11630.26690.215117)用雅格比公式求解方程1z2-yx103zy10x2z10y-xx0=0;y0=0;z0=0clearallx=0;y=0;z=0;a(1:3)=0;fork=1:10;x=(-0.1*a(2))+(0.2*a(3))+0.1;y=(-0.1*a(1))-(0.1*a(3))+0.3;z=(-0.1*a(1))+(0.1*a(2))+0.2;a(1)=x;a(2)=y;a(3)=z;endaa=0.11630.26690.215118)用追赶法求三对角方程组ax_0+bx_1+cx_2=da(k)=cos(0.1k),b(k)=4+sin(0.1k),c(k)=cos(0.2k),d(k)=1+cos(0.3k),k=1,2,..,12clearall;a=[cos(0.1)cos(0.2)cos(0.3)cos(0.4)cos(0.5)cos(0.6)cos(0.7)cos(0.8)cos(0.9)cos(1)cos(1.1)cos(1.2)]b=[4+sin(0.1)4+sin(0.2)4+sin(0.3)4+sin(0.4)4+sin(0.5)4+sin(0.6)4+sin(0.7)4+sin(0.8)4+sin(0.9)4+sin(1)4+sin(1.1)4+sin(1.2)]c=[cos(0.2)cos(0.4)cos(0.6)cos(0.8)cos(1)cos(1.2)cos(1.4)cos(1.6)cos(1.8)cos(2)cos(2.2)cos(2.4)]f=[1+cos(0.3)1+cos(0.6)1+cos(0.9)1+cos(1.2)1+cos(1.5)1+cos(1.8)1+cos(2.1)1+cos(2.4)1+cos(2.7)1+cos(3)1+cos(3.3)1+cos(3.6)];n=12;u(1)=c(1)/b(1);y(1)=f(1)/b(1);fork=2:nu(k)=c(k)/(b(k)-u(k-1)*a(k));y(k)=(f(k)-y(k-1)*a(k))/(b(k)-u(k-1)*a(k));endx(n)=y(n);fori=1:n-1x(n-i)=y(n-i)-u(n-i)*x(n-i+1);enddisp(x)Columns1through60.41020.27930.27220.22480.17930.1302Columns7through120.08360.04340.01450.00090.00500.020619)已知y(0)=1,y(1)=2,y’(0)=3,y’(1)=4,h=a*y(0)+b*y(1)+c*y’(0)+d*y’(1)求h(1/3)?clearallx0=0;x1=1;y0=1;y1=2;y2=3;y3=4;x=1/3;m=x1-x0;t=(x-x0)/(x1-x0);a=(t-1)*(t-1)*(1+2*t);b=t*t*(3-2*t);c=m*t*(t-1)*(t-1);d=m*t*t*(t-1);h=a*y0+b*y1+c*y2+d*y3;hh=1.4074