Question: find max of values, save solve values


I am trying to find the maximum of values in dsolve. In part 1 we solve the equation. In part 2 we do a doolop to know the values for specific time such as t=2. In part 3 we try to give this values names such as y[i] then to find the maximum of these values but it did not work for the maximum it gave y6 instead of the value.


Also, is it possible to save all values from dsolve  to a file the call it to find the maximum at each t?


> restart;

>with(DEtools); with(plots);
>k := 0; A := 0.37e-1; B := 0.2e-6;

>ode1 := diff(U(t), t) = -(A+r(t)+B*U(t))*U(t);

> ic[1] := U(365*k) = 1000;

> 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;


Part 1:

>for i to 5 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 .. 5));

end do;


Part 2:

> for i to 5 do sol[i](2) end do;


Part 3:

> for i to 5 do x[i] := proc (t) options operator, arrow; rhs(sol[i](t)[2]) end proc;
>y[i] := x[i](2)

> max(y[i]);


Thank you

Please Wait...