Having issues getting my nonlinear function to plot.
f = @(x) 2.^x-5*x+2; %Given Function
xaxis = [0:0.5:2]; %x-axis
plot(xaxis,f) %plotting function //DOESN'T WORK

댓글 수: 2

"Doesn't work" does not explain the problem. You get an error message:
Error using plot
Invalid data argument.
This is an important hint. The 2nd input is a function handle, but Matlab expect numerical values.
For a solution see Star Strider's answer.
Ethan Bales
Ethan Bales 2021년 9월 18일
yeah sorry about that. This is my first time using a forum like this and I'm still relatively new to coding. Thanks for insight!

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

 채택된 답변

Star Strider
Star Strider 2021년 9월 18일

2 개 추천

It works if you give ‘f’ a vector to work with
f = @(x) 2.^x-5*x+2; %Given Function
xaxis = [0:0.5:2]; %x-axis
plot(xaxis,f(xaxis)) %plotting function //DOESN'T WORK —> YEs, IT DOES!
Experiment to get different results.
.

댓글 수: 2

Ethan Bales
Ethan Bales 2021년 9월 18일
ahhhh I see the issue now, thanks for help!!
Star Strider
Star Strider 2021년 9월 18일
My pleasure!
.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 9월 18일

댓글:

2021년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by