Undefined function 'findpeak' for input arguments of type 'double'. Error in untitled4 (line 40) [peaks, t] = findpeak(pred);

조회 수: 2 (최근 30일)
clc;
clear;
close all;
% Parameters
a = 1; % Attack rate
h = 0.5; % Handling time
b = 0.5; % Conversion efficiency
d = 0.4; % Predator death rate
epsilon = 0.01; % Timescale separation
K = 5; % Carrying capacity
r_values = linspace(0.1, 1, 200);
x0 = 1.0;
y0 = 0.5;
initCond = [x0; y0];
dt = 0.01;
tspan = 0:dt:5000;
tr = 6000/dt; % time to discard as transient
results = [];
rosenzweigMacArthur = @(t, Y, r) [
r * Y(1) * (1 - Y(1)/K) - (a * Y(1) * Y(2)) / (1 + h * Y(1));
epsilon * ((b * a * Y(1) * Y(2)) / (1 + h * Y(1)) - d * Y(2))
];
for i = 1:length(r_values)
r = r_values(i);
opts = odeset('AbsTol',1e-12,'RelTol',1e-10);
[t, Y] = ode45(@(t,Y) rosenzweigMacArthur(t,Y,r), tspan, initCond, opts);
pred = Y(tr:end, 2); % discard transient
[peaks, t] = findpeak(pred);
if isempty(peaks)
% no oscillation detected → steady state
results(end+1, :) = [r, pred(end)];
else
% oscillatory: store unique peaks
up = unique(round(peaks,5));
for k = 1:length(up)
results(end+1, :) = [r, up(k)];
end
end
end
% Plotting bifurcation diagram
figure('Color','w');
plot(results(:,1), results(:,2), 'k.', 'MarkerSize', 6);
xlabel('Prey Growth Rate (r)', 'FontSize', 12);
ylabel('Predator Population Peaks or Fixed Points', 'FontSize', 12);
title(sprintf('Bifurcation Diagram using findpeaks (K = %.1f)', K), ...
'FontWeight','bold','FontSize',13);
grid on;
% Save figure
saveas(gcf, 'bifurcation_diagram_peaks.png');

답변 (1개)

Mathieu NOE
Mathieu NOE 2025년 5월 28일
이동: Walter Roberson 2025년 5월 29일
it's findpeaks with an "s" at the end (missing in your code)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by