matlab总练习题(完整版).docx
- 文档编号:2060485
- 上传时间:2022-10-26
- 格式:DOCX
- 页数:26
- 大小:894.91KB
matlab总练习题(完整版).docx
《matlab总练习题(完整版).docx》由会员分享,可在线阅读,更多相关《matlab总练习题(完整版).docx(26页珍藏版)》请在冰豆网上搜索。
>>vpa('pi',20)
ans=
3.1415926535897932385
>>vpa('exp
(1)',20)
ans=
2.7182818284590452354
>>x=linspace(-pi,pi,21);
>>y=sin(x)
y=
Columns1through6
-0.0000-0.3090-0.5878-0.8090-0.9511-1.0000
Columns7through12
-0.9511-0.8090-0.5878-0.309000.3090
Columns13through18
0.58780.80900.95111.00000.95110.8090
Columns19through21
0.58780.30900.0000
å-
>>k=1:
1000;
>>kk=1./k;
>>kkk=kk./k;
>>res=sum(kkk)-(pi^2)/6
res=
-9.9950e-04
%承接上题
>>sum(kk)-log(1000)
ans=
0.5777
>>power(1+eps,1/eps)
ans=
2.7183
>>a=rand(2,3)
a=
0.81470.12700.6324
0.90580.91340.0975
>>x=a(1,:
)
x=
0.81470.12700.6324
>>y=a(2,:
)
y=
0.90580.91340.0975
>>norm(x)
ans=
1.0391
>>norm(y)
ans=
1.2900
>>acos(dot(x,y)/norm(x)/norm(y))
ans=
0.8189
>>rand(3,3)
ans=
0.27850.96490.9572
0.54690.15760.4854
0.95750.97060.8003
>>det(ans)
ans=
0.2937
线性无关
a=
0.39220.7060
0.65550.0318
0.17120.2769
>>x=a(1,:
)
x=
0.39220.7060
>>y=a(2,:
)
y=
0.65550.0318
>>z=a(3,:
)
z=
0.17120.2769
>>alpha=x-z
alpha=
0.22100.4291
>>beta=y-z
beta=
0.4843-0.2451
>>alpha=[alpha0]
alpha=
0.22100.42910
>>beta=[beta0]
beta=
0.4843-0.24510
>>cross(alpha,beta)
ans=
00-0.2620
面积0.2620
>>a=11:
19;
>>b=a;
>>fork=1:
8
b=[b;a+10*k];
end
>>rank(b)
ans=
2
>>a=vander(1:
9);
>>b=fliplr(a)
b=
Columns1through5
11111
124816
1392781
141664256
1525125625
16362161296
17493432401
18645124096
19817296561
Columns6through9
1111
3264128256
24372921876561
102440961638465536
31251562578125390625
7776466562799361679616
168071176498235435764801
32768262144209715216777216
59049531441478296943046721
>>det(b)
ans=
5.0566e+15
方式一>>f=@(x,y)exp(x+y)+sin((x^2)+(y^2))
f=
@(x,y)exp(x+y)+sin((x^2)+(y^2))
>>f(1,2)
ans=
19.1266
方式二
functionf=myfunfun(x,y)
f=exp(x+y)+sin((x^2)+(y^2));
>>myfunfun(1,2)
ans=
19.1266
>>
Char1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727
>>a=ans;
>>sqrt2char(3-2)=a(3)
sqrt2char=
4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727
>>forx=1:
100
b(x)=str2num(sqrt2char(x))
end
>>sum(b)/100
ans=
4.8100
f=@(x)(x^3)*sin(x)+(x^2)/3+x*cos(x)
f=
@(x)(x^3)*sin(x)+(x^2)/3+x*cos(x)
>>ezplot(f,-2,1)
>>x0=fzero(f,-1)
x0=
-0.7889
另一根为0,是显然的
functiony=difun(x)
ifx<-pi
y=-x-pi;
elseifx>-pi&x y=sin(x); else y=(x-pi)/2; end end >>y=[] y= [] >>forx=-6: 0.05: 6 y=[ydifun(x)]; end >>plot(x,y) >>plot([-6: 0.05: 6],y) >>pi/4 ans= 0.7854%pi/4的理想值 矩形公式: functiony=rectangle(n) x=0: 1/n: 1; a=1./(1+x.*x); y=sum(a)*(1/n); end >>rectangle(1000) ans= 0.7861 >>rectangle(10000) ans= 0.7855 >>rectangle(100000) ans= 0.7854 梯形公式: functiony=trapezoid(n) x=0: 1/n: 1; a=1./(1+x.*x); begin=a (1); endd=a(n+1); a (1)=0; a(n)=0; y=sum(a)*(1/n)+begin*(1/n)*0.5+endd*(1/n)*0.5; end trapezoid(1000) ans= 0.7854 >>trapezoid(100) ans= 0.7853 Simpson公式 functiony=simpson(n) x=0: 1/n: 1; a=thefun(x); begin=a (1); endd=a(n+1); medium=[]; forx=1: n medium=[medium(a(x)+a(x+1))*0.5]; end a (1)=0; a(n)=0; y=begin*(1/n)*(1/6)+endd*(1/n)*(1/6)+sum(a)*(1/n)*(1/3)+sum(medium)*(1/n)*(1/6)*4; end functione=thefun(r) e=1./(1+r.*r); end >>simpson(100) ans= 0.7854 >>simpson(10) ans=0.7832 >>A=[621-1;2410;114-1;-10-13]; >>b=[615-5]'; >>x=A\b x= 0.7906 -0.3613 0.8639 -1.1152 >>[diag(1: 4)eye(4)] ans= 10001000 0200
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 练习题 完整版