Least square fitting - lsqcurvefit - multiple equations - not enough input arguments -

1 次查看(过去 30 天)
Hello everyone,
I am trying to fit some experimental data to a cerain model,
my data:
x_exp = [0.109112654
0.174029442
0.2775686
0.442708583
0.706098923
1.126193863
1.796225113
2.864892769
4.569366345
7.28791982
];
y_exp = [5247.044317
8170.755912
12604.15367
19261.43738
29160.90041
42700.48525
63815.24278
95016.30828
140804.9657
207196.2571
];
i want to fit this data using lsqcurvefit, but the problem is my model is not a one line code, it is contructed as follows, it has 4 parameters, o is the variable and my final output is G, i want to fit my y_exp with G:
% parameters are k , tau , Gg , G0
A = (o*tau)^-k * cos (k*pi/2);
B = (o*tau)^-k * sin (k*pi/2);
G1 = G0 + (((Gg-G0)* (1+A))/ (((1+A)^2)+B^2));
G2 = ((Gg-G0)* (-B)/ (((1+A)^2)+B^2));
G = ((G1^2 + G2^2)^0.5);
when i used lsqcurvefit, i constructed the code as follows, but i keep getting a message (Not enough input arguments):
% define A & B
A = @(x,xdata)(xdata*x(2))^-x(1) * cos (x(1)*pi/2);
B = @(x,xdata)(xdata*x(2))^-x(1) * sin (x(1)*pi/2);
% Define G' & G''
G1 = @(x,xdata)x(4) + (((x(3)-x(4))* (1+A(x)))/ (((1+A(x))^2)+B(x)^2));
G2 = @(x,xdata)((x(3)-x(4))* (-B(x))/ (((1+A(x))^2)+B(x)^2));
% Define G
G = @(x,xdata)((G1(x)^2 + G2(x)^2).^0.5);
x0 = [0.5 1E-4 1E+7 1E-5];
[x,resnorm,~,exitflag,output] = lsqcurvefit(G,x0,x_exp,y_exp)
can any one please help me with this?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-17
There are few errors in writing the equations. Following code correct those
A = @(x,xdata)(xdata*x(2)).^-x(1) * cos (x(1)*pi/2);
B = @(x,xdata)(xdata*x(2)).^-x(1) * sin (x(1)*pi/2);
% Define G' & G''
G1 = @(x,xdata)x(4) + (((x(3)-x(4))* (1+A(x,xdata)))./(((1+A(x,xdata)).^2)+B(x,xdata).^2));
G2 = @(x,xdata)((x(3)-x(4))* (-B(x,xdata))./(((1+A(x,xdata)).^2)+B(x,xdata).^2));
% Define G
G = @(x,xdata)((G1(x,xdata).^2 + G2(x,xdata).^2).^0.5);
x0 = [0.5 1E-4 1E+7 1E-5];
[x,resnorm,~,exitflag,output] = lsqcurvefit(G,x0,x_exp,y_exp)
However, now the issue is that lsqcurvefit converges to a wrong output, which is not optimal. Are you sure your model is correct?
  7 个评论
Ameer Hamza
Ameer Hamza 2020-5-18
The solution posted by Alex is calculated using another optimization package, called 1stOpt. That is different software, so MATLAB code cannot be used in that.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by