UNIVERSITY OF CALIFORNIA, BERKELEY
Engineering 7 – Spring 2009
Department of Civil and Environmental Engineering
Instructor: Professor Rector
Lab 04 – Problems [20 pts total]
Conditional, Loops, More Functions!
Monday, 03/02/2009 at 12:00 pm (noon)
Remember to use the
command if you are not familiar with a command. It will be much
faster than waiting for a GSI to answer your question. Moreover, a list of useful commands is
provided at the end of this document.
For this lab, you may submit your report as one Word document or one PDF file. If you submit a
Word document, please do not use headers/footers. Remember to submit the report on Bspace as
well as a hard copy in the drop boxes. Thanks!
loops (2 pts total)
Name 3 similarities between
loops, as well as 3 differences.
In what situations would you
loop versus a
Think about when you use a
loop versus a
loop, the number of
times you want pieces of code to run, etc.
Be as concise as possible, please!
loops both have a constructor clause, and both must be terminated with an end
You may use this example in your lab report.
2. Getting Comfortable with
statements (5 pts total)
For the following problems, write a script / m-file (NOT a function) that accomplishes the following tasks.
your code and output into your lab report only.
Your solution must include one or more
You may not use sum, min, max, or any rounding function in this problem!
If you can creatively
accomplish the answer without violating any of the restrictions, you will receive full credit
loop, create the first 16 Fibonacci numbers, given that the first two Fibonacci number entries
are 0 and 1:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
Create the same array in (a) using a while loop
Find the largest divisor for the integer 194621 (excluding the number itself)
Find all positive prime numbers under 50: