Plotting of an inline function

9 Ansichten (letzte 30 Tage)
Sahil Khan
Sahil Khan am 31 Aug. 2018
Bearbeitet: madhan ravi am 31 Aug. 2018
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 Kommentare
Stephen23
Stephen23 am 31 Aug. 2018
Bearbeitet: Stephen23 am 31 Aug. 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 am 31 Aug. 2018
Bearbeitet: madhan ravi am 31 Aug. 2018
Thank you @stephen and sorry

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Stephen23
Stephen23 am 31 Aug. 2018
Bearbeitet: Stephen23 am 31 Aug. 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])

Star Strider
Star Strider am 31 Aug. 2018

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by