필터 지우기
필터 지우기

How to build a plot differential equations

조회 수: 3 (최근 30일)
Maria
Maria 2023년 12월 6일
답변: Sam Chak 2023년 12월 6일
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