Quadratic equation

Thread Starter

jagjit Sehra

Joined Feb 29, 2008
25
Hi Folks,
I am having some difficulties in understanding what my graph is showing me in MATLAB.
I have chosen the value for a,b and c for the quadratic so the result will be complex, however the graph does not point to the values when the function cross the 0 axis. the first one does but according to the results the second should be in the third quadrant.

a = 1;
b = 0.009;
c = 5;
x =linspace(-16,16);
y = a*x .* x + b*x + c
plot(x,y)
x1=(-b+sqrt((b^2)-(4*a*c)))/(2*a)
x2=(-b-sqrt((b^2-4)*(a*c)))/(2*a)

The two roots are as follows:

x1 = -0.0045 + 2.2361i

x2 = -0.0045 - 2.2360i



x1= seems to be correct, however x2 is somewhere in the third quadrant this is not reflected on the graph generated by MATLAB.
I know this is something I am doing wrong I would appreciate it, if someone will show me the error of my ways.
 

Dave

Joined Nov 17, 2003
6,969
Did you consider the Matlab roots function?

For:

a = 1;
b = 0.009;
c = 5;

Rich (BB code):
p = [1 0.009 5];

q = roots(p)

q =

  -0.0045 + 2.2361i
  -0.0045 - 2.2361i
Dave
 
Top