MATLAB教程 R2014a 答案 全 张志涌-matlab2014答案 下载本文

-190.7388 16.4525 118.6963 123.0361 33.0336 -57.2817 37.3849 -66.8175 160.6261 69.9436 65.2278 -21.4319 170.2597 92.8549 -75.5045 -138.7923 -52.6574 -8.4902 115.9030 -189.3844 34.0593 -109.1584 20.6169 136.7896 -45.4089 135.7386 -10.7050 10.4240 Gi =

199.1404 33.1590 -86.1452 -7.5887 -181.6856 -145.4039 18.9686 16.5731 11.9053 -4.5021 87.0651 148.4022 127.5072 -7.2483 25.1791 -84.0887 -233.6194 135.0018 -128.3931 -28.4923 53.7385 41.5139 -24.4788 120.7113 0.8532 66.7238 -160.2738 -55.1871

28.6287 -75.6522 128.8596 -133.7671 3.1772 -282.0866 -13.7111 158.5203 -24.2673 -189.7767 -83.3384 16.7992 21.0869 67.0898 -182.1134 -180.7631 -143.6344 20.6149 80.5622 87.7339 9.4764 228.1237 Gn =

1.0253e+03

第四章 1 数值差分

d=0.001;

dxdt_diff=diff(y)/d;

dxdt_grad=gradient(y)/d; hold on;

plot(t,y,'-r');

plot(t(1:end-1),dxdt_diff,'-g'); plot(t,dxdt_grad,'-b');

210-1-2-3-4-5-601234567数值求导后存在很多的毛刺

2 数值计算

d=1e-5; t=0:d:10;

t=t+(t==0)*realmin;%去除影响 fx=sin(t)./t;

y=cumtrapz(fx)*d; plot(t,y);

yt1=find(t==4.5); y45=y(yt1)

y45 =

1.6541

21.81.61.41.210.80.60.40.20012345678910尝试integral d=1e-5; t=0:d:10;

t=t+(t==0)*realmin;%去除影响 fx=@(t)sin(t)./t; y=integral(fx,0,10) %plot(t,y);

%yt1=find(t==4.5); %y45=y(yt1)

y =

1.6583

3 数值积分

d=1e-5; t=0:d:pi;

t=t+(t==0)*realmin;%去除影响 fx=@(t)exp((sin(t)).^3); s=integral(fx,0,pi)

s =

5.1370

符号验算

syms x;

fxx=exp((sin(x))^3); ss=int(fxx,x,0,pi)

ss =

int(exp(sin(x)^3), x, 0, pi)

此时符号运算不如数值运算可以得出解析解

4 求数值积分

clear;

fx=@(x)exp(-abs(x)).*abs(sin(x)); format long ;

s=integral(fx,-5*pi,inf,'Abstol',1e-9)

s =

1.090331100328886

x=linspace(-5*pi,50,1e7); dx=x(2)-x(1);

st=trapz(exp(-abs(x)).*abs(sin(x)))*dx

st =

1.090331328559288

可知,trapz必须为有限数值;同样,quadl也需为有限数值

clear;

fx=@(x)exp(-abs(x)).*abs(sin(x)); format long ;

s=quadl(fx,-5*pi,50,1e-9)

s =

1.090331336243919

5 最小值点

%首先绘出函数曲线,确定大概找最小值范围 clear;

ft=@(t)sin(5*t).^2.*exp(0.06*t.*t)+1.8*abs(t+0.5)-1.5*t.*cos(2*t); t=-5:0.01:5;

ezplot(ft,[-5,5]); sin(5 t)2 exp(0.06 t t)+...-1.5 t cos(2 t)20181614121086420-5-4-3-2-10t12345