MATLAB实验第八次上机Word文档下载推荐.docx
《MATLAB实验第八次上机Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《MATLAB实验第八次上机Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。
![MATLAB实验第八次上机Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2023-2/2/464faeb0-7c2d-4a62-9bd9-977213c08b33/464faeb0-7c2d-4a62-9bd9-977213c08b331.gif)
x=solve('
x^4+2*x^2-15=0'
)
3^(1/2)
-3^(1/2)
i*5^(1/2)
-i*5^(1/2)
2.23607*i
-2.23607*i
…………………………………………………………….
2.
解析解
s='
x-sin(x)-exp(x)*cos(x)'
s=
x-sin(x)-exp(x)*cos(x)
x=solve(s)
1.4621214800914779232240323515507
1.46212
数值解
1.4)
Equationsolved.
fsolvecompletedbecausethevectoroffunctionvaluesisnearzero
asmeasuredbythedefaultvalueofthefunctiontolerance,and
theproblemappearsregularasmeasuredbythegradient.
<
stoppingcriteriadetails>
1.462121480439321
迭代法
M文件fun2.m
clear
x0=1.4;
x1=sin(x0)+exp(x0)*cos(x0);
whileabs(x1-x0)>
=0.00005
x0=x1;
x1=sin(x0)+exp(x0)*cos(x0);
end
x1
结果
fun2
x1=
1.462126234771429
vpa(x1,6)
1.46213
二分法
a=0;
b=1.45;
n=0;
whileb-a>
x=(a+b)/2;
n=n+1;
fa=a-sin(a)-exp(a)*cos(a);
fx=x-sin(x)-exp(x)*cos(x);
iffa*fx<
b=x;
else
a=x;
end
x,n=n-1
结果
fun1
1.449955749511719
n=
14
1.44996
另一个解略
……………………………………………………………………
3.
exp(-x)-sin(pi*x/2)+log(x)'
;
1.5493516167540306801165507666627
1.54935
……………………………………………………………….
4.
a=[-1,0,1;
-4,3,1;
1,3,2]
a=
-101
-431
132
det(a)
-18
p=poly(a)
p=
1.0000-4.0000-3.000018.0000
p=poly2str(p,'
x'
x^3-4x^2-3x+18
eig(a)
-2.0000
3.0000+0.0000i
3.0000-0.0000i
[y,r]=eig(a)
y=
-0.5774-0.2357+0.0000i-0.2357-0.0000i
-0.5774-0.2357-0.0000i-0.2357+0.0000i
0.5774-0.9428-0.9428
r=
-2.000000
03.0000+0.0000i0
003.0000-0.0000i
R=rank(a)
R=
3
n=inv(a)
-0.1667-0.16670.1667
-0.50000.16670.1667
0.8333-0.16670.1667
…………………………………………………..
5.
临时文件
fun1=inline('
x^3+3*sin(-x/3)-23'
);
fun2=inline('
x^3+3*x-23'
x1=fun1(pi),x2=fun1(5),x3=fun1(3.4)
5.408200468946500
x2=
99.013776126744702
x3=
13.586511915207851
x1=fun2(pi),x2=fun2(5),x3=fun2(3.4)
17.431054641069196
117
26.503999999999991
匿名函数
fun1=@(x)x^3+3*sin(-x/3)-23;
fun2=@(x)x^3+3*x-23;
永久文件
fun1.m
functiony=fun1(x)
y=x^3+3*sin(-x/3)-23;
fun2.m
functiony=fun2(x)
y=x^3+3*x-23;
。
6.
a=[1,4,7,20;
2,5,8,11;
3,-6,9,12];
b=[1;
3;
3];
c=rank(a),d=rank([a,b])
c=
d=
u=null(sym(a))
u=
161/12
5/6
-21/4
1
x=a\b
0
0.0373
0.5652
-0.1553
u=sym(a)\sym(b)
警告:
Systemisrankdeficient.Solutionisnotunique.
25/12
1/6
-1/4
7.
x=[1,1.4,1.8,2.2,2.6,3,3.4,3.8]
1.00001.40001.80002.20002.60003.00003.40003.8000
y=[2,-1.448,-1.664,-0.056,1.968,3,20.144,0.5520]
2.0000-1.4480-1.6640-0.05601.96803.000020.14400.5520
x1=[1.25,2.3,2.9,3.66]
1.25002.30002.90003.6600
y1=interp1(x,y,x1,'
linear'
y1=
-0.15500.45002.74207.4092
y2=spline(x,y,x1)
y2=
-0.64640.71901.205716.1500
spline'
x=[1,1.4,1.8,2.2,2.6,3,3.4,3.8,1.25,2.3,2.9,3.66]
Columns1through9
1.00001.40001.80002.20002.60003.00003.40003.80001.2500
Columns10through12
2.30002.90003.6600
y=[2,-1.448,-1.664,-0.056,1.968,3,20.144,0.5520,-0.6464,0.7190,1.2057,16.1500]
2.0000-1.4480-1.6640-0.05601.96803.000020.14400.5520-0.6464
0.71901.205716.1500
p=polyfit(x,y,4)
-6.950262.2790-192.3240242.1436-105.2824
poly2str(p,'
-6.9502x^4+62.279x^3-192.324x^2+242.1436x-105.2824
8.
symsx
s=int(exp(-x^2),-1,5)
(pi^(1/2)*(erf
(1)+erf(5)))/2
vpa(s,11)
1.6330510583
h=0.000001;
x=-1:
h:
5;
y=exp(-x.^2);
s=h*sum(y)
1.633051242203520
vpa(s,5)
1.6331
s=h*trapz(y)
1.633051058263760
9.
symst
s=int(exp(-0.5*t)*sin(t+pi/6),0,pi*3)
((2*3^(1/2)+1)*(exp(-(3*pi)/2)+1))/5
0.90084078782
h=pi/1000;
t=0:
pi*3;
y=exp(-0.5.*t).*sin(t+pi/6);
0.900840276606885
y='
exp(-0.5.*t).*sin(t+pi/6)'
s=quad(y,0,3*pi)
0.900840811006463
10.
y=dsolve('
D3y=-y'
'
y(0)=1,Dy(0)=0,D2y(0)=0'
exp(-t)/3+(2*exp(t/2)*cos((3^(1/2)*t)/2))/3
11.
fun=@(x,y)y-2*x/y;
[x,y]=ode23(fun,[0,1],[1])
0.080000000000000
0.180********0000
0.280000000000000
0.380000000000000
0.480000000000000
0.580000000000000
0.680000000000000
0.780000000000000
0.880000000000000
0.980000000000000
1.000000000000000
.0770********
1.166********0293
1.249017917208636
1.326676081253747
1.400034750953813
1.469738236869182
1.536284563268660
1.600068179713872
1.661407874348603
1.720565714193718
1.732154879417795
12.
fun=@(x,y)[y
(2);
-6*cos(x)];
ode23(fun,[-10,10],[5,0])
[x,y]=ode23(fun,[-10,10],[5,0])
-10.000000000000000
-9.999984109419911
-9.999904656519465
-9.999507392017236
-9.997521069506089
-9.987589456950357
-9.937931394171693
-9.823011698264244
-9.660813474879619
-9.460729774500120
-9.228030874486807
-8.964651209392159
-8.669191555479403
-8.335338*********
-7.945026707902023
-7.534135580254955
-7.098590248274665
-6.686765918941736
-6.351116143428428
-6.064078404739998
-5.816834208814697
-5.676579279755624
-5.536324350696551
-5.373707097371709
-5.165727528773497
-4.909807675114976
-4.583508333543399
-4.276309013996998
-3.969109694450596
-3.785877313496457
-3.644209936421614
-3.502542559346770
-3.329902814028738
-3.121191612349518
-2.880652050645896
-2.609412677193195
-2.305074556406769
-1.959395503555049
-1.548052236437003
-1.007685620871909
-0.648329535937590
-0.288973451003272
0.026695537887512
0.300568916557177
0.535176937187460
0.723543961635943
0.877312726974181
.0775********
1.324344071307815
1.634484898385757
1.955463740046763
2.276442581707769
2.469137613521180
2.602773107181954
2.736408600842728
2.896537924347151
3.094745633376593
3.325768726230144
3.587505914509060
3.881161418314442
4.212702926788669
4.599180775684407
5.108837174059754
5.487848523711013
5.866859873362272
6.200978970945136
6.489433181994937
6.738394722201685
6.882797275400684
.027*********
7.189********5368
7.396379056423532
7.651474921421556
7.976146768180901
8.304280982143922
8.550804724211686
8.746234647689784
8.881549241653310
9.016863835616837
9.176********4311
9.373476519950946
9.603796908489754
9.864848957890619
10.000000000000000
5.0000000000000000
5.0000000006356260.000080000412110
5.0000000228829070.000480014835347
5.0000006108989170.002480395940464
5.0000154768055770.012490016399744
5.0003887402727680.062729765988340
5.0098245486332430.318564990035898
.0816********
5.3079413752415691.861033444504114
5.7985550246162473.048473276894549
6.6699929290072004.437014602410657
.0379********
10.0111250073972837.378306529500154
12.6901253711142198.582014924615818
16.1963322498005139.238497672087590
19.9691544139016458.958461674000525
23.6170376367415717.630130032011948
26.3649160732226805.618043483159200
27.9279126974898523.668967408411018
28.7345333613971191.957557154672697
.0437********
.0714********
29.002319905912568-0.814292116839208
28.814731710854208-1.473350149009797
28.435981825387298-2.132********3079
27.819762614236211-2.621589449547680
26.936160651409942-2.688135353573485
26.175********5613-2.176********3862
25.651397927203703-1.155********2304
25.512240983073792-0.341307459132607
25.5136534848150910.372132415289034
25.6204153740232951.143482092578525
25.9030849179068532.139********6603
26.4791788365964393.384867129674014
27.4657960455782274.81039