The main problem here is to evaluate the user function at some point because we don’t know if the user will enter a function in x domain or another domain
I tried this but it doesn’t work:
function y = f(~)
y = input('Enter you function: ');
end
and this is what I want:
>>f
Enter you function: a^2+3*a-3
>>f(1)
ans =
1
This solution almost provides the exact requirements in your question. I’d feel kind of queezy using this though with the EVAL. You’d also want to wrap some error checking into this.
You can then use this class like:
>> a = f Enter your function: a^2+3*a-3 >> a(1) ans = 1 >> a(2) ans = 7