2
$\begingroup$
M1 = Array[Subscript[y, #1, #2][t] &, {2, 2}];
M0 = {{1, 0.00001}, {0.00001, 0}};
ci = Thread[Flatten[M1] == Flatten[M0]] /. {t -> 0};
s = NDSolve[{ I D[M1, t] == (M''.M1 - M1.M'')/20, ci}, Variables[M1], {t, 0, 10}]

I have solved the above differential equation. It gives 4 different solutions i.e. the 4 different matrix elements of M1 as the interpolating functions.

How to plot these different solutions. I tried doing

Plot[M1 /. s, {t, 0, 10}]

but it is not showing anything. Sorry I forgot to mention, M'' is defined as a matrix

M''={{3.58368*10^-6, -9.3358*10^-6}, {-9.3358*10^-6, -3.58368*10^-6}}

It is showing solution as

> {{Subscript[y, 1, 1][t] -> InterpolatingFunction[{{0., 10.}}, <>][t], 



Subscript[y, 1, 2][t] -> InterpolatingFunction[{{0., 10.}}, <>][t], 


 Subscript[y, 2, 1][t] -> InterpolatingFunction[{{0., 10.}}, <>][t], 


 Subscript[y, 2, 2][t] -> InterpolatingFunction[{{0., 10.}}, <>][t]}}
$\endgroup$
4
  • 1
    $\begingroup$ NDSolve is not producing a solution, so there is nothing for Plot to plot. At least one problem with your code is that M is undefined. By the way, it is prudent not to begin variable names with capital letters. $\endgroup$
    – bbgodfrey
    Commented Dec 15, 2019 at 14:44
  • $\begingroup$ The solutions are going to be complex-valued, so you might try ReImPlot instead of Plot. $\endgroup$
    – Michael E2
    Commented Dec 15, 2019 at 15:30
  • $\begingroup$ And M'' is shorthand for Derivative[2][M], which seems a somewhat hacky way to store a constant matrix. $\endgroup$
    – Michael E2
    Commented Dec 15, 2019 at 15:32
  • $\begingroup$ I tried but that doesn't work. $\endgroup$
    – maddy
    Commented Dec 15, 2019 at 16:39

1 Answer 1

2
$\begingroup$

Works for me:

M'' = {{3.58368*10^-6, -9.3358*10^-6}, {-9.3358*10^-6, -3.58368*10^-6}}    

M1 = Array[Subscript[y, #1, #2][t] &, {2, 2}];
M0 = {{1, 0.00001}, {0.00001, 0}};
ci = Thread[Flatten[M1] == Flatten[M0]] /. {t -> 0};
s = NDSolve[{I D[M1, t] == (M''.M1 - M1.M'')/20, ci}, 
  Variables[M1], {t, 0, 10}]

ReImPlot[M1 /. s, {t, 0, 10}]

enter image description here

To get different colors, you need to evaluate the argument (this is addressed elsewhere on this site):

ReImPlot[M1 /. s // Evaluate, {t, 0, 10}, PlotRange -> All]

enter image description here

One can see from comparing the results, there's a scaling issue in plotting. Probably, the best thing to do is to plot the components separately:

ReImPlot[#, {t, 0, 10}] & /@ Flatten[M1 /. s] // GraphicsRow

enter image description here

Hmm, labels might be nice:

ReImPlot[# /. s, {t, 0, 10}, PlotLabel -> #] & /@ 
  Flatten@M1 // GraphicsRow
$\endgroup$
8
  • $\begingroup$ Using M'' as a variable seems bad practice to me, but I just copied the OP's code. $\endgroup$
    – Michael E2
    Commented Dec 15, 2019 at 17:03
  • $\begingroup$ Sorry, but can u please let me know which version of Mathematica you are using as this command is not working for me. Also, what are those which are shown as solutions to the differential equation as they seem to be sinusoidal curves (the ones which are shown as interpolating functions)? Are they not the solutions? But here, the solutions seem to be something else. $\endgroup$
    – maddy
    Commented Dec 15, 2019 at 17:14
  • $\begingroup$ @MadhurimaChakraborty V12. In V10.1 and later you can use Plot[ReIm[# /. s]//Evaluate, .... In earlier versions, you can use Plot[{Re[#] /. First[s], Im[#] /. First[s]},.... You might need First[s] in the V10 code -- I can't test it. (You said, "the command" but I don't know what that means. I assumed ReImPlot.) $\endgroup$
    – Michael E2
    Commented Dec 15, 2019 at 17:21
  • $\begingroup$ Thank you so much. $\endgroup$
    – maddy
    Commented Dec 15, 2019 at 17:23
  • $\begingroup$ @MadhurimaChakraborty You're welcome. If you want to see sinusoidal plots, you need to integrate and then plot out to t -> 10^7 or more (because the coefficients are on the order of 10^-7). $\endgroup$
    – Michael E2
    Commented Dec 15, 2019 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.