필터 지우기
필터 지우기

Hi guys, this my quadratic equation i'm having problem to plot. it doesn't plot anything, I need a hand

조회 수: 2 (최근 30일)
clc
clear all;
close all;
syms x
x=-10:1:10;
a=input( ' Enter the A value \n' );
if a == 0
disp(' A is = 0');
end
b=input( ' Enter the B value \n' );
c=input( ' Enter the c value \n' );
dis = sym(sqrt(b^2 -4*a*c));
x1=(-b+dis) /(2*a);
x2=(-b-dis) /(2*a);
sym(x1)
sym(x2)
plot(x,x1);
hold on
plot(x,x2);
  댓글 수: 1
Image Analyst
Image Analyst 2015년 12월 28일
x is a multi-element vector while x1 and x2 are single numbers. Exactly what are you trying to plot? The quadratic curve plus the roots?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2015년 12월 28일
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Define x axis.
x=-10:1:10;
% Get user values of the coefficients.
a=input( ' Enter the A value (e.g. -1) ' );
if a == 0
disp(' A is = 0');
return;
end
b=input( ' Enter the B value (e.g. 2) ' );
c=input( ' Enter the c value (e.g. 55) ' );
% Create the y values, the curve.
y = a * x.^2 + b * x + c;
% Plot the quadratic curve.
plot(x, y, 'b*-', 'MarkerSize', 20, 'LineWidth', 3);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Solve for the roots.
dis = sqrt(b^2 -4*a*c)
x1 = (-b + dis) /(2*a)
x2 = (-b - dis) /(2*a)
% Plot the roots
hold on;
plot(x1, 0, 'ro', 'MarkerSize', 20, 'LineWidth', 3);
plot(x2, 0, 'ro', 'MarkerSize', 20, 'LineWidth', 3);
% Plot the axes
xl = xlim();
yl = ylim();
line([0,0], yl, 'LineWidth', 3, 'Color', 'k');
line(xl, [0,0], 'LineWidth', 3, 'Color', 'k');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by