Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Levenberg marquardt C coding algorithm

  1. Feb 5, 2013 #1
    HI guys. Haven't been here in a while...
    I have an algorithm attached that uses the levenberg marquardt non linear curve fitting alogrithm to fit a surface.
    My C coding skills are reasonable, however I am struggling to adjust the model so that I can fit my curve to it. I want to use this algorithm as its a nice standalone algorithm as opposed to some of these otherones that come as part of much larger packages.
    I have a simple dataset:
    double tx[5] = {1, 2, 3, 4, 5};
    double tz[5] = {1.2, 2.693, 4.325, 6.131, 8.125};
    that I am trying to fit to the following function:
    Code (Text):

     for (i = 0; i <sizeof(tz)-1; i++)
      {
        invtrig = arcsinh(sinh(p[2])*exp(p[0]*(i+1)*2*3.145));
        Fitted_Curve[i] = (1/(p[0]*p[1]))*(p[2]-invtrig);
        x += pow((tz[i]-Fitted_Curve[i]), 2);
     
        }
    return x;
     
    The original surface that the model was trying to fit was:
    Code (Text):

    double f( double tx, double tz, const double *p )
    {
        return p[0] + p[1]*tx + p[2]*tz;
    }
     
    Due to the simplicity of this algorithm I am struggling to see how to "convert" it all over so that it will successfully solve mine (which i have the solution to). I can get it to compile if I force it to, but it doesnt converge on the correct results at all - heads to #NAN#
    I have attached the code, there is one file called myalgorithm.c which I have been working on to get mine to work, and then there is surface1.c which is the example. Obviously only bring one into a project at a time as they both have a main in.
    Thanks
     

    Attached Files:

  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Levenberg marquardt C coding algorithm
  1. Symplectic algorithm (Replies: 4)

  2. Thomas algorithm (Replies: 3)

  3. Matlab code (Replies: 1)

Loading...