passing a matrix to ode45: ode45('fname',tspan,matrix,options)
4 views (last 30 days)
Show older comments
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
Accepted Answer
Walter Roberson
on 7 Aug 2011
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 Comments
Walter Roberson
on 28 Jan 2017
Depending on what is known, that might be a candidate for the boundary value problem routines.
RB
on 28 Jan 2017
Edited: Walter Roberson
on 28 Jan 2017
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}
\]

More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!