How to build a plot differential equations

3 次查看(过去 30 天)
Hi, I'm solving a differential equation and with the given parameters my graph should show a circle, but it's displaying a void, I don't understand why, please help
M8()
Значения параметров: n = 0,b=0, k = 1, a = 1, h = 0, p = 1 Решение задачи Коши для уравнения solver: 'ode45' extdata: [1×1 struct] x: [0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1] y: [2×11 double] stats: [1×1 struct] idata: [1×1 struct] Elapsed time is 0.017687 seconds.
function M8
n = 0;b=0; k = 1; a = 1; h = 0; p = 1; y(1)=0; y(2)=1; x=2;
f=@(t,y)[y(2);y(2)+2.*n.*(1+a.*y(1).^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
clc
disp('Значения параметров: n = 0,b=0, k = 1, a = 1, h = 0, p = 1')
disp('Решение задачи Коши для уравнения')
z= ode45(f,[0,1],[0,0]);
disp(z);
tic, [~,y] = ode45(f,[0,1],[0,0]);toc
plot(y(:,1),y(:,2))
grid on
end

采纳的回答

Sam Chak
Sam Chak 2023-12-6
Please check your second state equation. It does not produce a circle in the phase portrait. However, I will show you an example that produces a perfect circular trajectory.
M8
function M8
n = 0; b = 0; k = 1; a = 1; h = 0; p = 1; x = 2;
f = @(t, y) [y(2);
- y(1)];
% f = @(t, y) [y(2);
% y(2) + 2*n*(1 + a*y(1)^3)*y(1) + k^2*(y(1) + b*y(1)^3) - h*sin(p*x)];
% disp('Значения параметров: n = 0,b=0, k = 1, a = 1, h = 0, p = 1')
% disp('Решение задачи Коши для уравнения')
tspan = [0, 100]; %
y0 = [0, 1]; % initial values: y1(0) = 0, y2(0) = 1
[t, y] = ode45(f, tspan, y0);
% disp(z);
% tic, [~,y] = ode45(f,[0,1],[0,0]);toc
plot(y(:,1), y(:,2))
grid on
axis equal
xlabel y_1
ylabel y_2
end

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-12-6
n = 0;b=0; k = 1; a = 1; h = 0; p = 1; y(1)=0; y(2)=1; x=2;
f=@(t,y)[y(2);y(2)+2.*n.*(1+a.*y(1).^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
Your h is 0, so h.*sin(p.*x) is going to be 0, so the second entry in f is effectively
y(2)+2.*n.*(1+a.*y(1).^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)
If you let y(1) and y(2) both be 0, then that evaluates to 0.
Therefore with your h value and with those boundary conditions, your ode is constant 0, 0

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by