Curve fitting to atan function not working

조회 수: 11 (최근 30일)
Yousef Safadi
Yousef Safadi 2021년 8월 29일
댓글: Yousef Safadi 2021년 8월 29일
I have a set of 2x9 data vectors that I need to curve fit to the following function, I've been going at it all day with little to no success, tried limiting upper/lower limits of the coefficients as well as the starting points to something that would resemble the theoritical values to no avail.
Here's what I ended up with: result
For reference, the end result should result in a similar shape to this, a monotonically decreasing function with a limit of 0 as we approach 0 and a limit of -pi as we approch infinity.
I should note that I found the theoritical values using a different model and from that concluded that w0 should be around the 6.3 mark and t (tau) should be about 2.1-2.2
phi_A=[-3.228;1.574;-0.8063;0.02548;1.904;2.87;1.853;-1.824;3.929];
phi_B=[-3.259;-1.466;-3.859;-3.035;-1.18;2.857;1.851;-1.811;0.9015];
omega_A=[4.453;8.348;10.36;11.95;13.19;3.762;2.07;0.4691;7.921];
delta_phi=phi_B-phi_A;
figure(2);
[sorted_omega, asc]=sort(omega_A);
sorted_phi=delta_phi(asc);
plot(sorted_omega,sorted_phi,'bo');

채택된 답변

John D'Errico
John D'Errico 2021년 8월 29일
편집: John D'Errico 2021년 8월 29일
phi_A=[-3.228;1.574;-0.8063;0.02548;1.904;2.87;1.853;-1.824;3.929];
phi_B=[-3.259;-1.466;-3.859;-3.035;-1.18;2.857;1.851;-1.811;0.9015];
omega_A=[4.453;8.348;10.36;11.95;13.19;3.762;2.07;0.4691;7.921];
delta_phi=phi_B-phi_A;
figure(2);
[sorted_omega, asc]=sort(omega_A);
sorted_phi=delta_phi(asc);
plot(sorted_omega,sorted_phi,'bo')
You really have insufficient information to know the shape of that function between the upper and lower asymptotes.
So the fit will be completely useless crap, in terms of any estimates for the parameters. Worse, you already know the upper and lower asymptotes. So that data is indeed completely useless. Good luck. :)
Can you use say, the curve fitting toolbox? Of course, as that is usually my recommentation as the best choice.
You would do something like this:
mdl = fittype('atan(-omega./(tau*(omega0.^2 - omega^2)))','indep','omega')
mdl =
General model: mdl(omega0,tau,omega) = atan(-omega./(tau*(omega0.^2 - omega^2)))
estmdl = fit(sorted_omega,sorted_phi,mdl,'start',[6,1],'lower',[5,0.1],'upper',[8,10])
estmdl =
General model: estmdl(omega) = atan(-omega./(tau*(omega0.^2 - omega^2))) Coefficients (with 95% confidence bounds): omega0 = 5 (fixed at bound) tau = 10 (-556.6, 576.6)
figure
plot(sorted_omega,sorted_phi,'bo')
hold on
plot(estmdl)
grid on
hold off
But then you will see that in fact, this model has not a chance in hell of EVER fitting that data.
In fact, it has a singularity at omega0. So whoever gave you that model is totally dreaming.
So, is there a model that has at least the desired shape, that uses atan? Well, yes. Even so, the fit will be, as I said before, complete and total crapola.
But suppose you plot the atan function.
figure
fplot(@atan)
So the atan function has asymptotes at -pi/2 and pi/2. What you want to see looks like...
fplot(@(theta) -atan(theta) - pi/2)
This has the fundamental shape you seem to want. INtroducing a shift and scale, we will get this:
mdl = fittype('-atan(tau*(omega - omega0)) - pi/2','indep','omega')
mdl =
General model: mdl(omega0,tau,omega) = -atan(tau*(omega - omega0)) - pi/2
estmdl = fit(sorted_omega,sorted_phi,mdl,'start',[1,6])
estmdl =
General model: estmdl(omega) = -atan(tau*(omega - omega0)) - pi/2 Coefficients (with 95% confidence bounds): omega0 = 7.011 (5.992, 8.031) tau = 8.297 (0.6966, 15.9)
figure
plot(sorted_omega,sorted_phi,'bo')
hold on
plot(estmdl)
grid on
hold off
Note that the confidence limits on the parameters are REALLY wide. And that means that, while the model sort of fits your data, it is just a pipe dream. Of course, it is a wildly better pipe dream than what you were given to use.
As I said, the model you wanted to use is utter drivel in this context.
  댓글 수: 1
Yousef Safadi
Yousef Safadi 2021년 8월 29일
Yeah I doubted the model as well, double checked with my tutor, referred to the given pages and found a similar model on google and they all seem to match what I was given, that being said I appreciate your help, this seems miles better than not having anything to work with. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by