How do I write the Exponential Decay in Matlab?

What I need to do is plot the exponential decay using the given matrix and the formula y=a e^-bx I believe I have to write the formula in a different way using log but I do not understand how in matlab.
code:
%given matrix
x=[0;1;2;3;4;5;6]
y=[32;47;65;92;132;190;275]
n=size(x);
x1=[ones(n(1),1) x]
x1'
b=inv(y)*(log(x1)-log(y'));
yp=b(1)+b(2)*x;
sx=((sum((x-mean(x)).^2))/(n(1)-1))^.5
std(x)
sy=((sum((y-mean(y)).^2))/(n(1)-1))^.5
std(y)
sxy=(sum((x-mean(x)).*(y-mean(y))))/(n(1)-1)
corr=sxy/(sx*sy)
covar=cov(x,y)
corr=covar(1,2)/(sx*sy)
plot(x,y,'o',x,yp,'-')
legend(['a=',num2str(b(1)),' b=',num2str(corr)]);

댓글 수: 1

b=inv(y)*(log(x1)-log(y'));
y is a vector, you cannot get its inverse.

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

 채택된 답변

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2016년 10월 10일

0 개 추천

Here is your solution for exponential regression:
x=[0;1;2;3;4;5;6]
y=[32;47;65;92;132;190;275]
c=[ones(size(x)) x]\log(y);
a=exp(c(1));
b=-c(2);
xp=linspace(min(x),max(x),1000);
yp=a.*exp(-b.*xp);
plot(x,y,'o',xp,yp,'-')
legend(['a=',num2str(a),' b=',num2str(b)]);

댓글 수: 1

RedThermos
RedThermos 2016년 10월 11일
Thanks so much for the help. I greatly appreciate it.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

질문:

2016년 10월 10일

댓글:

2016년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by