MATLAB: Solving a simple integral with input equation from user

inputintegralMATLAB

I am using this code to enter an equation and solve a simple integral
str = input('Enter an equation in x: ','s') ;
f = function_handle.empty;
f = eval(['@()', str]);
x = f();
xmin= input('Lower limit of x: ')
xmax= input('Upper limit of x: ')
int(x, xmin, xmax)
But I get this error
Undefined function 'int' for input arguments of type 'double'.
Error in Untitled5 (line 7)
int(x,xmin, xmax)

Best Answer

syms x
str = input('Enter an equation in x: ','s') ;
f = function_handle.empty;
f = eval(['@(x)', str]);
%x = f();
xmin= input('Lower limit of x: ')
xmax= input('Upper limit of x: ')
int(f,x, xmin, xmax)