Graph gives warning : function behaves unexpectedly on array inputs. What does this mean?
1 次查看(过去 30 天)
显示 更早的评论
%plot to view graph
g =@(x) 3*x^3 +x^2 -2*x - 5;
figure(2)
o = -40:40;
fplot(g,[-40 40])
0 个评论
采纳的回答
Chris
2022-9-17
编辑:Chris
2022-9-17
You are using matrix (linear algebra) operators, which include * and ^. If you try to calculate the function directly, You get an error because raising a vector to a power doesn't work.
g =@(x) 3*x^3 +x^2 -2*x - 5;
o = -40:40;
y = g(o);
To operate on each x value individually, use elementwise operators (e.g, .^ .* ./ )
g =@(x) 3 .* x .^ 3 + x .^ 2 - 2 .* x - 5;
fplot(g,[-40,40])
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!