Fitting to Tanh function

Discussion in 'MATLAB' started by Darren Weinhold, Jun 30, 2011.

  1. 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
     
    Darren Weinhold, Jun 30, 2011
    #1
    1. Advertisements

  2. Darren Weinhold

    Alan Weiss Guest

    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
     
    Alan Weiss, Jun 30, 2011
    #2
    1. Advertisements

  3. Darren Weinhold

    Torsten Guest

    help lsqcurvefit

    Best wishes
    Torsten.
     
    Torsten, Jul 1, 2011
    #3
  4. 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!
     
    Darren Weinhold, Jul 6, 2011
    #4
  5. 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, Jul 6, 2011
    #5
  6. Darren Weinhold

    Alan Weiss Guest

    Alan Weiss, Jul 6, 2011
    #6
  7. 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
     
    Darren Weinhold, Jul 6, 2011
    #7
  8. Darren Weinhold

    Alan Weiss Guest

    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

     
    Alan Weiss, Jul 7, 2011
    #8
  9. Thanks so much for helping me!


     
    Darren Weinhold, Jul 7, 2011
    #9
  10. Darren Weinhold

    Greg Heath Guest

     
    Greg Heath, Jul 7, 2011
    #10
  11. Another option is to map the real line to [-1,1] with the arctanh function and do a linear regression there and map back.
     
    Greg von Winckel, Jul 7, 2011
    #11
  12. Darren Weinhold

    Greg Heath Guest

    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, Jul 7, 2011
    #12
  13. Darren Weinhold

    Greg Heath Guest


    This CSSM thread throws some light on the subject:

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

    Greg
     
    Greg Heath, Jul 8, 2011
    #13
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.