How do I fit an exponential equation to raw data
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pierce Hart
il 18 Feb 2018
Modificato: Jos (10584)
il 19 Feb 2018
I have been given raw data from a hurricane with the x component, radius, x=59:803 and Y component, pressure, data varying from around 990 to 1020. I have an equaiton y=exp(-A/(x^B)) and want to find coefficients A and B from the raw data. I did try applying fit and to no avail. I'm unfamiliar with these functions so perhaps I was using them incorrectly.
I hope you can help, Thanks.
PH
0 Commenti
Risposta accettata
Jos (10584)
il 18 Feb 2018
Modificato: Jos (10584)
il 19 Feb 2018
This should get you started:
% some data
x = 1:20 ;
y = exp(-10 ./ (x .^ 1.1)) ;
yr = y + randn(size(y))/10 ; % add noise
% fit procedure
g = fittype(@(A,B,x) exp(-A ./ (x.^B)))
f = fit(x(:),yr(:), g )
% result
yh = f(x) ;
plot(x,yr,'bo',x,y,'b:.',x,yh,'rs-')
For more information, read the documentation on fit.
3 Commenti
Jos (10584)
il 19 Feb 2018
What is the exact error you get?
(btw I made a mistake in my function, which I fixed)
Più risposte (1)
Star Strider
il 18 Feb 2018
You can use the fminsearch function to do the nonlinear regression.
The Code —
P = load('pressure.mat.txt');
R = load('radius.mat.txt');
Pressmb = P.Pressmb;
Radkm = R.Radkm;
PresRad = @(b,r) exp(-b(1)./(r.^b(2))); % Objective Function
B = fminsearch(@(b) norm(Pressmb - PresRad(b,Radkm)), [1, 1]);
RadV = linspace(min(Radkm), max(Radkm));
figure
plot(Radkm, Pressmb, 'pg')
hold on
plot(RadV, PresRad(B, RadV), '-r')
hold off
xlabel('Radius (km)')
ylabel('Pressure (mb)')
legend('Data', 'Fitted Data', 'Location','NW')
text(440, 997, sprintf('P(R) = e^{%.2f/(%.5f\\cdotR)}',B))
grid
The Plot —
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179136/image.png)
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!