How can I fit my data to an inverse tangent function?
43 次查看(过去 30 天)
显示 更早的评论
I'm trying to fit my data to an inverse tangent function. The function is:
y = atan(x*a/b/(a^2-x^2));
where a and b are the constants that I'd like to determine by fitting the data.
What I would like most is a working example of how to go about doing this. The data that I'm working with can be seen below.
%%Fit data to inverse tangent function
% y = atan(x*a/b/(a^2-x^2));
clear all; close all; clc;
x = [0.7 0.8 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4,2.6];
y = [10 11 15 15 15 17 20 25 34 47 75 100 140 155 162 170 171 176];
plot(x,y,'bo');
0 个评论
回答(4 个)
David Sanchez
2013-10-23
x = [0.7 0.8 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4,2.6];
y = [10 11 15 15 15 17 20 25 34 47 75 100 140 155 162 170 171 176];
% y = atan(x*a/b/(a^2-x^2))
modelFun = @(p,x) atan(x.*p(1)./p(2)./(p(1)^2-x.^2)); % p(1) = a; p(2) = b
startingVals = [1 1]; % try with any other starting values.
coefEsts = nlinfit(x,y, modelFun, startingVals);
Runze Ma
2022-5-26
Don't know if you guys have solved the problem or not. As I understand, this fitting is to get the resonance frequency and quality factor out of a phase sweep.
I figured out that the formula of y = atan(x*a/b/(a^2-x^2)) is not suitable for fitting in MATLAB due to the different period settings for the formula and the atan function in MATLAB. This will result in a discontinuity at resonance position f=f0. Instead, you should be using y=atan(b*(a^2-x^2)/a/x). This way, the funciton can run smoothly from -inf to inf and suitable for fitting.
Hope this will help anyone to solve the resonance problem.
0 个评论
Gabriel Felix
2023-7-21
This site has a useful complete guide to tangent/arctangent curve fitting. It uses python,though. However it had success using a certaing kind of tangent function for the fitting.
0 个评论
John D'Errico
2023-7-21
x = [0.7 0.8 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4,2.6];
y = [10 11 15 15 15 17 20 25 34 47 75 100 140 155 162 170 171 176];
First, LOOK AT YOUR DATA. PLOT IT. ALWAYS! Does it have the fundamental shape of an inverse tangent function?
plot(x,y,'o')
fplot(@atan)
And we see the curve does look like an atan function, though many other basic curves in the general sigmoidal family of functions might also apply. (So I might have chosen a sigmoid function, a cumulative normal, an atan, etc. Give me a minute or so, and I could pick at least a few more.) However, your specific question actually is not a simple atan function.
yfun = @(x,a,b) atan(x*a/b./(a^2-x.^2));
Note my use of the dotted operators to allow the function to be evaluated at many points at once. I'll just pick some simple values for a and b.
fplot(@(x) yfun(x,1,1))
And there we see the function family you are looking at does not have even a close to reasonable shape as that of your data. It cannot be used to fit your data. The result would be complete and utter garbage. I'm sorry, but it would.
mdl = fittype('a + b*atan((x - c)/d)','indep','x')
I've picked some starting corefficients directly from the plot itself, NOT by trying a fit, and then choosing and re-choosing new sets of start points. Admitedly, I was off by a bit on the parameter d, and had I thought just a bit longer when I was typing them in, I would have known a better value. But anything within a factor of 5 or so is close enough most of the time.
fittedmdl = fit(x',y',mdl,'start',[100 50 2 1])
plot(fittedmdl,x,y)
That simple atan model fits your data really quite well. I don't know why you think the model you chose would be appropriate.
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!