필터 지우기
필터 지우기

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개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by