Question:plot solution of ode with max and min

Question:plot solution of ode with max and min

Maple

Hello

I am trying to plot solution of ode0 together with the maximum and minimum values but I am having difficulty since the first plot is a solution and second is values. I should have a plot with two line one represent the solution of ode0 and second (the max an min). Any advise or suggestion?

This is the code:

> restart;
with(DEtools); with(plots); Nsols := 5; Ntstep := 10;
k := 0; A := 0.37e-1; B := 0.2e-6;
ode0 := diff(U(t), t) = -(A+B*U(t))*U(t);
ic[1] := U(365*k) = 1000;
sol[0] := dsolve({ode0, ic[1]}, U(t), range = 365*k .. 365*k+365, numeric);
p[0] := odeplot(sol[0], [[t, U(t)]], t = 365*k .. 365*k+365, colour = blue);
ode1 := diff(U(t), t) = -(A+r(t)+B*U(t))*U(t);
R := RandomTools:-Generate(distribution(Normal(-0.2e-1, 0.4e-1)), makeproc = true);
r := proc (t) if not type(t, numeric) then return 'procname(args)' end if; R() end proc;

> for i to Nsols do
sol[i] := dsolve({ode1, ic[1]}, numeric, known = r(t), method = classical[foreuler], stepsize = 0.1e-1);
p[i] := odeplot(sol[i], [[t, U(t)]], t = 365*k .. 365*k+365, colour = red)
end do;
display(seq(p[i], i = 1 .. Nsols));

> for j to Ntstep do
tvals[j] := evalf(j);
for i to Nsols do
x[i] := proc (t) options operator, arrow; rhs(sol[i](t)[2]) end proc;
y[i] := x[i](tvals[j])
end do;
ymaxval[j] := max([seq(y[i], i = 1 .. Nsols)])
end do;

> for j to Ntstep do
tvals[j] := evalf(j);
for i to Nsols do
x[i] := proc (t) options operator, arrow; rhs(sol[i](t)[2]) end proc;
y[i] := x[i](tvals[j]) end do; yminval[j] := min([seq(y[i], i = 1 .. Nsols)])
end do;

> plotofmaxmin := plot(yminval[i], yminval[i]);

> display(P[0], plotofmaxmin);

Thanks to Willem Ottevanger and Kitonum for the help with maximum part.

Thank you

﻿