How do I solve this differential system by using ode45?

조회 수: 1 (최근 30일)
Gan Huang
Gan Huang 2022년 3월 27일
답변: Sam Chak 2022년 3월 27일
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