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?
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!