help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to give as "real column vector of initial parameters" to nonlin


From: Dmitri A. Sergatskov
Subject: Re: What to give as "real column vector of initial parameters" to nonlin_curvefit?
Date: Fri, 12 Jun 2020 12:51:02 -0400



On Fri, Jun 12, 2020 at 6:06 AM Doron Behar <doron.behar@gmail.com> wrote:
On Fri, Jun 12, 2020 at 02:27:18PM +0900, Kai Torben Ohlhus wrote:
>
> You function call does not look that wrong, but the devil is in the
> detail.  Can you sent us a minimal working example containing all
> "guessed_*" values and "counts", "times"?
>
> Kai

Sure, I've attached 2 files to this email that should reproduce the
issue:

- `nomag-50-500.txt` contains the measurements I'm trying to fit the
  data to.
- `MWE.m` reads the measurements from the file, plots the data as is and
  then calls nonlin_curvefit in two different ways. Please see the %%
  comments I wrote in it.


There are multiple problems. 

There are errors in the code. You seem to mix up X and Y variables in plots and fits.
You read data as integers(?) -- why? You want doubles.

Octave (and matlab) is primarily an interactive programming/developing environment.
When your program crashes you still can inspect the variables left and see if the values
of those variables give you some hints.
You say "Using `;` instead of `,` doesn't work either", but the error is different!
It should have given you a clue.

I found in general the curve fitting in "optim" package are more finicky than they should be.
Out of those "leasqr" seems to work better for me than "nonlin_curvefit". 

The parameters in the fit function are usually not the same parameters you would use in
human definition of the function. Usually you want to make them be more similar to each other.
You should avoid divisions if possible.
In you case the function becomes:

exp(a*t)*(b*sin(w*t)+c*cos(w*t))
(a,b,c,w -- fit parameters; w = 2*pi*frequency)
It looks to me it fits better if you add a small offset as well.

Having said that, attached are a modified script and the output it produced for me.
 
Doron.


Dmitri.
--

Attachment: mve_das.m
Description: Text Data

Attachment: data_fit.svg
Description: image/svg

Attachment: error.svg
Description: image/svg


reply via email to

[Prev in Thread] Current Thread [Next in Thread]