Plotting of an inline function

str=input('Give an equation in x\n','s');
f=inline(str,'x');
I want to plot a graph of the function 'f'. I tried fplot but it is not working. How can I plot 'f' vs. 'x'.

10 comentarios

madhan ravi
madhan ravi el 31 de Ag. de 2018
Can you give an example of your input by copying every results from the command window?
Sahil Khan
Sahil Khan el 31 de Ag. de 2018
>> Untitled
Give an equation in x
x^2-3
>>
Copied from command window
Stephen23
Stephen23 el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 2018
@Sahil Khan: can you please explain why you are using a very outdated and almost obsolete inline function? The inline documentation clearly states "inline will be removed in a future release. Use Anonymous Functions instead." Do you have a reason why you cannot use (much better) function handles for this task?
Sahil Khan
Sahil Khan el 31 de Ag. de 2018
I wasnt exactly up to date with that. I am learning MATLAB and started three days before. Can you please elaborate the other method ?
Stephen23
Stephen23 el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 2018
@Sahil Khan: follow the bold blue link in my comment.
madhan ravi
madhan ravi el 31 de Ag. de 2018
@stephen cobeldick I have a question . I am using matlab 2017a but str2sym command is not working for me . Any reason/s?
Stephen23
Stephen23 el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 2018
@madhan ravi: did it work before? Do you have a license for that toolbox?
madhan ravi
madhan ravi el 31 de Ag. de 2018
Editada: madhan ravi el 31 de Ag. de 2018
What toolbox is required for this? Yes @stephen but suddenly it says undefined function same for sprint as well but sprintf and fprintf commands work don’t know why :/
Stephen23
Stephen23 el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 2018
"What toolbox is required for this?"
Use an internet search engine to find this page:
Read the text in the top left corner of that page:
Symbolic Math Toolbox
Use an internet search engine to search for "MATLAB what toolbox licenses do I have"
... etc
madhan ravi
madhan ravi el 31 de Ag. de 2018
Editada: madhan ravi el 31 de Ag. de 2018
Thank you @stephen and sorry

Iniciar sesión para comentar.

Respuestas (2)

Stephen23
Stephen23 el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 2018
You should use str2func to create an anonymous function:
str = input('Give an equation in x: ','s');
fun = str2func(sprintf('@(x)%s',str));
fplot(fun,[0,10])
And tested:
>> str = input('Give an equation in x: ','s');
Give an equation in x: sqrt(x)-x
>> fun = str2func(sprintf('@(x)%s',str));
>> fplot(fun,[0,10])

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 31 de Ag. de 2018

Editada:

el 31 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by