How to evaluate a user input function at a given point?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Maryam Ansari
le 15 Fév 2016
Commenté : Walter Roberson
le 15 Fév 2016
I'm unsure how to evaluate a given function at a given point X. Hypothetically, the user can input any function using any letter as a desired variable. How can I evaluate the function at the initial point given. I was thinking I could use the syms command. However, I'm unsure of what letter variable they would use. For instance, if the function was x+1 vs y+1, how can I ensure that the "initialX" is evaluated in place of x or y in the given function?
function y = randFunc(initialX, func)
y = func(initialX);
display(y);
0 commentaires
Réponse acceptée
Matt J
le 15 Fév 2016
Modifié(e) : Matt J
le 15 Fév 2016
3 commentaires
Walter Roberson
le 15 Fév 2016
In this case if func is given in the form of a symbolic expression, then use matlabFunction() to turn it into a function handle.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!