simultaneously, fitting two functions with two databases

1 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2022-8-14
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.
Arad
Arad 2022-8-14
编辑:Arad 2022-8-14
Thank you for your attentions.
  1. The f1 and f2 are roots of the 2-th equation and have same components in their terms. They have form as: F1=sqrt[A+sqrt[B]] and F2=sqrt[A-sqrt[B]].
  2. Although, they have complex terms in their boady, but they are real functions.
  3. You can neglicated the sqrt, and I change the database after it.
  4. the c1,c21,c22,c3 are real parameters.
A22= 2*c22*(2*cos((3*x)/2) - 2) - 3*c3 - 3*c1;
A21= 2*c21*(2*cos((3*x)/2) - 2) - 3*c3 - 3*c1;
B1=c1*(exp(x*1i) + 2*exp(-(x*1i)/2))
B3=c3*(2*exp(x*1i) + exp(-x*2i))
f1=sqrt((A11+A22)/2 - (abs(B1)^2 + abs(B3)^2 + B1*conj(B3) + B3*conj(B1) + ((A11-A22)/2)^2)^(1/2))
f2=sqrt((A11+A22)/2 + (abs(B1)^2 + abs(B3)^2 + B1*conj(B3) + B3*conj(B1) + ((A11-A22)/2)^2)^(1/2))
If needed, I calculate the functions analytically and write their real form which is based on the Cos(x)???

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2022-8-14
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)
Local minimum possible. lsqnonlin stopped because the size of the current step is less than the value of the step size tolerance.
C =
61.9452 +11.9296i 1.4621 -43.5196i -1.8836 +33.6286i 56.3354 -80.1942i
norm(F(C))
ans = 3.3212e+03
C = real(C)
C = 1×4
61.9452 1.4621 -1.8836 56.3354
  2 个评论
Torsten
Torsten 2022-8-15
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.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by