Plotting of an inline function

조회 수: 13 (최근 30일)
Sahil Khan
Sahil Khan 2018년 8월 31일
편집: madhan ravi 2018년 8월 31일
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
Stephen23
Stephen23 2018년 8월 31일
편집: Stephen23 2018년 8월 31일
"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 2018년 8월 31일
편집: madhan ravi 2018년 8월 31일
Thank you @stephen and sorry

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephen23
Stephen23 2018년 8월 31일
편집: Stephen23 2018년 8월 31일
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 2018년 8월 31일

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by