EXTRA information to be used later (learn outside of lab): Setting
up functions (M-files) in MATLAB:
- In Home/New click on "Function" and follow the pattern
suggested. As an example, write code to represent function f(x)=x^2
sin(pi x). Give a name to this function and save it in a file (called M-file)
- In command window, test this function to compute f(0),f(-1),f(1).
- Plot the function on the interval [-5,3 pi].
Extra: writing loops and computing vector norms in MATLAB:
- Write code in an M-file that will compute the norm of a vector x.
The code may look like this: (you may want to use proper indentation)
function s = mynorm(x)
s=0;
for j=1:length(x)
s = s + x(j).^2
end
end
- Compare with the result of MATLAB function norm
|