[R] finding complex roots in R

Toros Caglar toros.caglar at gmail.com
Fri Sep 17 00:40:07 CEST 2010


Thanks a lot. This helps a lot.

Toros

On Thu, Sep 16, 2010 at 4:29 PM, Ravi Varadhan <rvaradhan at jhmi.edu> wrote:
> Beware that you are likely to have multiple, or even infinitely many, roots
> in the complex plane.  In the first example, there are infinitely many
> roots, which are equal to +/- 1i  * (N * pi), where N = 1, 3, 5, ...
>
> Similarly, there are infinitely many roots in my second example.
>
> Therefore, I would suggest that you use the `multiStart' function in "BB" to
> explore this in your problem.
>
> Ravi.
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Ravi Varadhan
> Sent: Thursday, September 16, 2010 3:52 PM
> To: 'Toros Caglar'; r-help at r-project.org
> Subject: Re: [R] finding complex roots in R
>
> Hi Toros,
>
> It is actually quite easy to do this with existing real-root finders.  If
> you want to solve for F(z) = 0, where z = x + iy, you simultaneously solve
> for the zeros of the real and imaginary part of F.
>
> Here are a couple of examples using the package "BB":
>
> fn1 <- function(x, a){
> z <- x[1] + 1i * x[2]
> f <- exp(z) + a
> c(Re(f), Im(f))
> }
>
> fn2 <- function(x, a){
> z <- x[1] + 1i * x[2]
> f <- sin(z)^2 + sqrt(z) - log(z)
> c(Re(f), Im(f))
> }
>
> require(BB)
>
> # First example
>> BBsolve(par=c(1,1), fn=fn1, a=1)
>  Successful convergence.
> $par
> [1] -4.799024e-10  3.141593e+00
>
> $residual
> [1] 4.819472e-10
>
> $fn.reduction
> [1] 0.0002550771
>
> $feval
> [1] 81
>
> $iter
> [1] 5
>
> $convergence
> [1] 0
>
> $message
> [1] "Successful convergence"
>
> $cpar
> method      M     NM
>     2     50      1
>
> So, the complex root is: 0 + i*pi, as you might have guessed.
>
> # Second example
>> BBsolve(par=c(1,1), fn=fn2)
>  Successful convergence.
> $par
> [1] 0.2555197 0.8948303
>
> $residual
> [1] 9.079212e-08
>
> $fn.reduction
> [1] 0.0002494436
>
> $feval
> [1] 168
>
> $iter
> [1] 92
>
> $convergence
> [1] 0
>
> $message
> [1] "Successful convergence"
>
> $cpar
> method      M     NM
>     2     50      1
>
> Here the complex root is: 0.2555 + i*0.8948.
>
> In these two examples the function F(z) is scalar.  We can readily extend
> this to vector F using the method that I just described.
>
> Hope this helps,
> Ravi.
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Toros Caglar
> Sent: Wednesday, September 15, 2010 11:33 PM
> To: r-help at r-project.org
> Subject: [R] finding complex roots in R
>
> I am looking for a way to find the roots of a non-polynomial
> expression. I know R has a few ways to deal with polynomials, but, I
> could not find a method that deals with functions involving e^(x) type
> arguments, that have complex roots as well as real roots.
>
> Any ideas?
>
> Thanks,
>
> Toros
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list