In this assignment we are going to start using a second method for writing
a function. We used Maple's one line notation that
uses an arrow. The one line notation can be very powerful by
breaking your problem into little steps and then writing a single function
for each step and then composing them. The problem is that if you use
an if - then - fi construction or a for - do - od then
you should be writing a procedure rather than a function (although recent
versions of Maple allow you to use if - then - fi with functions
and the -> notation, but older versions don't).
Method 2 for creating a function:
nameoffunction := proc( variable );
some commands;
return value;
end;
What do the following procedures do?
> f1:=proc(x);
return x^2;
end;
> f1(5); f1(y); f1(1+a);
> f2:=proc(x);
if x mod 2=0 then
return x/2;
else
return x;
fi;
end;
> plots[pointplot]([seq([r,f2(r)],r=1..50)]);
Question #1:
Write a function/procedure so that you can compute the sequence define for
$A_0 = 1$ and $A_1 = 1$ and for $n\geq2$,
\[ A_n = A_{n-1} + 2*A_{n-2}. \]
That is, I would like you to write a function/procedure
myfunc so that myfunc(0) returns 1, myfunc(1)
returns 1 and for n>0 it should return $A_n$.
If you try to
evaluate your function at a negative number it should return 0.
Compute myfunc(n) for n between 1 and 15.
Next
compute myfunc(50) and myfunc(1000). What goes wrong?
Find the value of myfunc(10000).
You should open up a new worksheet and start from scratch. You will have to save
your work in a file and upload that file on to the course
moodle. Your
solution should be a sequence of commands where it is easy to change the input
string and after you execute the sequence of commands you should have the
correct output string. Please add documentation to your worksheet to explain how it
works. Just a few sentences is sufficient, but imagine that you were opening up the
worksheet for the first time and wanted to know what it did. You will be marked down
if what you write is not clear and coherent.
You should finish your assignment before class Monday, October 22 by 11:59pm. Assignments
submitted after this date will be assessed a penalty of 10% per day.