How do I find the period of this function?
*Note y(1) is equivalent to x and y(2) is equivalent to y in this set of equations.
My code:
sym vars
a=1; b=1; c=0.1; d=0.1;
RHS=@(t,y)([a*y(1)-b*y(1)*y(2); c*y(1)*y(2)-d*y(2)]);
[t,y]=ode45(RHS, [0 100], [5,0.2]);
figure
plot(t, y(:,1))
xlabel('t (in years)'); ylabel('Number of Prey (in millions)');
title('Number of Prey for 100 Year Period');
legend('x vs t');
set(gca, 'fontsize', 16);

 採用された回答

Star Strider
Star Strider 2020 年 4 月 26 日

0 投票

Use the Signal Processing Toolbox findpeaks function:
a=1; b=1; c=0.1; d=0.1;
RHS=@(t,y)([a*y(1)-b*y(1)*y(2); c*y(1)*y(2)-d*y(2)]);
[t,y]=ode45(RHS, [0 100], [5,0.2]);
figure
plot(t, y(:,1))
xlabel('t (in years)'); ylabel('Number of Prey (in millions)');
title('Number of Prey for 100 Year Period');
legend('x vs t');
set(gca, 'fontsize', 16);
[pks,locs] = findpeaks(y(:,1)); % Peaks & Locations
mean_period = mean(diff(t(locs))); % Period
text(min(xlim)+0.1*diff(xlim), min(ylim)+0.95*diff(ylim), sprintf('Mean Period = %.2f time units', mean_period))
.

4 件のコメント

Nasir Holliday
Nasir Holliday 2020 年 4 月 26 日
Thank you so much!! But could you explain the last line in the code starting with text(min(...
What does that do because I when I run the code, I do not get any results
Star Strider
Star Strider 2020 年 4 月 26 日
My pleasure!
The text call simply writes that line on the plot. It is not otherwise necessary for the code. (I do not understand the reason it did not print the results. It worked correctly for me in R2020a.)
Nasir Holliday
Nasir Holliday 2020 年 4 月 26 日
Oh! I didn't run it with the rest of the code so that's why! Thank you!
Star Strider
Star Strider 2020 年 4 月 26 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by