How can I use the input command to ask the user to enter an equation?

1 vue (au cours des 30 derniers jours)
Abdullah Nabi
Abdullah Nabi le 18 Avr 2020
Commenté : Abdullah Nabi le 18 Avr 2020
I want to write a command which will allow the user to enter an equation in terms of x and also, ask the user to enter the value of the variable x.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 18 Avr 2020
See this example
str = 'sin(x)*exp(x)'; % input function in term of x
f = str2func(['@(x)' str]); % convert to MATLAB function
x = 2; % evaluate at x=2
f(2) % evaluate the function

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by