Exercise 6.3: FOR loop

Make a function file of the following form:

function b = kwad(r)

in which a row vector is squared element-wise. Do this without using the command >> .^2.

(HINT: Use the command >> for)
a)
Work out the problem on paper.
b)
Write the m-file in MATLAB.
c)
Test the function file with the row $ a$ = [1 2 3 4 5] and, if necessary, debug the file.



Previous      Next      Up      Answer


Esteur 2010-03-22