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))^.5std(x)sy=((sum((y-mean(y)).^2))/(n(1)-1))^.5std(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)]);
Best Answer