I want to plot Isocline i.e want plot (x,y) when system contains step function .
Show older comments
% Parameters
r =0.1; % Define the value of r
k = 50; % Define the value of k
a =0.01; % Define the value of a
e = 0.5; % Define the value of e
m = 0.05; % Define the value of m
F = 1; % Define the value of F
%s =0.1; % Define the value of s
w = 0.1; % Define the value of w
b = 0.001; % Define the value of b
M = 50; % Define the value of M
s =0.1; % Define the value of sx
% Initial conditions
x0 =2; % Define the initial value of x
y0 =1; % Define the initial value of y
initial_conditions = [x0; y0];
% Time span for simulation
tspan = [0, 100]; % Define the time span (e.g., [0, 10])
% Solve the system of differential equations
[t, y] = ode45(@(t, y) kkk(t, y, r, k, a, e, m, F, s, w, b, M, x), tspan, initial_conditions);
% Extract the solution
x_sol = y(:, 1);
y_sol = y(:, 2);
function dydt = kkk(t,x,y, r, k, a, e, m, F, s, w, b, M)
x = y(1);
u = isocline_input(x, F, s, w, b, M);
dxdt = r * x * (1 - x / k) - a * x * y / (1 + q * u * M);
dydt = (e * a * x * y) / (1 + q * u * M) - m * y;
dydt = [dxdt; dydt];
end
function u = isocline_input(x, F,w, b, M, s)
pi0 = (w * F) / (s * (w + b * M));
pi1 = F * (w + b * M) / (s * w);
if x <= pi0
u = 0;
elseif x >= pi1
u = 1;
else
u = (s*x) / (s*x + F) + w * (s*x - F) / (b * (s*x + F) * M);
end
end
I want to plot (x,y) where is my fault please help
7 Comments
Walter Roberson
on 1 Aug 2023
What is the difference between this and https://www.mathworks.com/matlabcentral/answers/2002887-i-want-to-isocline-induced-step-function?s_tid=srchtitle ?
Walter Roberson
on 1 Aug 2023
[t, y] = ode45(@(t, y) kkk(t, y, r, k, a, e, m, F, s, w, b, M, x), tspan, initial_conditions);
function dydt = kkk(t,x,y, r, k, a, e, m, F, s, w, b, M)
It is confusing that you are passing x as the last parameter in your call, but your function expects to receive x as the second parameter.
mks
on 1 Aug 2023
mks
on 1 Aug 2023
Walter Roberson
on 1 Aug 2023
If you have equations that calculate the derivatives of the prey population and the derivatives of the predator population, then they must be combined into a single state vector instead of being separate variables
[t, y] = ode45(@(t, state) kkk(t, state, r, k, a, e, m, F, s, w, b, M), tspan, initial_conditions)
function dxydt = kkk(t, state, r, k, a, e, m, F, s, w, b, M)
x = state(1);
y = state(2);
....
dxydt = zeros(size(state));
dxydt(1) = ...
dxdyt(2) = ...
end
mks
on 1 Aug 2023
Edited: Walter Roberson
on 1 Aug 2023
mks
on 1 Aug 2023
Answers (1)
Walter Roberson
on 1 Aug 2023
Moved: Walter Roberson
on 1 Aug 2023
Your code needs q but you did not define any q, so I had to pick SOME value for q in order to debug.
You need to change the definition of q to something appropriate for your situation.
% Parameters
r =0.1; % Define the value of r
k = 50; % Define the value of k
a =0.01; % Define the value of a
e = 0.5; % Define the value of e
m = 0.05; % Define the value of m
F = 1; % Define the value of F
%s =0.1; % Define the value of s
w = 0.1; % Define the value of w
b = 0.001; % Define the value of b
M = 50; % Define the value of M
s =0.1; % Define the value of sx
%user's code does not define any q, but we need a value of it to debug
rng(655321)
q = rand() * 10 %define the value of q
% Initial conditions
x0 =2; % Define the initial value of x
y0 =1; % Define the initial value of y
initial_conditions = [x0; y0];
% Time span for simulation
tspan = [0, 100]; % Define the time span (e.g., [0, 10])
% Solve the system of differential equations
[t, y] = ode45(@(t, state) kkk(t, state, r, k, a, e, m, F, s, w, b, M, q), tspan, initial_conditions);
% Extract the solution
x_sol = y(:, 1);
y_sol = y(:, 2);
subplot(2,1,1); plot(t, x_sol); title('x');
subplot(2,1,2); plot(t, y_sol); title('y');
function dydt = kkk(t, state, r, k, a, e, m, F, s, w, b, M, q)
x = state(1);
y = state(2);
u = isocline_input(x, F, s, w, b, M);
dxdt = r * x * (1 - x / k) - a * x * y / (1 + q * u * M);
dydt = (e * a * x * y) / (1 + q * u * M) - m * y;
dydt = [dxdt; dydt];
end
function u = isocline_input(x, F, s, w, b, M)
pi0 = (w * F) / (s * (w + b * M));
pi1 = F * (w + b * M) / (s * w);
if x <= pi0
u = 0;
elseif x >= pi1
u = 1;
else
u = (s*x) / (s*x + F) + w * (s*x - F) / (b * (s*x + F) * M);
end
end
2 Comments
mks
on 1 Aug 2023
Sam Chak
on 1 Aug 2023
What exactly do you mean by "u is an Adaptive Step Function"? I tried searching the keywords, but they seem unrelated. A closer look shows that
depends on the parameter
that is defined through 3 static (non-dynamic) If-Else statements, making it looks like the scheduling approach.

Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!