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!