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:
Fitting to Tanh function

Subject: Fitting to Tanh function

From: Darren Weinhold

Date: 30 Jun, 2011 14:13:10

Message: 1 of 13

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

Subject: Fitting to Tanh function

From: Alan Weiss

Date: 30 Jun, 2011 17:54:16

Message: 2 of 13

On 6/30/2011 10:13 AM, Darren Weinhold 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

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

Subject: Fitting to Tanh function

From: Torsten

Date: 1 Jul, 2011 07:47:41

Message: 3 of 13

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.

Subject: Fitting to Tanh function

From: Darren Weinhold

Date: 6 Jul, 2011 18:25:29

Message: 4 of 13

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.Hennig@umsicht.fraunhofer.de> wrote in message <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Darren Weinhold

Date: 6 Jul, 2011 18:51:07

Message: 5 of 13

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>...
> 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.Hennig@umsicht.fraunhofer.de> wrote in message <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Alan Weiss

Date: 6 Jul, 2011 19:18:50

Message: 6 of 13

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$pb7$1@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.Hennig@umsicht.fraunhofer.de> wrote in message
>> <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Darren Weinhold

Date: 6 Jul, 2011 19:59:10

Message: 7 of 13

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 <aweiss@mathworks.com> wrote in message <iv2ceq$5hq$1@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$pb7$1@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.Hennig@umsicht.fraunhofer.de> wrote in message
> >> <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Alan Weiss

Date: 7 Jul, 2011 11:53:01

Message: 8 of 13

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

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 <aweiss@mathworks.com> wrote in message
> <iv2ceq$5hq$1@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$pb7$1@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.Hennig@umsicht.fraunhofer.de> wrote in message
>> >> <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Darren Weinhold

Date: 7 Jul, 2011 12:46:25

Message: 9 of 13

Thanks so much for helping me!


Alan Weiss <aweiss@mathworks.com> wrote in message <iv46mu$19h$1@newscl01ah.mathworks.com>...
> 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
>
> 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 <aweiss@mathworks.com> wrote in message
> > <iv2ceq$5hq$1@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$pb7$1@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.Hennig@umsicht.fraunhofer.de> wrote in message
> >> >> <976d409f-e832-4748-a6fd-281ea73caf2b@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.

Subject: Fitting to Tanh function

From: Greg Heath

Date: 7 Jul, 2011 14:59:30

Message: 10 of 13

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 -

Subject: Fitting to Tanh function

From: Greg von Winckel

Date: 7 Jul, 2011 15:15:23

Message: 11 of 13

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>...
> 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

Subject: Fitting to Tanh function

From: Greg Heath

Date: 7 Jul, 2011 18:43:43

Message: 12 of 13

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

Subject: Fitting to Tanh function

From: Greg Heath

Date: 8 Jul, 2011 02:39:21

Message: 13 of 13

On Jul 7, 2:43 pm, Greg Heath <he...@alumni.brown.edu> wrote:
> 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?


This CSSM thread throws some light on the subject:

http://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/8150ccce42b56c5a

Greg

Tags for 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