How to solve this differential equation using matlab?
1 view (last 30 days)
Show older comments

I know the value of n_(j-1), T_(j-1) and n_(j).
I want to solve this differential equation and get the numerical solution.
How can I do it in MATLAB?
2 Comments
Torsten
on 16 Nov 2022
What do you mean by
I know the value of ndot_(j-1), T_(j-1) and ndot_(j)
?
Do you have time-dependent analytic functions for them ? Or only time-dependent vectors ? Or something else ?
Answers (1)
Simran
on 10 Feb 2025
As I understand, you want to solve the following differential equation:
[ \frac{\partial T_j}{\partial t} = \dot{n}{j-1} T{j-1} - \dot{n}_j T_j ] using MATLAB. What you provided is a first-order differential equation for T_j.
As you mentioned, the values for - ( \dot{n}{j-1} ), ( T{j-1} ), and ( \dot{n}_j ) are known. All we need is an initial condition for ( T_j) at ( t = 0 ) . Lets say (T_j(0) = T_{j0} ) .
Next, create a function in MATLAB to represent the ODE (first-order differential equation) and name it odefun.m. Below is odefun.m:
function dTdt = odefun(t, Tj, nj_minus_1, Tj_minus_1, nj)
dTdt = nj_minus_1 * Tj_minus_1 - nj * Tj;
End
We can solve this ODE using the inbuilt MATLAB function “ode45”. You can refer to this link to understand about it more:
Below is the script to solve it:
% first define the known parameters
nj_minus_1 = 1.0; % example value, you can use your own value
Tj_minus_1 = 100; % example value
nj = 0.5; % example value
% Set the initial condition by defining T_{j0}.
Tj0 = 50; % example initial value
% Define time span for the solution
tspan = [0 10];
% Use MATLAB’S ODE solver (ode45) to solve ODE (first order differential equation)
[t, Tj] = ode45(@(t, Tj) odefun(t, Tj, nj_minus_1, Tj_minus_1, nj), tspan, Tj0);
% Lastly plot the solution
plot(t, Tj);
xlabel('Time');
ylabel('T_j');
title('Solution of the Differential Equation');
The graph of the ODE should look something like this:

The solution can be tested with some different parameter values to see if it behaves as expected.
Below are the links attached that maybe relevant to the discussion:
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!