# Combine Plots into one using a loop?

Posted 8 months ago
1141 Views
|
11 Replies
|
3 Total Likes
|
 I want this program's plots to be combined into one plot - just can't seem to make it appear in one plot. Any suggestions? n = -1; While[n < 3, sol = NDSolve[{D[xtraj[t], t] == -(Sinh[ 2 xtraj[t] (-t)]/ (Cosh[2 xtraj[t] (-t)])), xtraj[0] == n}, xtraj[t], {t, -4, 8}]; n = n + 0.25; p = ParametricPlot[{t, xtraj[t]} /. sol, {t, -4, 8}, PlotRange -> All, PlotStyle -> {Blue, Full, Thick}, AxesStyle -> Thickness[.001], LabelStyle -> {Black, Medium}]; Print[p]]  Attachments:
Answer
11 Replies
Sort By:
Posted 8 months ago
 This?Download the notebook for the code. Attachments:
Answer
Posted 8 months ago
 Thanks.
Answer
Posted 8 months ago
 sol = Table[ NDSolveValue[{D[xtraj[t], t] == -(Sinh[2 xtraj[t] (-t)]/(Cosh[2 xtraj[t] (-t)])), xtraj[0] == n}, xtraj[t], {t, -4, 8}], {n, -1, 2.75, .25}]; Plot[sol, {t, -4, 8}, PlotRange -> All, PlotStyle -> Automatic, AxesStyle -> Thickness[.001], LabelStyle -> {Black, Medium}, AxesOrigin -> {0, -10}] 
Answer
Posted 8 months ago
 The problem with this one is that the x and y values are different the plot is flattened?
Answer
Posted 8 months ago
 We can use the additional option AspectRatio -> Automatic Plot[sol, {t, -4, 8}, PlotRange -> All, PlotStyle -> Automatic, AxesStyle -> Thickness[.001], LabelStyle -> {Black, Medium}, AxesOrigin -> {0, -10}, AspectRatio -> Automatic] 
Answer
Posted 8 months ago
 That looks much better :-) thank you!
Answer
Posted 8 months ago
 How about reversing the plot?
Answer
Posted 8 months ago
 I have another question - how can I restrict the domain such that:-0.1> xtraj[t]> 0.1Any help would be much appreciated.
Answer
Posted 8 months ago
 Is there anything like this? sol1 = Table[ NDSolveValue[{D[xtraj[t], t] == -(Sinh[2 xtraj[t] (-t)]/(Cosh[2 xtraj[t] (-t)])), xtraj[0] == n}, xtraj[t], {t, -4, 8}], {n, -.1, .1, .02}]; p1 = Plot[sol1, {t, -4, 8}, PlotRange -> {{-1, 1}, {-.15, .15}}, PlotStyle -> Automatic, AxesStyle -> Thickness[.001], LabelStyle -> {Black, Medium}, PlotLegends -> Table[n, {n, -.1, .1, .02}]] 
Answer
Posted 8 months ago
 Interesting code but it's not quite what I wanted - thanks.
Answer
Posted 8 months ago
 Are you asking about excluding a range of y values when plotted or when integrated? Your question is not clear.To restrict your plot you can use RegionFunction: Plot[sol, {t, -4, 8}, PlotRange -> All, PlotStyle -> Automatic, AxesStyle -> Thickness[.001], LabelStyle -> {Black, Medium}, AxesOrigin -> {0, -10}, AspectRatio -> Automatic, RegionFunction -> Function[{x, y}, (y > -2) && (y < 2)]] to get
Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments