Novocaine Example
> restart;
Initial Condition:
.
Recursion Formula:
.
Define the function
directly from the difference equation.
This is called a
recursive
definition.
> u := proc(n) if n<=0 then 500 else u(n-1) - 0.2*u(n-1) fi end;
We can now evaluate
for various values on
simply by entering
.
> u(0); u(1); u(2); u(3);
We can generate a list of points for
taking on the values from 0 to 25 by entering .
> [seq([n,u(n)], n=0..25)];
We can avoid printing out the entire list, but save it for future use by assigning the list to a variable and by terminating the command with a colon.
> pts := [seq([n,u(n)], n=0..25)]:
We can plot the list of points using the plot command.
> plot(pts,style=point);
Upon reflection, we see that we can write
in a
closed form
as
.
What happens if we simply replace
by
and let
take on arbitrary values?
>
u := proc(t) 500*(0.8)^t end;
plot(u(t),t=0..25);
We can display both plots by giving each one a name, supressing any output,
and displaying them with the plots[display] command.
>
P1 := plot(pts,style=point):
P2 := plot(u(t),t=0..25):
plots[display]({P1,P2});