Skip to main content
1-Visitor
July 7, 2021
Solved

fitting Data with genfit and a model based on a numerical solved ODE

  • July 7, 2021
  • 1 reply
  • 2793 views

Hello,

 

I have a very complex differential equation that can only be solved numerically. Here I use a simple differential equation as a proxy for the sake of clarity. This differential equation contains the parameter a. I would like to determine this parameter a by fitting it with the method of least squares with my data X and Y. I need the numerical solution of the differential equation. From the numerical solution of the differential equation I only need the last value for each row of my data X. This is done by the function xsolvend. This is done by the function xsolvend.

Because the differential equation is complex, I use genfit. For this I need the function xsolvend_fit which contains the derivative after the fitting parameter a.

The numerical solution of the differential equation with determination of the final value works. See comparison with the analytical solution, which I can easily determine in this simple example.

Already with xsolvend_fit there are problems and Mathcad cannot calculate this.

Mathcad returns the following error for genfit: "There is no convergent solution for this regression. Check your derivatives, let genfit calculate the derivatives numerically, check your model for singularities, or try different starting values."

How can I have the derivatives of xsolvend_fit calculated numerically?

Does anyone have an idea for a solution?

 

Thank you very much.

 

Best regards

Paul

Best answer by Werner_E

Here is a similar approach using "genfit". I am not sure why you think that the fit function should return a vector of two elements and use the derivative.

Werner_E_0-1625788138357.png

Mathcad 15 sheet attached

 

1 reply

25-Diamond I
July 7, 2021

The function you can use in genfit must have at least two arguments (a free variable and a parameter or parameter list). Your function fit has just the parameter a as its only argument.

1-Visitor
July 8, 2021

Hello Werner,

 

Thank you very much for your advice. I have implemented it. But it still doesn't work. The problem is probably that no derivative can be calculated from the numerical function or the picking function.

My idea now is that I first calculate the parameter a for each data point of X and Y. Then I calculate the mean value from all the values of a. In the case of the analytical solution, I simply rearrange the equation and get a=x/Y Can I also realise this with Odesolve? Unfortunately, I have not been successful so far. I have thought of another way, which is shown in the appendix. It uses the function Find(x). For one data point this way works. For several data points, unfortunately, it doesn't, especially since I then also need the estimated value as a vector.

Maybe you have another idea.

Thanks a lot

Best regards

Paul

25-Diamond I
July 8, 2021

I think I now understood what you are looking for and I guess you won't need "genfit". After all you don't want to fit a function but just to find a single value which gives a desired result.

The secret to success seems to be to set up all functions to work for single scalars first without having vector arguments in mind. At last you can call those function with vectors as arguments if you use vectorization:

Werner_E_0-1625786981899.png

Mathcad 15 sheet attached