How to Solve a system of first order differential equation in MATLAB?

조회 수: 65 (최근 30일)
ashish ranjan
ashish ranjan 2016년 9월 4일
댓글: dawar 2024년 4월 7일 7:40
how to write the command to solve series of differential equation in MATLAB
Dx/Dt = (a+b+c)*x + k*y + l*z
Dy/Dt = k*y + a*x
Dz/Dt = l*z + b*x
  댓글 수: 1
dawar
dawar 2024년 4월 7일 7:40
S = S + c(i)*x^(i-1) find the first order ordinary differential equation

댓글을 달려면 로그인하십시오.

답변 (2개)

Vaclav Ondra
Vaclav Ondra 2016년 9월 4일
편집: Vaclav Ondra 2016년 9월 4일
Have a look at examples on ode solvers page. There's an example of the system of ODEs. Simply rewrite your system into Matlab form, i.e.
function dydt = f(t,y)
dydt = [(a+b+c)y(1) + k*y(2) + I*y(3)
k*y(2) + a*y(1)
I*y(3) + b*y(1)];
end
and use, for example, ode45 solver
tspan = [0 1]; % your time interval
y0 = [1; 0; 0]; % your initial conditions
[t,y] = ode45(@f,tspan,y0); % solver
Everything is explained in the documentation.
  댓글 수: 3
Muhammad Sinan
Muhammad Sinan 2020년 10월 19일
You can program this problem is a single script file such as
%% Parameter
a = ?;
b = ?;
c = ?;
k = ?;
I = ?;
%% Initial Conditions
IC = [?, ?, ?];
%% Time span
tinitial = ?;
tfinal = ?;
df = ?;
t = linspace(tinitial, tfinal, df);
%% Model/ system of differential equations
Model = @(t, X) [(a+b+c)*X(1) + k*X(2) + l*(3);
k*X(2) + a*X(1);
l*X(3) + b*X(1)];
%% Solution
sol = ode45(Model, t, IC);
sol = deval(sol, t)
%% Substituitions for the dependent variables
x = X(1);
y = X(2);
z = X(3);
%% Plot by a single figure
plot(t, sol)
legend("x", "y", "z")
%% Plot separately
figure(1)
plot(t, x)
xlabel("Time")
ylabel("Solution of Dx/Dt")
figure(2)
plot(t, y)
xlabel("Time")
ylabel("Solution of Dy/Dt")
figure(3)
plot(t, z)
xlabel("Time")
ylabel("Solution of Dz/Dt")
Please replace the "?" by your desired syntex.
omar A.alghafoor
omar A.alghafoor 2020년 11월 12일
there is error in
%% Substituitions for the dependent variables
x = X(1);
y = X(2);
z = X(3);
Undefined function 'X' for input arguments of type 'double'.
Error in solve_ode45_test (line 201)
x = X(1);
why ???

댓글을 달려면 로그인하십시오.


Nur
Nur 2023년 2월 4일
syms y(x)
ode (x) =diff (y(x),x) == (2*((y(x))^2 + X^2)) / (y(x)*x);
ode(x) =
Invalid expression. Check for missing or extra characters.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
diff(y(x),x) == (2*y(x)^2) + 2*X^2)/(x*y(x))
cond = y(2) == -1;
ySol(x) = dsolve (ode , cond)
ySol(x) =
-(x^4*(X^2/16 + 1/16) - X^2)^(1/2)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by