lsqcurvefit for two different equations and variables
6 次查看(过去 30 天)
显示 更早的评论
Hello,
i have a data which consists of one input value (i) and two output values (Y) values, say Y1 and Y2. I want to fit my experimental data to a model using lsqcurvefit. what i know is that i can fit my data using only one X variable and one Y variable. is there a way that i can optimize my functions to fit both variables at the same time?
i = [1.17451E+00
1.87115E+00
2.98100E+00
4.74915E+00
7.56606E+00
1.20538E+01
1.92034E+01
3.05936E+01
4.87399E+01
7.76494E+01
1.23706E+02
1.97081E+02
3.13978E+02
5.00210E+02
7.96904E+02
1.26958E+03
2.02262E+03
3.22231E+03
5.13358E+03
];
y1 = [242.5088007
444.8689004
802.8335979
1425.305568
2489.312239
4277.004598
7229.179527
12405.99648
20430.99265
33235.46262
53403.34191
87814.94488
138006.2801
213871.8819
326838.3103
492534.4889
731921.9324
1072549.39
1549866.402
];
y2 = [3377.017069
5268.932921
8164.853585
12566.38759
19209.17965
29163.75918
43975.87673
64027.8721
95789.07289
142240.1411
209646.5318
298137.6129
433807.5582
626647.3615
898659.2993
1279418.677
1808323.209
2537378.074
3534598.31
];
% i have 3 parameters
% define the equations
y1_theo = @(x,xdata)x(1).*(1+(x(2)./xdata).^(log10(2)/x(3))).^(-x(3)./log10 (2));
% define d
y2_theo = @(x,xdata)90./(1+(xdata./x(2)).^(log10(2)./x(3)));
% initial values
x0 = [1E+9 1000 1];
% specify the bounds
lb=[0 0 0];
ub = [inf inf inf];
% optimize
[x,resnorm,~,exitflag,output] = lsqcurvefit([y1_theo y2_theo],x0,i,[y1 y2],lb,ub)
I have tried to write the code as above, but it is not working, can someone please help me with this?
0 个评论
采纳的回答
Star Strider
2020-6-3
This works, however it only fits one of the curves:
y_theo = @(x,xdata) [x(1).*(1+(x(2)./xdata).^(log10(2)/x(3))).^(-x(3)./log10 (2)), 90./(1+(xdata./x(2)).^(log10(2)./x(3)))];
x0 = [1E+9 1000 1];
% specify the bounds
lb=[0 0 0];
ub = [inf inf inf];
% optimize
[x,resnorm,~,exitflag,output] = lsqcurvefit(y_theo,x0,i,[y1 y2],lb,ub)
figure
plot(i, [y1 y2], 'p')
hold on
plot(i, y_theo(x,i), '-r')
hold off
grid
It may be necessary to review both parts of ‘y_theo’ to be certain they are coded correctly, and that ‘x0’ is appropriate. (I have used this sort of construction in other problems, and it worked as it should.)
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!