《高等应用数学问题的MATLAB求解》——第8章习题代码
(1)
>> t=0:0.12:1;y=t.^2*exp(-5*t).*sin(t);
>> t1=0:0.02:1;y0=t1.^2.*exp(-5*t1).*sin(t1);y1=interp1(t,y,t1,'spline');
>> plot(t1,y1,':',t,y,'o',t1,y0)
(2)
>> t=0:0.12:3;y=sin(10*t.^2+3);
>> t1=0:0.02:3;y0=sin(10*t1.^2+3);y1=interp1(t,y,t1,'spline');
>> plot(t1,y1,':',t,y,'o',t1,y0)
结果
(3)
>> [x,y]=meshgrid(-2:.4:2,-2:.4:2);
>> z=exp(-x.^2-y.^4).*sin(x.*y.^2+x.^2.*y)./(3*x.^3+y);
>> surf(x,y,z),axis([-2,2,-2,2,-0.3,0.3]);
>> [x1 y1]=meshgrid(-2:.1:2,-2:.1:2);
>> z1=interp2(x,y,z,x1,y1,'spline');figure;surf(x1,y1,z1),axis([-2,2,-2,2,-0.3,0.3]);
>> z0=exp(-x1.^2-y1.^4).*sin(x1.*y1.^2+x1.^2.*y1)./(3*x1.^3+y1);
>> figure;surf(x1,y1,z1-z0)
结果
(4)
>> x=-2:0.3:4.9;y=[0.1029,0.1174,0.1316,0.1448,0.1566,0.1662,0.1733,0.1775,0.1785,0.1764,0.1711,0.1630,0.1526,0.1402,0.1266,0.1122,0.0977,0.0835,0.0702,0.0577,0.0469,0.0373,0.0291,0.0224];
>> x1=-2:0.02:4.9;y1=interp1(x,y,x1);y2=interp1(x,y,x1,'spline');y3=interp1(x,y,x1,'nearest');y4=interp1(x,y,x1,'pchip');
>> subplot(2,2,1);plot(x1,y1,x,y,'o');subplot(2,2,2);plot(x1,y2,x,y,'o');subplot(2,2,3);plot(x1,y3,x,y,'o');subplot(2,2,4);plot(x1,y4,x,y,'o')