Reputation: 13
I need to input a function through console into a second one. I have this function
trapez(fun,a,b,n)
so if I type this in the command line
trapez(@(x) x.^3,0,1,2)
it works perfectly but I need to run a program that uses a string input from the user like: 'x^4'and it gets used in the trapez function. I need the 'x^4' to become a function usable for trapez. I have tried this:
t=input('func')
trapez(t,a,b,n)
and
t=input('func')
str2func(t)
but I get this error: error creating function handle "@x.^2"
Upvotes: 1
Views: 96