cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

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

PS_9759531
8-Gravel

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

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

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:PS_9759531)

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

 

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:PS_9759531)

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.

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

Werner_E
25-Diamond I
(To:PS_9759531)

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

 

Werner_E
25-Diamond I
(To:PS_9759531)

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

 

Hello Werner,

 

Thank you very much for your solutions. They were both very helpful to me. I was able to solve my actual problem. It is really amazing how much knowledge you have.

I only understood the vectorise command now! Many thanks for that too.

I got the idea with the derivatives for genfit from the Mathcad help. There, the derivative was still added.

Best regards

Paul

Werner_E
25-Diamond I
(To:PS_9759531)


I got the idea with the derivatives for genfit from the Mathcad help. There, the derivative was still added.

Best regards

Paul


Sorry, you are right! I completely forgot about that as  I seldom used genfit with that option. Providing the symbolic(!!) derivative functions helps the algorithm as it does not have to use (inprecise) numerical derivation that way. But you don't have a symbolic representation of your function which returns the end y-value as it relies on the result of odesolve which is a numerical bunch of data points only.

Announcements

Top Tags