Finding exponential curve and r-squared using polyfit

I have been trying to figure out how to find the exponential regression and r-squared given a set of x and y values as t and P. The equation I am given is P = a*e^(-b/t) This is my code
temp = [10:10:200];
pres = [1.227, 2.337, 4.241, 7.375, 12.340, 19.920,31.160,47.360, 70.110,101.330,143.270,198.540,270.130,361.380,476.000,618.060,792.020,1002.700,1255.100,1554.900]
tnew = 1.0 ./ (273.15+temp)
logp = log(pres)
AB = polyfit(tnew, logp, 1)
a = exp(AB(1))
b = -AB(2)
curve = a * exp(b./tnew)
r2 = 1 - sum(((a-b)./tnew-logp).^2)/ sum(( logp- mean(logp)).^2)
Can anyone help me out?

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by