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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by