how can we display our real roots or points

5 vues (au cours des 30 derniers jours)
adriana resendez
adriana resendez le 3 Mar 2015
Commenté : Star Strider le 3 Mar 2015
>> f = @(x) x^3-3*x-1;
>> fplot(f, [-10 10]); grid on;
  2 commentaires
Andrew Newell
Andrew Newell le 3 Mar 2015
Do you want to find the roots or just change the display so you can see the crossings?
adriana resendez
adriana resendez le 3 Mar 2015
both

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 3 Mar 2015
Modifié(e) : Star Strider le 3 Mar 2015
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 commentaires
adriana resendez
adriana resendez le 3 Mar 2015
on the m file?
Star Strider
Star Strider le 3 Mar 2015
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Just for fun dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by