Numerical Solution for Matrix Differential Equation

16 Ansichten (letzte 30 Tage)
Ramtin Taheri
Ramtin Taheri am 23 Mär. 2019
Kommentiert: Ramtin Taheri am 24 Mär. 2019
I am trying to solve the following differential equation:
where matrix Y is the desired solution, and A is a known matrix. The matrix sizes can be up to 8x8.
To check that MATLAB accepts a matrix ODE, I tried the following codes for the simplest case of 2x2 matrix and a constant A:
A=[1, 2; -1, -2];
ode_func =@ (X) -X*X-A;
Y0 = [1, 1; 1, 1]; T0=0; Tf=100;
Y=zeros(2,2);
[T,Y] = ode45(@(t,y) ode_func(y), [T0,Tf], Y0);
But it returns the error:
Error using *
Inner matrix dimensions must agree.
Error in =@ (X) -X*X -A
Error in @(t,y)ode_func(y)
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
It seems the codes are not working. So, I am wondering whether MATLAB is able to solve a matrix ODE?
Thank you,
  2 Kommentare
Walter Roberson
Walter Roberson am 23 Mär. 2019
The second parameter will always be passed as a column vector, and the result of the ode_func must be a column vector of exactly the same length.
ode_func = @(X) reshape( - reshape(X,2,2).^2 - A, [], 1)
Ramtin Taheri
Ramtin Taheri am 24 Mär. 2019
Thanks that solved the problem.
Also I had to change the initial condition to a column vector Y0(:)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by