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

%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 件のコメント

Elisa
Elisa 2024 年 9 月 13 日
移動済み: Voss 2024 年 9 月 13 日
i found that the a0 vlues will be the same value as the exponential e(1), which is why that causes alpha to be 0, but how to fix this probleM?
nick
nick 2024 年 9 月 13 日
Hi @Elisa,
Kindly please attach the XLSX file 'cockroach_population' which will help in resolving the query effectively.
Elisa
Elisa 2024 年 9 月 13 日
I think i found the problem, thank you!
Torsten
Torsten 2024 年 9 月 13 日
It's not wrong, but better use exp(x) instead of exp(1).^x in your code.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Interpolation についてさらに検索

質問済み:

2024 年 9 月 13 日

コメント済み:

2024 年 9 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by