cftool 曲线拟合。

楼主最近在用matlab中cftool工具箱中的custom equation做曲线拟合时,用的表达式是y=4.1855-a*exp(b*x)-c*exp(d*x) 为什么拟合出来的a、b、c、d参数的正负号问题和实际问题不符合 a、c是电压参数应该为正 b、d参数应该也是常数。附上数据:
x=[0.100000000000000;0.200000000000000;0.300000000000000;0.400000000000000;0.500000000000000;0.600000000000000;0.700000000000000;0.800000000000000;0.900000000000000;1;1.10000000000000;1.20000000000000;1.30000000000000;1.40000000000000;1.50000000000000;1.60000000000000;1.70000000000000;1.80000000000000;1.90000000000000;2;2.10000000000000;2.20000000000000;2.30000000000000;2.40000000000000;2.50000000000000;2.60000000000000;2.70000000000000;2.80000000000000;2.90000000000000;3.00000000000000;3.10000000000000;3.20000000000000;3.30000000000000;3.40000000000000;3.50000000000000;3.60000000000000;3.70000000000000;3.80000000000000;3.90000000000000;4;4.10000000000000;4.20000000000000;4.30000000000000;4.40000000000000;4.50000000000000;4.60000000000000;4.70000000000000;4.80000000000000;4.90000000000000;5;5.10000000000000;5.20000000000000;5.30000000000000;5.40000000000000;5.50000000000000;5.60000000000000;5.70000000000000;5.80000000000000;5.90000000000000;6;6.10000000000000;6.20000000000000;6.30000000000000;6.40000000000000;6.50000000000000;6.60000000000000;6.70000000000000;6.80000000000000;6.90000000000000;7;7.10000000000000;7.20000000000000;7.30000000000000;7.40000000000000;7.50000000000000;7.60000000000000;7.70000000000000;7.80000000000000;7.90000000000000;8;8.10000000000000;8.20000000000000;8.30000000000000;8.40000000000000;8.50000000000000;8.60000000000000;8.70000000000000;8.80000000000000;8.90000000000000;9;9.10000000000000;9.20000000000000;9.30000000000000;9.40000000000000;9.50000000000000;9.60000000000000;9.70000000000000;9.80000000000000;9.90000000000000;10];
y=[4.14150000000000;4.14150000000000;4.14120000000000;4.14120000000000;4.14090000000000;4.14060000000000;4.14030000000000;4.14030000000000;4.14000000000000;4.13960000000000;4.13930000000000;4.13930000000000;4.13900000000000;4.13870000000000;4.13870000000000;4.13840000000000;4.13810000000000;4.13810000000000;4.13780000000000;4.13750000000000;4.13720000000000;4.13720000000000;4.13690000000000;4.13620000000000;4.13620000000000;4.13590000000000;4.13560000000000;4.13560000000000;4.13530000000000;4.13530000000000;4.13500000000000;4.13470000000000;4.13470000000000;4.13440000000000;4.13410000000000;4.13410000000000;4.13380000000000;4.13380000000000;4.13340000000000;4.13340000000000;4.13310000000000;4.13310000000000;4.13280000000000;4.13280000000000;4.13250000000000;4.13250000000000;4.13220000000000;4.13220000000000;4.13190000000000;4.13190000000000;4.13190000000000;4.13160000000000;4.13160000000000;4.13130000000000;4.13130000000000;4.13100000000000;4.13100000000000;4.13070000000000;4.13070000000000;4.13070000000000;4.13030000000000;4.13030000000000;4.13000000000000;4.13000000000000;4.12970000000000;4.12970000000000;4.12910000000000;4.12910000000000;4.12910000000000;4.12880000000000;4.12880000000000;4.12850000000000;4.12850000000000;4.12850000000000;4.12820000000000;4.12820000000000;4.12790000000000;4.12790000000000;4.12760000000000;4.12760000000000;4.12760000000000;4.12720000000000;4.12720000000000;4.12690000000000;4.12690000000000;4.12690000000000;4.12660000000000;4.12660000000000;4.12630000000000;4.12630000000000;4.12630000000000;4.12600000000000;4.12600000000000;4.12570000000000;4.12570000000000;4.12570000000000;4.12540000000000;4.12540000000000;4.12510000000000;4.12510000000000];

 Accepted Answer

dowexoc
dowexoc on 19 Nov 2022

0 votes

clear,clc
x=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9.0, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10.0]';
y=[4.1415, 4.1415, 4.1412, 4.1412, 4.1409, 4.1406, 4.1403, 4.1403, 4.14, 4.1396, 4.1393, 4.1393, 4.139, 4.1387, 4.1387, 4.1384, 4.1381, 4.1381, 4.1378, 4.1375, 4.1372, 4.1372, 4.1369, 4.1362, 4.1362, 4.1359, 4.1356, 4.1356, 4.1353, 4.1353, 4.135, 4.1347, 4.1347, 4.1344, 4.1341, 4.1341, 4.1338, 4.1338, 4.1334, 4.1334, 4.1331, 4.1331, 4.1328, 4.1328, 4.1325, 4.1325, 4.1322, 4.1322, 4.1319, 4.1319, 4.1319, 4.1316, 4.1316, 4.1313, 4.1313, 4.131, 4.131, 4.1307, 4.1307, 4.1307, 4.1303, 4.1303, 4.13, 4.13, 4.1297, 4.1297, 4.1291, 4.1291, 4.1291, 4.1288, 4.1288, 4.1285, 4.1285, 4.1285, 4.1282, 4.1282, 4.1279, 4.1279, 4.1276, 4.1276, 4.1276, 4.1272, 4.1272, 4.1269, 4.1269, 4.1269, 4.1266, 4.1266, 4.1263, 4.1263, 4.1263, 4.126, 4.126, 4.1257, 4.1257, 4.1257, 4.1254, 4.1254, 4.1251, 4.1251]';
fx1=@(b,x)4.1855-b(1)*exp(b(2)*x)-b(3)*exp(b(4)*x);
fx2=@(b,x)(b(1)+b(2)*x+b(3)*x.^2)./(1+b(4)*exp(b(5)*x.^2));
b1=[-0.008842326585 -0.2206452512 0.05213333521 0.01635157441];
b2=[4.139594755 -0.001647275513 1.890084207e-05 -0.0005259496851 -0.1936895608];
for l=1:5
b1=lsqcurvefit(fx1,b1,x,y);
b1=nlinfit(x,y,fx1,b1);
b2=lsqcurvefit(fx2,b2,x,y);
b2=nlinfit(x,y,fx2,b2);
end
figure(1),clf
plot(x,y,'bo','markersize',8)
x1=linspace(min(x)-.5,max(x)+.5,350);
y1=fx1(b1,x1);
y2=fx2(b2,x1);
hold on
plot(x1,y1,'k-','linewidth',1.5)
plot(x1,y2,'r-','linewidth',1.5)
axis tight
legend('data','fit1','fit2','location','best')
RSS1=(y-fx1(b1,x))'*(y-fx1(b1,x))
RSS2=(y-fx2(b2,x))'*(y-fx2(b2,x))
如图。

More Answers (0)

Tags

Asked:

on 19 Nov 2022

Answered:

on 19 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!