Discussion in 'Math' started by jagjit Sehra, Mar 14, 2008.

1. ### jagjit Sehra Thread Starter Member

Feb 29, 2008
25
0
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.

2. ### Dave Retired Moderator

Nov 17, 2003
6,960
146
x2 should be:

Code ( (Unknown Language)):
1. x2=(-b-sqrt((b^2)-(4*a*c)))/(2*a)
Dave

3. ### jagjit Sehra Thread Starter Member

Feb 29, 2008
25
0
Thanks Dave,
I didnt spot that Shame on me!
Jag.

4. ### Dave Retired Moderator

Nov 17, 2003
6,960
146
Did you consider the Matlab roots function?

For:

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

Code ( (Unknown Language)):
1. p = [1 0.009 5];
2.
3. q = roots(p)
4.
5. q =
6.
7.   -0.0045 + 2.2361i
8.   -0.0045 - 2.2361i
Dave