How to plot square root of solution to an ODE

Hi,

I have an ODEProblem, let us say like the one in this example: https://docs.sciml.ai/stable/tutorials/ode_example/

function parameterized_lorenz!(du,u,p,t)
 du[1] = p[1]*(u[2]-u[1])
 du[2] = u[1]*(p[2]-u[3]) - u[2]
 du[3] = u[1]*u[2] - p[3]*u[3]
end

u0 = [1.0,0.0,0.0]
tspan = (0.0,1.0)
p = [10.0,28.0,8/3]
prob = ODEProblem(parameterized_lorenz!,u0,tspan,p)

I solve this ODE using solve() and want to plot time versus square root of the second coordinate. How can I do this?

I managed to do this, but feels like a hack:

plot(1:29,sqrt.(Array(sol)'[:,2]))

It’s mentioned in the plotting page: https://docs.sciml.ai/latest/basics/plot/

plot(sol,vars=(sqrt,0,2))
1 Like

Thanks! That almost worked, I had to make a small change:

f(x,y) = return (x,sqrt(y))
plot(sol,vars=(f,0,2))

since the compiler is expecting f to be a function of two variables here.

1 Like