How to Plot inside For Loop for Differential Equation

Hi all,

I read this topic but it is not helping me to plot in a looping:

I want to plot functions of:

p = 900 +e^{t/2}

p = 900 +50e^{t/2}

p = 900 +100e^{t/2}

p = 900 +150e^{t/2}

p = 900 +200e^{t/2}

p = 900 -50e^{t/2}

p = 900 -100e^{t/2}

p = 900 -150e^{t/2}

p = 900 -200e^{t/2}

it should be easy to use for loop (for i in 50:50:200), but why my code below does not work?

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x/2)
   
plot(f,0,10, xticks=false, xlims=(0,10), ylims=(600,1200), 
    bottom_margin = 10mm, label=L" 900 + ce^{t/2}", framestyle = :zerolines, 
    legend=:outerright)

for i = 50:50:200
g(x) = 900 + i*exp(x/2) 
display(plot!(g, xticks=false, xlims=(0,10), ylims=(600,1200), 
    bottom_margin = 10mm, label="", framestyle = :zerolines, 
    legend=:outerright))    
end

It becomes 3 layouts, I just want 1 layout with multiple graphs.

Does this work for you?

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x / 2)

p = plot(f, 0, 10, xticks=false, xlims=(0, 10), ylims=(600, 1200),
    bottom_margin=10mm, label=L" 900 + ce^{t/2}", framestyle=:zerolines,
    legend=:outerright)

for i = 50:50:200
    g(x) = 900 + i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

display(p)
1 Like

Works great,

it seems too many variables I made lots of mistakes then

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x / 2)

p = plot(f, 0, 10, xticks=false, xlims=(0, 10), ylims=(600, 1200),
    bottom_margin=10mm, label=L" 900 + e^{t/2}", framestyle=:zerolines,
    legend=:outerright)

for i = 10:20:100
    g(x) = 900 + i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

for i = 10:20:100
    g(x) = 900 - i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end


display(p)