Effacer les filtres
Effacer les filtres

How to plot a function and each starting value in different colors? (Newton's Method)

1 vue (au cours des 30 derniers jours)
I have to plot a dot at each starting point (x0, 0) in red, green and blue, if the method converges to the roots of the function (roots = 1, 2, 3), respectively. If the method fails I have to plot a diamond.
This is my code:
NewtonMethod1D(@(x) x.^3-6*x.^2+11*x-6, @(x) 3*x.^2-12*x+11, 0:0.1:4, 1.e-12, 10)
x = [1 2 3];
colorstr = 'rgb';
if x == 1 x == 2 x == 3
for i = 0:0.1:4
plot(f, f(x))
hold on
plot(i, 0, 'color', colorstr(i))
end
else
for i = 0:0.1:4
plot(f, f(x))
hold on
plot(i, 0, 'kd')
end
end

Réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by