# How do I fit an exponential equation to raw data

5 vues (au cours des 30 derniers jours)
Pierce Hart le 18 Fév 2018
Modifié(e) : Jos (10584) le 19 Fév 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Jos (10584) le 18 Fév 2018
Modifié(e) : Jos (10584) le 19 Fév 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-')
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Pierce Hart le 18 Fév 2018
Hey Jos,
Thanks for your answer. If I simply use what you provide I have an erorr in my code.I follow the outline of what you're doing and sturggle to see where I'm going wrong. I've attached my data and script so you can see.
Jos (10584) le 19 Fév 2018
What is the exact error you get?
(btw I made a mistake in my function, which I fixed)

Connectez-vous pour commenter.

### Plus de réponses (1)

Star Strider le 18 Fév 2018
You can use the fminsearch function to do the nonlinear regression.
The Code
Pressmb = P.Pressmb;
PresRad = @(b,r) exp(-b(1)./(r.^b(2))); % Objective Function
figure
hold on
hold off
ylabel('Pressure (mb)')
legend('Data', 'Fitted Data', 'Location','NW')
text(440, 997, sprintf('P(R) = e^{%.2f/(%.5f\\cdotR)}',B))
grid
The Plot
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by