Matlab中,关于曲线拟合的问题!那位高手帮我做一下这个matlab的曲线拟合问题!hx=[137.7699554137.7719955137.7634158137.2436762136.8213823137.1116036136.8567032136.810182136.3980186136.2150053136.1752496135.8923706135.7208186135.2
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/05 19:38:52
Matlab中,关于曲线拟合的问题!那位高手帮我做一下这个matlab的曲线拟合问题!hx=[137.7699554137.7719955137.7634158137.2436762136.8213823137.1116036136.8567032136.810182136.3980186136.2150053136.1752496135.8923706135.7208186135.2
Matlab中,关于曲线拟合的问题!
那位高手帮我做一下这个matlab的曲线拟合问题!
hx=[137.7699554
137.7719955
137.7634158
137.2436762
136.8213823
137.1116036
136.8567032
136.810182
136.3980186
136.2150053
136.1752496
135.8923706
135.7208186
135.2451707
135.2728581
134.5948898
134.3563914
134.5380509
134.4293285
133.95397
133.81371
133.7630312
133.40488
133.1147648
133.1261521
132.6218493
132.4923748
131.8706343
132.0098587
131.8892554
131.8683221
131.3473314
131.2803557
131.0240088
130.5984378
130.4394363
130.1305073
130.0036691
129.3785403
129.1337541
129.1461066
129.0079484
128.8133323
128.5039209
128.3054625
128.2054142
127.7223371
127.4256424
127.5652494
127.0671263
126.5290465
126.8274645
126.5512294
126.2100718
125.9566193
125.8578291
125.460809
125.3081621
125.1405776
124.8403313
124.4580766
124.007329
123.6520613
123.6139543
123.1620506
123.0993301
122.6425939
122.3230297
122.0256828
121.7823608
121.6673579
121.0139916
120.7392876
120.1394678
119.9347381
119.5963817
119.4558118
118.8791308
118.6840487
118.1493573
117.8626148
];
py=[3.480750708
3.480752173
3.462591916
3.427757508
3.392915314
3.357982397
3.323134494
3.288446258
3.253603256
3.218669831
3.183873732
3.149020401
3.114265498
3.07942757
3.044599973
3.009778214
2.974925896
2.940188768
2.905244865
2.870406917
2.83564897
2.800751537
2.766057544
2.731204796
2.696332527
2.661496895
2.626631313
2.591989048
2.557106572
2.522286278
2.487412024
2.452547064
2.417865055
2.383009613
2.34813703
2.313309062
2.278457824
2.243745355
2.208770657
2.174067614
2.139190705
2.104330421
2.06962337
2.034772174
1.999912111
1.96504879
1.930211472
1.895527912
1.860676111
1.825794001
1.791037739
1.756142591
1.721406787
1.686593412
1.651737749
1.616839063
1.582030158
1.54731976
1.512457237
1.477609942
1.442764574
1.40784802
1.373250437
1.338377571
1.303445779
1.268671508
1.233816763
1.199165703
1.1642722
1.129415735
1.094553662
1.059729964
1.025105986
0.990282659
0.955423114
0.920578899
0.885714229
0.851037725
0.816182068
0.781318228
0.746500564
];
求曲线拟合:f=a*(x-170.87)^n 并且都用plot 在一个图上画出.(用不同颜色)
急死了,怎么算都是两个交叉的.是哪儿搞错了啊?我用下面这个做的:
s = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[],...
'Upper',[],...
'Startpoint',[]);
f = fittype('a*(x-170.87)^n','problem','n','options',s);
呃.对不起,我打错了.是f=a*(107.87-x)^n,107.87不是170.87
您看看还是按照您这么算么?
Matlab中,关于曲线拟合的问题!那位高手帮我做一下这个matlab的曲线拟合问题!hx=[137.7699554137.7719955137.7634158137.2436762136.8213823137.1116036136.8567032136.810182136.3980186136.2150053136.1752496135.8923706135.7208186135.2
你的拟合函数有问题,因为从向量hx来看其取值范围一直小于170.87,因此x-170.87将一直会是一个负数,而实际应用中指数函数的底数要求是一定为正数,因此把拟合函数改为f=a*(170.87-x)^n还比较靠谱.很显然等式两边均为正数,因此可以考虑对两边取对数,得到log(f)=n*log(170.87-x)+log(a),那么这个问题实际上就转化为了一个线性拟合问题,程序如下(数据此处不列出,但实际运行时要有):
x = log10(170.87 - hx);
y = log10(py);
[p,S] = polyfit(x,y,1);
n = p(1);
a = 10 ^ p(2);
% 求拟合后的结果,此式也可:f = 10 .^ polyval(p,x);
f = a * ((170.87 - hx) .^ n);
plot(hx,py,'r',hx,f,'b');
你说的是f=a*(x-107.87)^n吗?那样程序不用做大改动,只需改成下面:
x = log10(hx - 107.87);
y = log10(py);
[p,S] = polyfit(x,y,1);
n = p(1);
a = 10 ^ p(2);
% 求拟合后的结果,此式也可:f = 10 .^ polyval(p,x);
f = a * ((hx - 107.87) .^ n);
plot(hx,py,'r',hx,f,'b');