can someone help me by solving this error, there are three ode wich i have to solve and plot a single graph of al three equations in one graph.

조회 수: 1 (최근 30일)
function dydt=graph(t,y)
dydt = zeros(3,1) ; %column vector
dydt(1) = 1.07*y(1)*y(1)-y(1)*y(1)*y(1)-0.17*y(1)-(0.36*y(1)*y(2))-(0.0001*sqrt(y(1)*y(3))/(1+0.2*sqrt(y(1))));
dydt(2) = y(2)*(0.06*y(1)-4.06*y(2)*y(3)-0.09);
dydt(3) = (0.000089*sqrt(y(1)*y(3)))/(1+0.2*sqrt(y(1)))-0.232*y(2)*y(3)-y(3);
end
y0=[50 100 50];
tspan=[0 100];
[t,y]=ode45(@(t,y) graph(t,y),tspan,y0)
plot(t,y)
  댓글 수: 5
Rik
Rik 2022년 1월 28일
Comment posted as flag by @devyanshi bansal:
can u help me with ploting same for 3-d graph as well
devyanshi  bansal
devyanshi bansal 2022년 1월 29일
can anyone please help with the plotting of 3-d spiral graph of the same equations

댓글을 달려면 로그인하십시오.

답변 (1개)

Satyam
Satyam 2025년 6월 11일
Hi Devyanshi,
To solve the error, the code can be modified by putting the last 4 lines of code to the top as suggested previously. For plotting a 3D spiral graph, one can leverage the ‘plot3’ function of MATLAB.
Refer to the documentation of ‘plot3’ function to know about the syntax: https://www.mathworks.com/help/matlab/ref/plot3.html
Here is a code snippet demonstrating its usage:
y0=[50 100 50];
tspan=[0 100];
[t,y]=ode45(@(t,y) graph(t,y),tspan,y0);
% Plot the 3D spiral trajectory
figure;
plot3(y(:,1), y(:,2), y(:,3), 'b', 'LineWidth', 2);
Warning: Imaginary parts of complex X, Y, and/or Z arguments ignored
grid on;
xlabel('y_1'); ylabel('y_2'); zlabel('y_3');
title('3D Spiral Trajectory of the ODE System');
view(3); % Set default 3D view
function dydt=graph(t,y)
dydt = zeros(3,1) ; %column vector
dydt(1) = 1.07*y(1)*y(1)-y(1)*y(1)*y(1)-0.17*y(1)-(0.36*y(1)*y(2))-(0.0001*sqrt(y(1)*y(3))/(1+0.2*sqrt(y(1))));
dydt(2) = y(2)*(0.06*y(1)-4.06*y(2)*y(3)-0.09);
dydt(3) = (0.000089*sqrt(y(1)*y(3)))/(1+0.2*sqrt(y(1)))-0.232*y(2)*y(3)-y(3);
end

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by