Filter löschen
Filter löschen

How to build a plot differential equations

3 Ansichten (letzte 30 Tage)
Maria
Maria am 6 Dez. 2023
Beantwortet: Sam Chak am 6 Dez. 2023
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

Akzeptierte Antwort

Sam Chak
Sam Chak am 6 Dez. 2023
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

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 6 Dez. 2023
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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by