simultaneously, fitting two functions with two databases
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have two data sets y1(x00) and y2(x00) in the x00 range, as:
x00=[0,1,1.5,2,2.5,3,3.5,4,4.5,5]*2*pi/3;
y1=[0,1.082,2.27,3.91,5.93,8.24,10.69,13.02,14.83,15.55];
y2=[36.39,36.16,35.81,35.24,34.40,33.27,31.88,30.39,29.11,29.00];
I need fitting both functions f1=@(c1,c21,c22,c3,x) and f2=@(c1,c21,c22,c3,x), with these data in ranges x00.
Note that [c1,..,c4] are required constant coefficients and x is the varibale in range of the x00. I need to obtain the [c1,..,c4] parameters.
In my search, I found nonlinear least squre methodes with matlab, but please take into account that I am new to Matlab and can only curve fit very basic data points.
x00=[0,1,1.5,2,2.5,3,3.5,4,4.5,5]*2*pi/3;
y1=[0,1.082,2.27,3.91,5.93,8.24,10.69,13.02,14.83,15.55];
y2=[36.39,36.16,35.81,35.24,34.40,33.27,31.88,30.39,29.11,29.00];
f1=@(c1,c21,c22,c3,x) sqrt( 2.0*c21*cos(1.5*x) - 3.0*c3 - 2.0*c21 - 2.0*c22 - 3.0*c1 + 2.0*c22*cos(1.5*x) - 1.0*exp(-x*1.5i)*(c1*c3 + 2.0*c1^2*exp(x*4.5i) + 2.0*c1^2*exp(x*1.5i) + 5.0*c1^2*exp(x*3.0i) + 5.0*c3^2*exp(x*3.0i) + 2.0*c3^2*exp(x*6.0i) + 6.0*c21^2*exp(x*3.0i) + 6.0*c22^2*exp(x*3.0i) + 2.0*c3^2 - 8.0*c21^2*exp(x*3.0i)*cos(1.5*x) + 2.0*c21^2*exp(x*3.0i)*cos(3.0*x) - 8.0*c22^2*exp(x*3.0i)*cos(1.5*x) + 2.0*c22^2*exp(x*3.0i)*cos(3.0*x) + 6.0*c1*c3*exp(x*4.5i) + 6.0*c1*c3*exp(x*1.5i) + 4.0*c1*c3*exp(x*3.0i) + c1*c3*exp(x*6.0i) - 12.0*c21*c22*exp(x*3.0i) + 16.0*c21*c22*exp(x*3.0i)*cos(1.5*x) - 4.0*c21*c22*exp(x*3.0i)*cos(3.0*x))^(1/2));
f2=@(c1,c21,c22,c3,x) sqrt( 2.0*c21*cos(1.5*x) - 3.0*c3 - 2.0*c21 - 2.0*c22 - 3.0*c1 + 2.0*c22*cos(1.5*x) + exp(-x*1.5i)*(c1*c3 + 2.0*c1^2*exp(x*4.5i) + 2.0*c1^2*exp(x*1.5i) + 5.0*c1^2*exp(x*3.0i) + 5.0*c3^2*exp(x*3.0i) + 2.0*c3^2*exp(x*6.0i) + 6.0*c21^2*exp(x*3.0i) + 6.0*c22^2*exp(x*3.0i) + 2.0*c3^2 - 8.0*c21^2*exp(x*3.0i)*cos(1.5*x) + 2.0*c21^2*exp(x*3.0i)*cos(3.0*x) - 8.0*c22^2*exp(x*3.0i)*cos(1.5*x) + 2.0*c22^2*exp(x*3.0i)*cos(3.0*x) + 6.0*c1*c3*exp(x*4.5i) + 6.0*c1*c3*exp(x*1.5i) + 4.0*c1*c3*exp(x*3.0i) + c1*c3*exp(x*6.0i) - 12.0*c21*c22*exp(x*3.0i) + 16.0*c21*c22*exp(x*3.0i)*cos(1.5*x) - 4.0*c21*c22*exp(x*3.0i)*cos(3.0*x))^(1/2));
Any support will help me, thanks.
Please assist.
3 commentaires
Star Strider
le 14 Août 2022
Looking at ‘f1’ and ‘f2’, they appear to produce a complex result because of the complex exponential. They also seem to be the same except for the seventh terms that have opposite signs. Is one of the dependent variables supposed to fit one of the functions and the other dependent variable the other, or one the real part of the function and the other the imaginary part of the function, or something else?
Also, it might be better to square the independent variables and fit the functions without taking the square roots, for the obvious reason that there are going to be two square roots resulting from each function.
Réponse acceptée
Torsten
le 14 Août 2022
I think you will have to work on the representation of f1 and f2 without the imaginary unit:
c10 = 3.0;
c210 = 1.0;
c220 = -1.0;
c30 = 0.5;
C0 = [c10,c210,c220,c30];
x = [0,1,1.5,2,2.5,3,3.5,4,4.5,5]*2*pi/3;
y1 = [0,1.082,2.27,3.91,5.93,8.24,10.69,13.02,14.83,15.55];
y2 = [36.39,36.16,35.81,35.24,34.40,33.27,31.88,30.39,29.11,29.00];
f1 =@(c1,c21,c22,c3) real(2.0*c21*cos(1.5*x) - 3.0*c3 - 2.0*c21 - 2.0*c22 - 3.0*c1 + 2.0*c22*cos(1.5*x) - exp(-x*1.5i).*(c1*c3 + 2.0*c1^2*exp(x*4.5i) + 2.0*c1^2*exp(x*1.5i) + 5.0*c1^2*exp(x*3.0i) + 5.0*c3^2*exp(x*3.0i) + 2.0*c3^2*exp(x*6.0i) + 6.0*c21^2*exp(x*3.0i) + 6.0*c22^2*exp(x*3.0i) + 2.0*c3^2 - 8.0*c21^2*exp(x*3.0i).*cos(1.5*x) + 2.0*c21^2*exp(x*3.0i).*cos(3.0*x) - 8.0*c22^2*exp(x*3.0i).*cos(1.5*x) + 2.0*c22^2*exp(x*3.0i).*cos(3.0*x) + 6.0*c1*c3*exp(x*4.5i) + 6.0*c1*c3*exp(x*1.5i) + 4.0*c1*c3*exp(x*3.0i) + c1*c3*exp(x*6.0i) - 12.0*c21*c22*exp(x*3.0i) + 16.0*c21*c22*exp(x*3.0i).*cos(1.5*x) - 4.0*c21*c22*exp(x*3.0i).*cos(3.0*x))).^(1/2) - y1.^2;
f2 =@(c1,c21,c22,c3) real(2.0*c21*cos(1.5*x) - 3.0*c3 - 2.0*c21 - 2.0*c22 - 3.0*c1 + 2.0*c22*cos(1.5*x) + exp(-x*1.5i).*(c1*c3 + 2.0*c1^2*exp(x*4.5i) + 2.0*c1^2*exp(x*1.5i) + 5.0*c1^2*exp(x*3.0i) + 5.0*c3^2*exp(x*3.0i) + 2.0*c3^2*exp(x*6.0i) + 6.0*c21^2*exp(x*3.0i) + 6.0*c22^2*exp(x*3.0i) + 2.0*c3^2 - 8.0*c21^2*exp(x*3.0i).*cos(1.5*x) + 2.0*c21^2*exp(x*3.0i).*cos(3.0*x) - 8.0*c22^2*exp(x*3.0i).*cos(1.5*x) + 2.0*c22^2*exp(x*3.0i).*cos(3.0*x) + 6.0*c1*c3*exp(x*4.5i) + 6.0*c1*c3*exp(x*1.5i) + 4.0*c1*c3*exp(x*3.0i) + c1*c3*exp(x*6.0i) - 12.0*c21*c22*exp(x*3.0i) + 16.0*c21*c22*exp(x*3.0i).*cos(1.5*x) - 4.0*c21*c22*exp(x*3.0i).*cos(3.0*x))).^(1/2) - y2.^2;
F = @(c)[f1(real(c(1)),real(c(2)),real(c(3)),real(c(4))),f2(real(c(1)),real(c(2)),real(c(3)),real(c(4)))];
C = lsqnonlin(F,C0)
norm(F(C))
C = real(C)
2 commentaires
Torsten
le 15 Août 2022
At least this gives you some hints on how to set up your problem. The fitting results itself are bad - so I think you will have to further modify f1 and f2.
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!