Skip to main content
Became Hot Network Question
Improve formatting
Source Link
Domen
  • 33.4k
  • 3
  • 47
  • 66

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 NDSolveNDSolve. The matrix in question is 2x2, with each element being a function of time. After using NDSolveNDSolve, 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[\[Rho]Clear[ρ, \[Rho]eeρee, \[Rho]egρeg, \[Rho]geρge, \[Rho]ggρgg, \[Alpha]α, \[CapitalGamma]cΓc, \[CapitalGamma]0Γ0, \[Sigma]plusσplus, \[Sigma]minus];σminus];
\[Rho][t_]
ρ[t_] = {{\[Rho]ee[t]ρee[t], \[Rho]eg[t]ρeg[t]}, {\[Rho]ge[t]ρge[t], \[Rho]gg[t]ρgg[t]}};
\[Sigma]plusσplus = {{0, 1}, {0, 0}};
\[Sigma]minusσminus = ConjugateTranspose[\[Sigma]plus];ConjugateTranspose[σplus];
\[Alpha]α = 5;
\[CapitalGamma]0Γ0 = 1;
\[CapitalGamma]cΓc := \[Alpha]*\[CapitalGamma]0;α*Γ0;
\[Rho]0ρ0 = {{1, 0}, {0, 0}};
sol = NDSolve[{\[Rho]'[t]ρ'[t] == ((\[CapitalGamma]cΓc + \[CapitalGamma]0Γ0)/2) (2*\[Sigma]minus2*σminus.\[Rho][t]ρ[t].\[Sigma]plusσplus - 
 \[Sigma]plus σplus.\[Sigma]minusσminus.\[Rho][t]ρ[t] - \[Rho][t]ρ[t].\[Sigma]plusσplus.\[Sigma]minusσminus), \[Rho][0]ρ[0] == \[Rho]0ρ0}, \[Rho][t]ρ[t], {t, 0, 1}]; 

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

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

Thank you!

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[\[Rho], \[Rho]ee, \[Rho]eg, \[Rho]ge, \[Rho]gg, \[Alpha], \[CapitalGamma]c, \[CapitalGamma]0, \[Sigma]plus, \[Sigma]minus];
\[Rho][t_] = {{\[Rho]ee[t], \[Rho]eg[t]}, {\[Rho]ge[t], \[Rho]gg[t]}};
\[Sigma]plus = {{0, 1}, {0, 0}};
\[Sigma]minus = ConjugateTranspose[\[Sigma]plus];
\[Alpha] = 5;
\[CapitalGamma]0 = 1;
\[CapitalGamma]c := \[Alpha]*\[CapitalGamma]0;
\[Rho]0 = {{1, 0}, {0, 0}};
sol = NDSolve[{\[Rho]'[t] == ((\[CapitalGamma]c + \[CapitalGamma]0)/2) (2*\[Sigma]minus.\[Rho][t].\[Sigma]plus - \[Sigma]plus.\[Sigma]minus.\[Rho][t] - \[Rho][t].\[Sigma]plus.\[Sigma]minus), \[Rho][0] == \[Rho]0}, \[Rho][t], {t, 0, 1}];
Plot[Evaluate[{\[Rho]ee[t], \[Rho]eg[t]}/.sol] ,{t,0,0.5}]

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

Thank you!

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.

Source Link

Retrieving only first function in matrix ODE using NDSolve

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[\[Rho], \[Rho]ee, \[Rho]eg, \[Rho]ge, \[Rho]gg, \[Alpha], \[CapitalGamma]c, \[CapitalGamma]0, \[Sigma]plus, \[Sigma]minus];
\[Rho][t_] = {{\[Rho]ee[t], \[Rho]eg[t]}, {\[Rho]ge[t], \[Rho]gg[t]}};
\[Sigma]plus = {{0, 1}, {0, 0}};
\[Sigma]minus = ConjugateTranspose[\[Sigma]plus];
\[Alpha] = 5;
\[CapitalGamma]0 = 1;
\[CapitalGamma]c := \[Alpha]*\[CapitalGamma]0;
\[Rho]0 = {{1, 0}, {0, 0}};
sol = NDSolve[{\[Rho]'[t] == ((\[CapitalGamma]c + \[CapitalGamma]0)/2) (2*\[Sigma]minus.\[Rho][t].\[Sigma]plus - \[Sigma]plus.\[Sigma]minus.\[Rho][t] - \[Rho][t].\[Sigma]plus.\[Sigma]minus), \[Rho][0] == \[Rho]0}, \[Rho][t], {t, 0, 1}];
Plot[Evaluate[{\[Rho]ee[t], \[Rho]eg[t]}/.sol] ,{t,0,0.5}]

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

Thank you!