next up previous
Next: About this document ...

ESC 251 HW 15 Due: Oct. 8

Remember to indent the bodies of your IF-THEN and looping structures.

(5 pts) Take the script that you wrote in Problem 2 of HW 13 and write it as a function. Use the syntax
     function nf = myfact(n)
in the first line of your function. Your function should check the input to make sure n is an integer. If n is an integer, your function should set nf equal to n!, otherwise the function should print an error message and set nf equal to an empty array. To do this, you can do
    nf = 1:0;
Note that you have already written most of this.
(5 pts) Write a function that will take a vector as input and output the index of the first element in the vector whos absolute value is greater than 10. If no value of the vector is greater than 10, the function should output an empty array. Test your function using the vectors in the data files hw15_1.dat and hw15_2.dat. You might find the break command useful. The break command is used to immediately exit a loop. Run the commands below to see how this command works.
     for i = 1:10
         if(i > 5)

next up previous
Next: About this document ...