How do I solve this differential system by using ode45?

1 view (last 30 days)
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

Answers (1)

Sam Chak
Sam Chak on 27 Mar 2022
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:

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!