my graph won't show the exponential graph as the alpha value is 0, can someone help fix this problem?

3 views (last 30 days)
%a
cockrach=importdata('cockroach_population.xlsx');
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf('parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f',p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf('exponential-cockraches rate: cockraches= %.2fe^%.2fx\n',alpha, Beta);
figure
plot(days,cockraches,'b.');
hold on
plot(days,polyval(p,days),'r-','LineWidth',3);
plot(days,exponential_curve,'g-','LineWidth',3)
title('numbers of cockraches vs times(days)');
xlabel('cockraches');
ylabel('days');
legend('unlinearised',text1,text2)
  4 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!