User Tools

Site Tools


gibson:teaching:fall-2012:math445:vectoreval.m

An example of a function that takes another function as an argument.

function r = vectoreval(f,x);

  N = length(x);
  r = zeros(N,1);
  for i=1:N
    r(i) = f(x(i));
  end

end

You can call this function in Matlab with the syntax

x = linspace(0,pi,100);
s = vectoreval(@sin, x);
gibson/teaching/fall-2012/math445/vectoreval.m.txt · Last modified: 2012/09/20 05:10 by gibson