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:
Root finding for non-polynomials

Subject: Root finding for non-polynomials

From: rmutt

Date: 30 Apr, 2008 21:28:29

Message: 1 of 6

In relation to my previous post, I wonder if anyone can point me to a good root-finding algorithm that allows real coefficients with sums of non-integer exponents; eg, (3-2i)+2*x^(1/2)+3x.

In MATLAB, there is 'roots' which only works for polynomials and 'fzero' which will not take complex coefficients. I have created an implementation of Laguerre's method using a symbolic equation that works quite well, but is slow... Mathematica can run my entire dataset in several seconds while my code in MATLAB will take 2 seconds to run each point. Any help would be greatly appreciated!

Subject: Root finding for non-polynomials

From: Roger Stafford

Date: 30 Apr, 2008 22:07:03

Message: 2 of 6

rmutt <bach_1006@yahoo.com> wrote in message
<25649841.1209590939923.JavaMail.jakarta@nitrogen.mathforum.org>...
> In relation to my previous post, I wonder if anyone can point me to a good
root-finding algorithm that allows real coefficients with sums of non-integer
exponents; eg, (3-2i)+2*x^(1/2)+3x.
>
> In MATLAB, there is 'roots' which only works for polynomials and 'fzero'
which will not take complex coefficients. I have created an implementation of
Laguerre's method using a symbolic equation that works quite well, but is
slow... Mathematica can run my entire dataset in several seconds while my
code in MATLAB will take 2 seconds to run each point. Any help would be
greatly appreciated!
------------
  If, as in this post and in your other post, the powers are all multiples of 1/2,
this is a problem that can be solved using matlab's 'roots'. For example,

 (3-2i)+2*x^(1/2)+3x = 0

can be solved as a problem of finding the roots of the polynomial equation

 (3-2i)+2*y+3*y^2 = 0

and then the squares of these y-roots being taken to get the x-roots. (You
could also use the quadratic equation formula in this example.)

  A similar statement is also true for other fractional powers with small
fractions involved.

Roger Stafford

Subject: Root finding for non-polynomials

From: rmutt

Date: 1 May, 2008 15:29:01

Message: 3 of 6

This is what pursued originally, but it never really worked out well. Now I realize that was partly because of my coding error. The other problem is that 'roots' can return values that are not even roots! For example, consider the function: -3*x + 2*sqrt(x) + (3-2i)

roots([-3,2,3-2i]).^2 >> 1.9536-0.8692i; 0.4909-0.4641i
secant(), findroot() >> 1.9536-0.8692i

Substituting 0.4909-0.4641i into the equation returns 3.05-1.2i; clearly not a root. I can easily throw out nonsense values but am still often left with a decision about which of a couple of values is most appropriate.

Subject: Root finding for non-polynomials

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 1 May, 2008 18:24:37

Message: 4 of 6

In article <11204850.1209655772018.JavaMail.jakarta@nitrogen.mathforum.org>,
rmutt <bach_1006@yahoo.com> wrote:
>This is what pursued originally, but it never really worked out well. Now I realize that was partly because of my coding error. The other problem is that 'roots' can return values that are not even roots! For example, consider the function: -3*x + 2*sqrt(x) + (3-2i)

>roots([-3,2,3-2i]).^2 >> 1.9536-0.8692i; 0.4909-0.4641i
>secant(), findroot() >> 1.9536-0.8692i

>Substituting 0.4909-0.4641i into the equation returns 3.05-1.2i; clearly not a root. I can easily throw out nonsense values but am still often left with a decision about which of a couple of values is most appropriate.


It depends how you define sqrt(x). You have defined it in terms of
the principal square root, but the negative of that principle value
is also a square root. If we carry the negative outside and continue
to use the principle square root calculator, then we have the
new equation -3*x - 2*sqrt(x) + (3-2i)
and 0.4909-0.4641i *is* a solution to that.

As your -3*x + 2*sqrt(x) + (3-2i) is symbolic and not specific about
which square root should be taken, finding both roots is correct.
--
  "The study of error is not only in the highest degree
  prophylatic, but it serves as a stimulating introduction to the
  study of truth." -- Walter Lipmann

Subject: Root finding for non-polynomials

From: Roger Stafford

Date: 1 May, 2008 18:46:04

Message: 5 of 6

rmutt <bach_1006@yahoo.com> wrote in message
<11204850.1209655772018.JavaMail.jakarta@nitrogen.mathforum.org>...
> This is what pursued originally, but it never really worked out well. Now I
realize that was partly because of my coding error. The other problem is that
'roots' can return values that are not even roots! For example, consider the
function: -3*x + 2*sqrt(x) + (3-2i)
>
> roots([-3,2,3-2i]).^2 >> 1.9536-0.8692i; 0.4909-0.4641i
> secant(), findroot() >> 1.9536-0.8692i
>
> Substituting 0.4909-0.4641i into the equation returns 3.05-1.2i; clearly
not a root. I can easily throw out nonsense values but am still often left with
a decision about which of a couple of values is most appropriate.
--------
  In the theory of complex functions one learns that the square root analytic
function has two branches of equal validity. As you circle around the origin,
one branch moves continuously into the other branch, and it takes two trips
around to return to the original branch if you want to avoid discontinuities.
Hence, the square root of any complex number is considered to have two
possible answers, one the negative of the other.

  The matlab function z^(1/2) always selects the one with the non-negative
real part, but there is a penalty to pay in doing so. As you circle across the
negative real line in the z-plane, the matlab answer does a discontinuous
jump in its imaginary part. Matlab's choice is in keeping with the convention
that for positive real numbers the positive square root is always selected. But
as you see, in the broader sense of the complex world, both answers must be
considered to be valid.

  In the equation you mentioned, -3*x + 2*sqrt(x) + (3-2i) = 0 really does
have two possible roots, depending on how the square root is selected. The
value 0.4909-0.4641i which you rejected, actually is a root if its square root
with the negative real part is selected, and that should be considered a
perfectly valid square root value. To admit one and reject the other as a
"nonsense" value seems like a very arbitrary action if one is working with
complex numbers.

  In any case, I would think that deciding which root to choose is a much less
difficult operation than finding the roots in the first place.

Roger Stafford

Subject: Root finding for non-polynomials

From: rmutt

Date: 1 May, 2008 20:12:06

Message: 6 of 6

Right, thanks for the correction.

Tags for this Thread

No tags are associated with 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