Numerical Solution for Matrix Differential Equation

16 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2019-3-23
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 2019-3-24
Thanks that solved the problem.
Also I had to change the initial condition to a column vector Y0(:)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by