MTH 420-520 LAB 2 EXTRA PRACTICE IN MATLAB

EXTRA information to be used later (learn outside of lab): Setting up functions (M-files) in MATLAB:
  1. 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)
  2. In command window, test this function to compute f(0),f(-1),f(1).
  3. Plot the function on the interval [-5,3 pi].

Extra: writing loops and computing vector norms in MATLAB:
  1. 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
  2. Compare with the result of MATLAB function norm