フィルターのクリア

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

1 回表示 (過去 30 日間)
Seanice Thompson
Seanice Thompson 2018 年 3 月 11 日
編集済み: Seanice Thompson 2018 年 3 月 11 日
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 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by