Introductory Programming
Fall 2006
Homework 1
Some of these problems are adapted from Faires and Burden,
Numerical Methods.
The sequence described by , , and for ,
, is called a Fibonacci sequence. Its
terms occur naturally in many botanical species, particularly those
with petals or scales arranged in the form of a logarithmic spiral
(see http://maven.smith.edu/~phyllo/) .
The Fibonacci sequence can be approximated by the following expression:
![\begin{displaymath}
F_n \approx \frac{1}{\sqrt{5}}
\left[
\left( \frac{1 + \sqr...
...t)^{n+1} -
\left( \frac{1 - \sqrt{5}}{2} \right)^{n+1}
\right]
\end{displaymath}](hw01-img6.png) |
(1) |
- Use MATLAB to evaluate this expression for
and .
- Write a script called fibonacci1.m that evaluates this
expression for whatever the current value of n is. You should
be able to invoke your script like this:
>> n = 10
>> fibonacci1
89
- To see the list of MATLAB's elementary math functions, type help elfun. To read the documentation of abs, type help
abs. Then try to evaluate the following expressions:
abs(pi)
abs (pi)
abs ( pi )
a b s ( p i )
abs[pi]
abs{pi}
abs(pi
abs()
abs(1, 2)
abs pi
abs('pi')
abs(1 + i)
exp(i*pi)
- Use MATLAB to check if the following equations hold. You can
check the equations two ways: first, compute the value of both sides
and see if they are the same (use the format long command to see
all the digits); alternatively, compute the difference between the
right and left sides and see if the difference is zero. You should
check 1 or 2 values of
for each equation.
-
-
-
-
Can you find values of for which these equations are
not exactly true in floating-point arithmetic?
|