1
$\begingroup$

I have a very stupid question, but I don't use Mathematica very often, so here it goes:

I'm trying to solve some "matrix" ODE using NDSolve. The matrix in question is 2x2, with each element being a function of time. After using NDSolve, I obtain four interpolating functions corresponding to the four elements of the matrix. However, I'm having trouble figuring out how to extract and plot only one specific element of the matrix.

For instance, in the code snippet below, I'm getting the correct solution, but it plots the entire first row of the matrix instead of just the element at position (1,1):

ClearAll["Global`*"]
Clear[ρ, ρee, ρeg, ρge, ρgg, α, Γc, Γ0, σplus, σminus];

ρ[t_] = {{ρee[t], ρeg[t]}, {ρge[t], ρgg[t]}};
σplus = {{0, 1}, {0, 0}};
σminus = ConjugateTranspose[σplus];
α = 5;
Γ0 = 1;
Γc := α*Γ0;
ρ0 = {{1, 0}, {0, 0}};
sol = NDSolve[{ρ'[t] == ((Γc + Γ0)/2) (2*σminus.ρ[t].σplus -
  σplus.σminus.ρ[t] - ρ[t].σplus.σminus), ρ[0] == ρ0}, ρ[t], {t, 0, 1}];

Plot[Evaluate[{ρee[t], ρeg[t]}/.sol] ,{t,0,0.5}]

I've tried using the Part function and referencing only ρee[t] but without success. Any assistance would be greatly appreciated.

$\endgroup$
1
  • $\begingroup$ Maybe use Part outside Evaluate like this: Evaluate[{\[Rho]ee[t], \[Rho]eg[t]}/.sol][[1,1]]? $\endgroup$
    – mattiav27
    Commented Apr 29 at 7:28

1 Answer 1

3
$\begingroup$

try this. Use

Flatten[ρ[t]]

Instead of

ρ[t]

In your NDSolve call. Now the solution list of 4 solutions.

enter image description here

And then

Plot[Evaluate[ρee[t] /. sol], {t, 0, 0.5}]

enter image description here

$\endgroup$

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.