Reputation: 1081
How i can execute an equation from GUI? Example: How i can do this with various type of equation?
Thanks the answers.
Upvotes: 2
Views: 1744
Reputation: 56905
I'm not entirely sure what you mean, but I think you want to grab the equation that a user types in to a text box and turn it in to a function?
Why does your F
change from 3 arguments to 4? i.e. F(x,y,y') --> F(1,0,5,-1)
in the next line? (The examples of F you gave don't seem to match up with your equation..)
In any case, check out eval()
, perhaps that is what you want.
It takes in a matlab command as a string, e.g. 2 + 3
, and evalutes it.
So
eval('2+3') % gives 5
eval('f=@(x,y,ydash) y*sqrt(1+ydash^2)') % gives a function f
f(1,5,-2) % gives 11.1803
But in any case, how do you expect the user to type in the square root symbol and the squared symbol? The eval()
approach relies on them typing in syntax that matlab will understand.
If you clarify your question a bit more this will be easier.
Upvotes: 3