Not Really sure how to go about plotting this?

조회 수: 1 (최근 30일)
Hudson Harrell
Hudson Harrell 2020년 9월 27일
답변: Image Analyst 2020년 9월 27일
for x=0:0.01:6
y=x.^2+2*x-10 ;
if abs(y) <0.05 %Tolerance
fprintf('the root is %g \n' ,x)
break
end
end

채택된 답변

Image Analyst
Image Analyst 2020년 9월 27일
Try using roots() - the function meant for doing that:
x = linspace(-6, 6, 1000);
y = x.^2 + 2 * x - 10;
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
r = roots([1,2,-10])
% Make black line for x axis;
yline(0, 'LineWidth', 2);
% Make vertical lines at roots
xline(r(1), 'LineWidth', 2, 'Color', 'r');
xline(r(2), 'LineWidth', 2, 'Color', 'r');
xlabel('x', 'FontSize', 18);
ylabel('t', 'FontSize', 18);
caption = sprintf('Roots at %.2f and %.2f', r(1), r(2));
title(caption, 'FontSize', 18);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by