Q:

Request User Input Equation Matlab

I want to write a function that I can call later that allows me to request the user to input an equation. I.e. how can I have the user input something like sin(x) or exp(x^2) so that I can evaluate that function at any number of points?
I want to write the function as something like:
    function f = myf(x)
    f = %user enters equation%

A:

You can use a function handle: 
function y = myf(x)

f = @(x) input('Input Equation: ');
y = f(x);

end

So for example:
>> myf(2)
Input Equation: x^2

ans =

     4

>> myf(1)
Input Equation: exp(x)

ans =

    2.7183

The @(x) f(x) is called a function handle. The input can be done using the input function. Inside input, 'Input Equation: ' is a string but when it asks you on the command line do not use a string just use the examples above.

