passing a matrix to ode45: ode45('fna​me',tspan,​matrix,opt​ions)

조회 수: 4 (최근 30일)
William
William 2011년 8월 7일
편집: Walter Roberson 2017년 1월 28일
Hi all,
I am 'recoding' some code written by my professor that integrates a PDE over a 2D lattice.
It appears that he passes the 2D initial condition to ode45() without reshaping it first, and that ode45 automatically reshapes it...I didn't know you could do this? I can't find any documentation on this, but it looks like that is exactly what is happening.
Am I missing something here?
Code:
whos Y0
% confirms 21x21
pause();
[T,Y]=ode45('eqNLS2D_sat',tspan,Y0,options,Nx,Ny);
function [F]=eqNLS2D_sat(t,Y,flag,Nx,Ny)
global C gamma mu V VV LAP;
whos Y
%confirms 441x1
pause();
Y2=Y.*conj(Y);
F=(-LAP*Y+gamma*Y./(1+Y2)+VV.*Y)/1i;
Will

채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 7일
I suspect this is merely standard linear indexing. Every multidimensional array index maps in to a linear array position number. For example, a 4 x 4 array has the following linear indexes:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
so if you had (for example) the array A
32 35 11 38
40 6 30 28
22 3 33 17
34 16 7 14
then the "30" could be indexed as A(2,3) or equivalently as A(10)
Nothing special needs to be done to invoke this kind of linear indexing: it happens automatically when an array is indexed with a single index.
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 1월 28일
Depending on what is known, that might be a candidate for the boundary value problem routines.
RB
RB 2017년 1월 28일
편집: Walter Roberson 2017년 1월 28일
Thanks. I have the terminal values but the equation is involving 2*2 matrices.
Solve the following system of ODE's
d/dt Y(t)=-(H(t))^{T}Y(t)
d/dt V(t)=-Y(t)^{T}Q^{T}QY(t)
with the terminal conditions Y(T)=I_{2} and V(T)=0. Y, V, H and Q are 2*2 matrices.
I am unable to use ode45 since I want matrix result.
It would be great if you can give a suggestion.
\[
H=
\begin{bmatrix}
-0.5 & 0.4 \\
0.007 & -0.008
\end{bmatrix}
\]
\[
Q=
\begin{bmatrix}
0.06 & -0.0006 \\
-0.06 & 0.006
\end{bmatrix}
\]

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by