Error with plotting my function
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2021-9-18
"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.
采纳的回答
Star Strider
2021-9-18
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.
.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!