Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fitting to Tanh function

189 views
Skip to first unread message

Darren Weinhold

unread,
Jun 30, 2011, 10:13:10 AM6/30/11
to
Hello,

I am do research in plasma physics and am using MATLAB to plot the data I collect for a double langmuir probe. I would like to fit this plotted data to a tanh function since that is what the theory says it should follow. I haven't been able to find anything too helpful so far.

Thanks,
Darren

Alan Weiss

unread,
Jun 30, 2011, 1:54:16 PM6/30/11
to

If you have Statistics Toolbox, try nlinfit.
http://www.mathworks.com/help/toolbox/stats/bq_676m-43.html

If you have Optimization Toolbox, try lsqcurvefit.
http://www.mathworks.com/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1

Alan Weiss
MATLAB mathematical toolbox documentation

Torsten

unread,
Jul 1, 2011, 3:47:41 AM7/1/11
to

help lsqcurvefit

Best wishes
Torsten.

Darren Weinhold

unread,
Jul 6, 2011, 2:25:29 PM7/6/11
to
So I am having trouble defining the function to use here.
I want to fit two variables we will call them 'temperature' and 'current'. The function I want is

current*tanh(xdata/(2*temperature)

where xdata is the xdata of the data that I am fitting to. What would I input in my code to do this?
Thanks!

Torsten <Torsten...@umsicht.fraunhofer.de> wrote in message <976d409f-e832-4748...@x3g2000yqj.googlegroups.com>...

Darren Weinhold

unread,
Jul 6, 2011, 2:51:07 PM7/6/11
to
I should probably also add that I would like the code to display the values of 'temperature' and 'current' as well as the r^2 value.

"Darren Weinhold" wrote in message <iv29ap$pb7$1...@newscl01ah.mathworks.com>...

Alan Weiss

unread,
Jul 6, 2011, 3:18:50 PM7/6/11
to
Did you look at the link I gave in my previous post in this thread?
http://www.mathworks.com/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1

Alan Weiss
MATLAB mathematical toolbox documentation

Darren Weinhold

unread,
Jul 6, 2011, 3:59:10 PM7/6/11
to
Yes, I was just having trouble getting the code to run. However, your post encouraged me to look back at the example and I was simply missing a space. I can now get it to run. Thank you very much!

What exactly is the resnorm? I would like the R-squared value, is this related to it?

Thanks again,
Darren

Alan Weiss <awe...@mathworks.com> wrote in message <iv2ceq$5hq$1...@newscl01ah.mathworks.com>...

Alan Weiss

unread,
Jul 7, 2011, 7:53:01 AM7/7/11
to
As explained in the documentation
http://www.mathworks.com/help/toolbox/optim/ug/f10534.html#brcfihg
"resnorm" is short for norm of the residual, the squared norm of the
vector of errors.

If I understand correctly, R-squared is a measure of the linear errors,
I am not sure how it applies to a nonlinear fitting problem. However, if
you use the nlinfit function from Statistics Toolbox instead of
lsqcurvefit, you can get an estimated covariance matrix for the fitted
parameters, which might satisfy your desire for an accuracy measurement.

Alan Weiss
MATLAB mathematical toolbox documentation

Darren Weinhold

unread,
Jul 7, 2011, 8:46:25 AM7/7/11
to
Thanks so much for helping me!


Alan Weiss <awe...@mathworks.com> wrote in message <iv46mu$19h$1...@newscl01ah.mathworks.com>...

Greg Heath

unread,
Jul 7, 2011, 10:59:30 AM7/7/11
to
On Jul 7, 7:53 am, Alan Weiss <awe...@mathworks.com> wrote:
> As explained in the documentationhttp://www.mathworks.com/help/toolbox/optim/ug/f10534.html#brcfihg

> "resnorm" is short for norm of the residual, the squared norm of the
> vector of errors.
>
> If I understand correctly, R-squared is a measure of the linear errors,
> I am not sure how it applies to a nonlinear fitting problem. However, if
> you use the nlinfit function from Statistics Toolbox instead of
> lsqcurvefit, you can get an estimated covariance matrix for the fitted
> parameters, which might satisfy your desire for an accuracy measurement.
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
>
> On 7/6/2011 3:59 PM, Darren Weinhold wrote:
>
>
>
> > Yes, I was just having trouble getting the code to run. However, your
> > post encouraged me to look back at the example and I was simply missing
> > a space. I can now get it to run. Thank you very much!
> > What exactly is the resnorm? I would like the R-squared value, is this
> > related to it?
>
> > Thanks again,
> > Darren
>
> > Alan Weiss <awe...@mathworks.com> wrote in message
> > <iv2ceq$5h...@newscl01ah.mathworks.com>...

> >> Did you look at the link I gave in my previous post in this thread?
> >>http://www.mathworks.com/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1
>
> >> Alan Weiss
> >> MATLAB mathematical toolbox documentation
>
> >> On 7/6/2011 2:51 PM, Darren Weinhold wrote:
> >> > I should probably also add that I would like the code to display the
> >> > values of 'temperature' and 'current' as well as the r^2 value.
>
> >> > "Darren Weinhold" wrote in message
> >> > <iv29ap$pb...@newscl01ah.mathworks.com>...

> >> >> So I am having trouble defining the function to use here. I want to
> >> >> fit two variables we will call them 'temperature' and 'current'. The
> >> >> function I want is
> >> >> current*tanh(xdata/(2*temperature)
>
> >> >> where xdata is the xdata of the data that I am fitting to. What would
> >> >> I input in my code to do this?
> >> >> Thanks!
>
> >> >> Torsten <Torsten.Hen...@umsicht.fraunhofer.de> wrote in message
> >> >> <976d409f-e832-4748-a6fd-281ea73ca...@x3g2000yqj.googlegroups.com>...

> >> >> > On 30 Jun., 16:13, "Darren Weinhold" <darrenweinh...@gmail.com>
> >> wrote:
> >> >> > > Hello,
>
> >> >> > > I am do research in plasma physics and am using MATLAB to plot the
> >> >> data I collect for a double langmuir probe. I would like to fit this
> >> >> plotted data to a tanh function since that is what the theory says it
> >> >> should follow. I haven't been able to find anything too helpful so
> >> far.
>
> >> >> > > Thanks,
> >> >> > > Darren
> >> >> > > help lsqcurvefit
> >> >> > > Best wishes
> >> >> > Torsten.- Hide quoted text -
>
> - Show quoted text -

Greg von Winckel

unread,
Jul 7, 2011, 11:15:23 AM7/7/11
to
Another option is to map the real line to [-1,1] with the arctanh function and do a linear regression there and map back.

"Darren Weinhold" wrote in message <iui09m$ofb$1...@newscl01ah.mathworks.com>...

Greg Heath

unread,
Jul 7, 2011, 2:43:43 PM7/7/11
to
On Jul 7, 10:59 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Jul 7, 7:53 am, Alan Weiss <awe...@mathworks.com> wrote:
>
>
>
> > As explained in the documentationhttp://www.mathworks.com/help/toolbox/optim/ug/f10534.html#brcfihg
> > "resnorm" is short for norm of the residual, the squared norm of the
> > vector of errors.
>
> > If I understand correctly, R-squared is a measure of the linear errors,
> > I am not sure how it applies to a nonlinear fitting problem. However, if
> > you use the nlinfit function from Statistics Toolbox instead of
> > lsqcurvefit, you can get an estimated covariance matrix for the fitted
> > parameters, which might satisfy your desire for an accuracy measurement.
>
> > Alan Weiss
> > MATLAB mathematical toolbox documentation

Hi Alan,

Isn't it frustrating to be hornswaggled into top-posting
by an OP who doesn't know better?

I have gotten into the habit of using R-squared and
degree-of-freedom adjusted R-squared as performance
measures for nonlinear neural networks.

What is the perceived danger in doing so?

Greg

Greg Heath

unread,
Jul 7, 2011, 10:39:21 PM7/7/11
to
0 new messages