# [R] nonlinear curve fitting on a torus

Spencer Graves spencer.graves at pdf.com
Mon Apr 14 17:11:21 CEST 2008

```      Have you tried plotting it, e.g., like the following:

npts = 51 # or some number
h = seq(0, ???, length=npts)
funh <- rep(NA, npts)
for(i in 1:npts)funh[i] <- fun(h[i])
plot(h, funh)

Hope this helps.
Spencer

Sungsu wrote:
>
> Dear Spencer.
>
>
> I have n data points observed on the surface of a torus. I am trying
> to fit the geodesic line equation to these points on the surface:
>
> the equation is
> ‘u=h*integrate(((5+cos(v))*sqrt((5+cos(v))^2-h^2))^{-1}) from 0 to v’.
>
> I wrote the following R code to make the above function.
>
> fun<-function(h)
>
> {
>
> u<-h*integrate(((5+cos(y))*sqrt((5+cos(y))^2-h^2))^(-1)),lower=0,upper=v)\$value
>
> u
>
> }
>
> Then minimized the sum of
> (1-cos(u-h**integrate(((5+cos(y))*sqrt((5+cos(y))^2-h^2))^(-1)),lower=0,upper=v)\$value)
> as:
>
> nlminb(c(1),fun,lower=0,upper=9)
>
> I did not get an error, but the estimated h is 9 or 0, these are just
> boundaty values.
>
> I would like to appreciate your help.
>
>
>
> Sungsu
>
> UCR
>
> ps: you may use any sized two vectors for u and v with values from 0
> to 2pi in the above equation.
>
> ---- Original message ----
>
>     *Date:* Sun, 13 Apr 2008 13:54:17 -0700
>     *From:* Spencer Graves <spencer.graves at pdf.com>
>     *Subject:* Re: [R] nonlinear curve fitting on a torus
>     *To:* Sungsu <skim033 at ucr.edu>
>     *Cc:* r-help at r-project.org
>     > Having seen no reply to this, I will offer a couple of comments
>     >that may or may not be useful. Googling for "geodesic equation on a
>     >torus" produced interesting hits, but RSiteSearch("geodesic
>     equation on
>     >a torus") found nothing. RSiteSearch("torus") returned 33 hits,
>     some of
>     >which referred to a package "geozoo".
>     >
>     > If you want a solution of a differential equation, you might
>     >consider lsoda {odesolve}. The 'fda' package may also be useful.
>     >
>     > To say more, I'd prefer to hear more specifics from you. PLEASE
>     >do read the posting guide
>     "http://www.R-project.org/posting-guide.html"
>     >and provide commented, minimal, self-contained, reproducible code.
>     >Doing so can make it much easier for people to understand what you
>     >want. If you provide code that doesn't quite work, someone who is
>     >interested can copy it from your email into R and try things,
>     possibly
>     >generating a solution to your problem. Without a self-contained
>     >example, you restrict the pool of possible respondents to people who
>     >have actually worked with a "geodesic equation on a torus" -- or to
>     >fools like me who are willing to expose their ignorance
>     commenting on
>     >something we know essentially nothing about.
>     >
>     > Hope this helps.
>     > Spencer Graves
>     >
>     >Sungsu wrote:
>     >> Dear R users.
>     >>
>     >> I have data observed on the surface of a torus, and
>     >> am trying to fit the nonlinear regression using
>     >>
>     >> the geodesic equation on a torus. Could anyone give
>     >>
>     >> Sincerely,
>     >>
>     >> SUNGSU KIM
>     >>
>     >> [[alternative HTML version deleted]]
>     >>
>     >> ______________________________________________
>     >> R-help at r-project.org mailing list
>     >> https://stat.ethz.ch/mailman/listinfo/r-help