[R] how to fit gauss beam?

From: Thomas Hunger <hto_at_arcor.de>
Date: Mon 04 Sep 2006 - 14:14:50 GMT


I am having a hard time fitting a gauss beam using R. In gnutplot I did something like

$ w(z) = w0 * sqrt(1+(z/z0)**2)
$ fit w(z) 'before_eom.txt' using 1:2 via w0, z0

to obtain w0 and z0. Now I want to do the same in R. I tried a linear model like this (r = radius, z = distance):

beam <- function(z) {
  sum(sqrt(1 + z**2))

lm(r ~ I(beam(z)), data = before_eom)

Which gives nonsensical answers ...

Then I tried a nonlinear model:

d <- read.table ("before_eom.tab", header=T)
z <- d$d
r <- d$minor * 1e-6

beam<- function(p) {
  M <- 1.1
  sum((r-M*p[1]*sqrt(1 + (z/p[2])**2))^2)

out <- nlm(beam, p=c(400, 0.1), hessian=TRUE) out$estimate

This is very sensitive to the starting values and gives nonsensical answers as well...

Is there a simple way to translate the gnuplot fit into R?


R-help@stat.math.ethz.ch 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. Received on Tue Sep 05 00:22:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.