kmath icon indicating copy to clipboard operation
kmath copied to clipboard

Calculating the coefficients from values of X and Y.

Open drindt opened this issue 1 year ago • 4 comments

Dear community,

I'm kindly asking for an example of calculating coefficients of a 4th line polynomial. Then I want to calculate the Y value I am looking for from the known X. I am grateful for any help.

drindt avatar Jul 03 '23 07:07 drindt

Could you please elaborate? Do you need to interpolate a fourth-degree polynomial from points? Or you need to fit points with fourth degree polynomial?

I think it is the second one because interpolation does not make a lot of sense with degree higher than 3. The fit example could be found here: https://github.com/SciProgCentre/kmath/blob/b5f85a6d86021a34e3760135b8883e1bf22c9cca/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt#L76. You need to bind additional symbol so it would be four polynomial coefficients and then fit it. I will add an example later.

We can probably add a simplified polynomial fit as well since we have support for polynomials.

SPC-code avatar Jul 03 '23 07:07 SPC-code

@SPC-code I'm not a mathematician, so please be careful with my question. I would like to do fitting, but it should also be possible to search for Y outside, but it doesn't have to be precise. To be a bit more detailed, I have X(0-30000) and Y(0-50.0) values. Now I want to get the Y calculated for the X value.

Thank you for your efforts, which I appreciate very much.

drindt avatar Jul 03 '23 07:07 drindt

@drindt I checked the code. Adding simplified support for polynomial functions will require some minor additions to polynomials API. I will do it later. Right now here is the example using current API: https://datalore.jetbrains.com/view/notebook/DDsWb8KgH71TgC7qsKDGs1. It requires some additional code to set up.

You can call on resultPolynomial.value(arg) both for interpolation and extrapolation. It is also possible to estimate errors for those values, but it would require adding new concepts to the probability part of the framework. Exciting idea, but my time is sadly limited.

SPC-code avatar Jul 07 '23 08:07 SPC-code

Please feel free to start a discussion in #mathematics channel in Kotlin Slack.

SPC-code avatar Jul 07 '23 08:07 SPC-code