Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentario
Image Analyst
Image Analyst el 28 de Dic. de 2015
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?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 28 de Dic. de 2015
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')

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by