I want to plot Isocline i.e want plot (x,y) when system contains step function .
7 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
回答(1 个)
Walter Roberson
2023-8-1
移动:Walter Roberson
2023-8-1
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 个评论
Sam Chak
2023-8-1
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1447342/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1447347/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1447352/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Uncertainty Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!