Numerical Solution for Matrix Differential Equation

조회 수: 13 (최근 30일)
Ramtin Taheri
Ramtin Taheri 2019년 3월 23일
댓글: Ramtin Taheri 2019년 3월 24일
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