How do I solve this differential system by using ode45?

1 次查看(过去 30 天)
Here is my system. how do i use ode45 to solve this. I dont know how to build a array contain all these funciton and put into ode45.
Thank for helping me.
x' = 6*x/y;
y' = x'*4;
z' = 16*x';
x0 %Initial condition are known,
y0
z0

回答(1 个)

Sam Chak
Sam Chak 2022-3-27
Since is known, you can make direct substitutions into and . Here is the demo:
function Demo_ode45
close all
clc
tspan = [0 1]; % time span of simulation
y0 = [1 0.5 0.25]; % initial values
[t, y] = ode45(@(t, y) odefcn(t, y), tspan, y0);
plot(t, y, 'linewidth', 1.5)
grid on
xlabel('Time, t [sec]')
ylabel('x, y, z')
title('Time responses of the system')
legend('x', 'y', 'z', 'location', 'best')
end
function dydt = odefcn(t, y) % Ordinary Differenctial Equations
dydt = zeros(3,1);
dydt(1) = 6*y(1)/y(2);
dydt(2) = 4*(6*y(1)/y(2));
dydt(3) = 16*(6*y(1)/y(2));
end
Result:

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by