I have ode like this

Now if I need the result for a series of different values of the parameter “p”, I was trying to use for loop to do that, here is the code

Which shows the following error!

Please help me to solve this. I also have some other concern and will share once it gets resolve.

Thank you all.

These are just warnings and you can get rid of them by doing what is suggested in the warnings!

1 Like

GregR
#3
I wrapped your code in a function and ran it in the REPL. There were no errors.

I am using Julia 1.6.2 on Windows 10.

Regards,

Greg

Hi Greg,

In REPL it is working But I am unable to generate a single figure!

The following code in REPL

using DifferentialEquations

f(u,p,t) = 1.01*u + p*u^(1.1)

u0 =1/2

tspan = (0.0,1.0)

for p in 1:5

```
prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
using Plots
P=plot(sol)
display(P)
```

end

Showing 5 different figures, but I need a single graph! Don’t know how to do that.

Regards,

Phoni

```
using Plots
P = plot()
for p in 1:5
prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
plot!(P,sol)
end
display(P)
```

Thank you very much @Jeff_Emanuel

I was trying to plot the last value of the solution versus the recurring parameter using the following code

using DifferentialEquations

f(u,p,t) = 1.01*u + p*u^(1.1)

u0 =1/2

tspan = (0.0,1.0)

using Plots

PP = plot()

for p in 1:0.01:2

```
prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
SL=sol[1,:]
S=[p SL[end]]
scatter!(PP,S,legend=false)
```

end

display(PP)

savefig(“sct.png”)

which leads the following figure

But according to the data stored as in “S = [p SL[end]]” it should be like

I was unable to resolve this problem!!

Can I use plot! command instead of scatter!? because using plot! command nothing was appear in the figure.

GregR
#8
I made things more explicit:

Blockquote

f(u,p,t) = 1.01*u + p*u^(1.1)

u0 =1/2

tspan = (0.0,1.0)

x =

y =

for p in 1:0.01:2

prob = ODEProblem(f,u0,tspan,p)

sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)

SL=sol[1,:]

S=[p SL[end]]

push!(x, p)

push!(y, SL[end])

end

print(x)

PP = scatter(x, y, legend=false)

display(PP)

savefig(“sct.png”)

Blockquote

Regards,

Greg

To obtain the desired result with Plots.jl, this line should be written as a Tuple:

```
S=(p, SL[end])
```

*NB:*

*The code in previous posts should be inserted between back-ticks*

Thanks @GregR and @rafael.guerra for your input