I want to plot Isocline i.e want plot (x,y) when system contains step function .
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% 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 Kommentare
Antworten (1)
Walter Roberson
am 1 Aug. 2023
Verschoben: Walter Roberson
am 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 Kommentare
Sam Chak
am 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.
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!