I'm no matlab expert but i'm writing a function for Simpson's rule when I run the function with a function f in terms of x as one of my inputs it returns an error message "Undefined function or variable 'x'."; I wrote this yesterday, I came back to it today and now it won't work. any help would be massively appreciated function simpsons_rule_function( a, b, fun, n )
if (mod(n,2)~=0) error('n is odd, n must be even'); endh=(b-a)/(n);xp=a:h:b;syms x;f(x)= (fun);Y=f(xp);Y_0=f(a);Y_n=f(b);Y_odds=Y(2:2:end);Y_evens=Y(3:2:end-1);Y_evens1=sum(Y_evens);Y_odds1=sum(Y_odds);I=(h/3)*((Y_0+Y_n)+4*Y_odds1+2*Y_evens1)end
Best Answer