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.
3 次查看(过去 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)
回答(1 个)
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);
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!