Undefined function or variable 'x'

1 view (last 30 days)
luke milner
luke milner on 19 Mar 2016
Commented: Rena Berman on 20 Jan 2017
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');
end
h=(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

Accepted Answer

Jan
Jan on 19 Mar 2016
What do you expect the line "f(x)= (fun);" to do? How should indexing with the symbolic expression "x" work?

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!