In matlab i know i can convert string into anonymous function with str2func.
For example;
s= '@(x) x.^2';
h= str2func(s);
h(2) would be 4
But what if i do not know the number of unknown? Let's say user of this program will enter lots of function to get a numerical solution of a system. When the user enters x^2, i should add @(x) to its beginning then convert it to a function. But in programming time i do not know how many function the user will enter with how many unknown. @(x) may should be @(x,y) as well as @(x,y,z). If the user enters the number of unknowns, how can i create and add the necessary prefix at runtime?
ps: number of unknown can be any integer number.
cos(x)? Can variable names have more than one letter?@(x)toy.^2. That's why it is much cleaner for the user to spec out what names they want to use first. Perhaps you should just prepend the@.@(x,y) x.^yis very different from@(y,x) x.^yregexpand somesprintf. But how do you decide if byx^2+y^3the user meant@(x,y) x^2+y^3or@(y,x) x^2+y^3? they are different function