solve differential equation with matrix

How can I solve the following differential equation with MATRIX?
where T is the unknown:
P is known (I know P4, P5 and P6):
R^-1=G is known (I know all its terms):
C is known (I know all its terms):

Answers (1)

Yes your system of ODEs are on the form (with singular mass-matrix, C) that ode23t and ode15s can handle, at least according to the help and documentation.
HTH

4 Comments

I have some difficulties to find something that can be useful for me. Sorry but can you help me more? In particular is it possible to write the whole equation with matrix o I need to divide the matrix into different equation before?
Your ODE-defining function should look something like this for the case where there is no mass-matrix:
function dTdt = fcn_dTdt(t,T,R,P)
dTdt = P - R\T; % In this example I use I as mass-matrix for simplicity
% this should be equivalent to: dTdt = P - inv(R)*T
end
This you would then call with something like this:
T0 = 500*rand(6,1);
t = linspace(0,10,1001);
R = randn(6,6); % you're values I don't know
P = rand(6,1);
[t_out,T_out] = ode15s(@(t,T) fcn_dTdt(t,T,R,P),t,T0);
For how to implement and use have a look at the code for batonode. There you can see how the mass-matrix is handled.
I tried to write:
function dTdt = fcn_dTdt(t,T,G,P,C) %I have put G (not R) and C
dTdt =C^(-1)*(P-G*T);
end
[t_out,T_out] = ode15s(fcn_dTdt(t,T,G,P,C),t, T0);
but I received this error:
Error: File: programma_totale_6nodi_1A.m Line: 504 Column: 5
Function definitions are not permitted in this context.
Maybe because this computation is inside a for loop.
Start by looking at the odeexamples - that gui lets you run and inspect a good number of examples with different combinations of the ODE-integrators' capabilities. You can also look at the source code of them, which should illustrate how to write the code.
In this example you should save the first code-snippet to a .m-file with the name fcn_dTdt.m and then put the setup and ode15s call either in a script or on the command-line.

Sign in to comment.

Asked:

on 17 Jul 2020

Commented:

on 17 Jul 2020

Community Treasure Hunt

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

Start Hunting!