Homework #1

All problems must be in a single *.m file. You will need an additional file for the function in Problem 7. See class webpage for naming convention. Make a separate block in the code for each problem.

Contents

Problem 1

Use 'fprintf' to print your name followed by a carriage return to the command line.

Problem 2

Use a 'for' loop to count up the integers between 1 and 100. Gauss did this in his head in a few seconds as a schoolboy. Can you?

Problem 3

Use a 'while' loop to find the first (smallest) 10 prime numbers. Use your own algorithm (not with MATLAB's 'isprime', etc.) Suppress output to the command line during the loop. Store the results in a 10 x 1 array and display this array at the end of your code.

Problem 4

Reproduce the following figure as closely as possible using your name as the title (close counts). Note that the linewidths and text sizes are not all the default.

Problem 5

Build the following matrix and assign to variable 'X'. Display X in the command window as below.

X =

     1     2     3
     4     5     6
     7     8     9

Problem 5

Index into the array created above to replace the value '8' with '18'. Display the result as below. Do NOT just recreate the matrix.

X =

     1     2     3
     4     5     6
     7    18     9

Problem 7

Make a function that calculates and returns the the square of the input. Make a separate *.m file for the function. See class webpage for naming convention. Use your function to calculate the sqaure of '10.5' and display the results in the command window.