# Is possible to plot a list of ODE solution in one step?

I'm currently strugling with plotting the solution of ODEs, the code witch creates the solution is written below:

ClearAll["Global*"]
Ts = 24;
Lt = 250*10^-6;
Lkozep = 50*10^-6;
ρ = 3.4*10^-5;
λ = 34;
h = 3.5*10^-6;
wc = {30*10^-6};
wkezd = 3*10^-6;
wvég = 1*10^-6;
U = 1;
Discretisation of one leg
n = 3;
define vectors
ΔL = Lt/n;
Δx = ΔL
Lbal = Table[i, {i, 0, Lt, ΔL}];
Ljobb = Table[i, {i, Lt + Lkozep, Lt*2 + Lkozep, ΔL}];
L = Join[Lbal, Ljobb]
Length[L]
Δw = (wkezd - wvég)/(n - 1);
Wbal = Table[i, {i, wkezd, wvég, -Δw}];
Wjobb = Table[i, {i, wvég, wkezd, Δw}];
w = Join[Wbal, wc, Wjobb]
Abal = Table[Wbal[[i]]*h, {i, n}];
Ajobb = Table[Wjobb[[i]]*h, {i, n}];
Akozep = wc*h;
A = Join[Abal, Akozep, Ajobb];
Rbal = Table[ρ*(Δx/Abal[[i]]), {i, n}];
Rjobb = Table[ρ*(Δx/Ajobb[[i]]), {i, n}];
Rkozep = Table[ρ*(Lkozep/A[[i]]), {i, n + 1, n + 1}];
Rvektor = Join[Rbal, Rkozep, Rjobb];
Rvektorszum = Sum[Rvektor[[i]], {i, 2*n + 1}];
Ubal = Table[Rbal[[i]]*U/Rvektorszum, {i, n}];
Ukozep = Table[Rkozep[[j]]*U/Rvektorszum, {j, 1, 1}];
Ujobb = Table[Rjobb[[i]]*U/Rvektorszum, {i, n}];
Uvektor = Join[Ubal, Ukozep, Ujobb];
T = Table[Symbol["T" <> ToString@i][x], {i, n*2 + 1}];
Tderivált = D[T, {x, 2}];
Telsőderivált = D[T, {x, 1}];
diffegy =
Tderivált == (Uvektor*
Uvektor)/(-λ*Δx^2*ρ);
pfkezd = T[[1]] == Ts /. {x -> 0};
pfbef = T[[2*n + 1]] == Ts /. {x -> 2*Lt + Lkozep};
Tseged1 = Table[T[[i]], {i, 1, 2*n}];
Tseged2 = Table[T[[i]], {i, 2, 2*n + 1}];
Lseged = Table[L[[i]], {i, 2, 2*n + 1}];
pfbalfele = MapThread[#1 /. x -> #2 &, {Tseged1, Lseged}];
pfjobbfele = MapThread[#1 /. x -> #2 &, {Tseged2, Lseged}];
pfillesztesi = pfbalfele == pfjobbfele;
Telsőderivaltseged1 = Table[Telsőderivált[[i]], {i, 1, 2*n}];
Telsőderivaltseged2 = Table[Telsőderivált[[i]], {i, 2, 2*n + 1}];
pfderiváltbalfele =
Table[A[[i]], {i, 1, 2*n}]*
MapThread[#1 /. x -> #2 &, {Telsőderivaltseged1, Lseged}];
pfderiváltjobbfele =
Table[A[[i]], {i, 2, 2*n + 1}]*
MapThread[#1 /. x -> #2 &, {Telsőderivaltseged2, Lseged}];
pfderiváltillesztési = pfderiváltbalfele == pfderiváltjobbfele;
sol = DSolve[{diffegy, pfkezd, pfbef, pfderiváltillesztési,
pfillesztesi}, T, x];
T /. sol;


My question is that whether is it possible to plot the "i"th element of the solution where x goes from the "i"th element of L to "i+1" th element of L

• You overuse Table; simpler and more efficient forms are available. Look up Range, Total, Most, Rest – Bob Hanlon Aug 28 '16 at 15:14

You can create a function, which takes i as element:

ploti[i_?IntegerQ] := Plot[(T /. sol)[[1, i]], {x, L[[i]], L[[i + 1]]}]
ploti[3]


Show[Table[
Plot[(T /. sol)[[1, i]], {x, L[[i]], L[[i + 1]]}], {i,
Length[L] - 1}], PlotRange -> All]


or alternatively:

Show[Table[ploti[i], {i, Length[L] - 1}], PlotRange -> All]


or if you prefer a more formal way:

Plot[Piecewise[
Table[{(T /. sol)[[1, i]], L[[i]] < x < L[[i + 1]]}, {i,
Length[L] - 1}]], {x, 0, 0.0006}, PlotRange -> {25, 140}]
`

• And is it possible the plot all the curves in one coordinate system? – G.David Aug 28 '16 at 14:23
• @G.David I've amended my answer. – Feyre Aug 28 '16 at 14:28
• Thank you so much. It was really helpful – G.David Aug 28 '16 at 15:15