how can we display our real roots or points

5 次查看(过去 30 天)
>> f = @(x) x^3-3*x-1;
>> fplot(f, [-10 10]); grid on;

采纳的回答

Star Strider
Star Strider 2015-3-3
编辑:Star Strider 2015-3-3
Use the roots function:
xr = roots([1 0 -3 -1]);
They all happen to be real. This gives the x-values, so if you want to plot them, the y vector is:
yr = zeros(size(xr));
  4 个评论
Star Strider
Star Strider 2015-3-3
I changed ‘r’ to ‘xr’ when I created ‘yr’ and forgot to change it in ‘yr’. The code is consistent now.
With a couple tweaks, you can plot everything easily:
f = @(x) x^3-3*x-1;
xr = roots([1 0 -3 -1]);
yr = zeros(size(xr));
figure(1)
fplot(f, [-10 10], '-r')
hold on
plot(xr, yr, 'bp')
hold off
grid on

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by