How to plot a function and each starting value in different colors? (Newton's Method)
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!