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.

2 visualizaciones (últimos 30 días)
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 comentarios
devyanshi  bansal
devyanshi bansal el 29 de En. de 2022
can anyone please help with the plotting of 3-d spiral graph of the same equations

Iniciar sesión para comentar.

Respuestas (1)

Satyam
Satyam el 11 de Jun. de 2025
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

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by