Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to solve a set of univariate quadratic equations simultaneously?

Subject: How to solve a set of univariate quadratic equations simultaneously?

From: Joe

Date: 24 May, 2012 02:21:08

Message: 1 of 4

Hi all:

I am trying to find an efficient way to solve a whole set of quadratic equations. The function roots(p) can only solve one quadratic equation at a time. Imagine if I have a mxnx3 matrix A. At each position (m,n) in the matrix, there are stored 3 values, each representing a coefficient of an quadratic equation.

e.g. A(m,n,:) = [1 2 3] for the equation x^2 +2x+3=0.

I would like to solve the quadratic equation at each location (m,n) simultaneously, without having to use the function roots() and loop through each matrix position.

I would really appreciate some help on this!

Thank you in advance!

Joe

Subject: How to solve a set of univariate quadratic equations simultaneously?

From: Roger Stafford

Date: 24 May, 2012 08:26:07

Message: 2 of 4

"Joe " <joe1030@hotmail.com> wrote in message <jpk5uk$d0h$1@newscl01ah.mathworks.com>...
> I am trying to find an efficient way to solve a whole set of quadratic equations. The function roots(p) can only solve one quadratic equation at a time. Imagine if I have a mxnx3 matrix A. At each position (m,n) in the matrix, there are stored 3 values, each representing a coefficient of an quadratic equation.
> e.g. A(m,n,:) = [1 2 3] for the equation x^2 +2x+3=0.
- - - - - - - - - - -
 a = A(:,:,1); b = (:,:,2); c = A(:,:,3);
 X(:,:,1) = (-b+sqrt(b.^2-4*a.*c))./(2*a);
 X(:,:,2) = (-b-sqrt(b.^2-4*a.*c))./(2*a);

  My high school algebra teacher wrote the equivalent of this formula in my yearly annual to make sure I remembered it. I had forgotten it on one of her quizzes.

Roger Stafford

Subject: How to solve a set of univariate quadratic equations simultaneously?

From: Roger Stafford

Date: 24 May, 2012 08:37:08

Message: 3 of 4

"Roger Stafford" wrote in message <jpkrav$6ga$1@newscl01ah.mathworks.com>...
> a = A(:,:,1); b = (:,:,2); c = A(:,:,3);
- - - - - - - - -
  Oops! The first line should read:

 a = A(:,:,1); b = A(:,:,2); c = A(:,:,3);

Roger Stafford

Subject: How to solve a set of univariate quadratic equations simultaneously?

From: Joe Xiao

Date: 24 May, 2012 15:24:23

Message: 4 of 4

"Roger Stafford" wrote in message <jpkrvk$8qo$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jpkrav$6ga$1@newscl01ah.mathworks.com>...
> > a = A(:,:,1); b = (:,:,2); c = A(:,:,3);
> - - - - - - - - -
> Oops! The first line should read:
>
> a = A(:,:,1); b = A(:,:,2); c = A(:,:,3);
>
> Roger Stafford

Thanks Roger! Sometimes you're just so set on finding a function that'll do the job that you forget to go back to the basics! lol Thanks again!

Joe

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us