picewise quadratic fit

picewise quadratic fit - maybe a newbie question.. - Messages

#1 Posted: 12/14/2023 7:31:52 PM
zhkz

zhkz

3 likes in 13 posts.

Group: User

hello everyone,
i want to fit a list of data points by picewise quadratic function like this,

1.png
where 0.6 is the break point that i chose in advance .

the requirements are:
1. the function and its first derivetive at the break point should be continuous,
2. the break point is not known thus is also a parameter to fit.
(but in my data points, i wold like to choose 0.6 as breakpoint in advance )

this picewise quadratic is taken from a empirial expression , so it's not appropriate to take other function forms

The Fit function provided by Maxima plugin seems can not do that:
2.png


any suggestion is welcomed, the .sm file is attatched for the datapoints
thanks in advance.
picewise_qudratic_fit.sm (14 KiB) downloaded 20 time(s).
#2 Posted: 12/14/2023 9:47:38 PM
StvMath

StvMath

35 likes in 56 posts.

Group: User

Maxima isn't required! See the attached. (This simple approach isn't quite continuous at the cross-over point, though it would be if you had chosen x = 0.555).

picewise_qudratic_fit_b.sm (20 KiB) downloaded 29 time(s).
1 users liked this post
Alvaro Diaz Falconi 12/15/2023 1:58:00 PM
#3 Posted: 12/15/2023 1:10:16 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

I want to fit a list of data points by picewise quadratic function
the requirements are:
1. the function and its first derivative at the break point should be continuous,
2. the break point is not known thus is also a parameter to fit.
................
Quadratic joins at support points automated wrt X vector.
Quadratic derivative can't be smooth at junctions.
Only cubic derivative is smooth at junctions.
Jean

Worksheet30.sm (32 KiB) downloaded 18 time(s).
#4 Posted: 12/15/2023 11:39:33 AM
zhkz

zhkz

3 likes in 13 posts.

Group: User

Wrote

though it would be if you had chosen x = 0.555).

picewise_qudratic_fit_b.sm (20 KiB) downloaded 29 time(s).



thanks for your solution , but even though at 0.555 , the first derivative is not continuous
1.png
2.png

maybe the first derivative continuity of quadratic function at joint point can not be achieved in theory as Jean Giraud said , though the empirial expression I refer to does have continuity at joint point, the empirial expression ,which only needs the max y value , the min y value and a paticular x value , can give the picewice qudratic function , as below

tmpB332.png
5.png
the below figure have some typos in formula of a1 and b1 ,the above figue is correct

well i think it must have some additonal constraint conditon to achieve that.

if intrested , you can find this empirial function at :
[1] Li X, Shao W, Tang J, et al. An Investigation of the Contact Fatigue Characteristics of an RV Reducer Crankshaft, Considering the Hardness Gradients and Initial Residual Stress[J]. Materials, 2022, 15(21): 7850.
[2] Wang W, Liu H, Zhu C, et al. Evaluation of contact fatigue risk of a carburized gear considering gradients of mechanical properties[J]. Friction, 2020, 8(6): 1039-1050.

#5 Posted: 12/15/2023 1:59:22 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Maxima isn't required! See the attached. (This simple approach isn't quite continuous at the cross-over point, though it would be if you had chosen x = 0.555).

picewise_qudratic_fit_b.sm (20 KiB) downloaded 29 time(s).



Hi. I just take the excelent Stv work and add some basic maths.

picewise_qudratic_fit_b.sm (30 KiB) downloaded 23 time(s).

Clipboard01.png

Best regards.
Alvaro.
#6 Posted: 12/15/2023 2:38:51 PM
zhkz

zhkz

3 likes in 13 posts.

Group: User

Thank you all guys and have a nice day, looks like I'll have to accept the fact that the jump point derivatives are discontinuous.
#7 Posted: 12/15/2023 7:31:12 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

General remark for Fit():

- names for the variables and the parameters must be undefined. Use Clear for repeated fits if assignment was used.
- You can do the fit, evaluate the mean square error and plot the function without actually assigning the variables.
- Sometimes the default precision is not sufficient, then it is advisable to reduce the tolerance (optional argument)

For piecewise functions, use conditionals wrapped in charfun(). In Maxima conditionals evaluate to true or false, charfun() converts that to 1 or 0, so you can do arithmetics and plotting
If you want continuity between the functions, use the conditions to eliminate some parameters symbolically. This enforces these conditions exactly.

For the discontinuous independent functions, the fit can't include x.0 because the target function's dependence on x.0 is piecewise constant between data points. x.0 essentially assigns the data points to the independent fit ranges. So the derivative is zero or undefined, which Fit() can't handle.

For the continuous fit, the inclusion of x.0 as fit variable also fails but with less obvious reason, at least the derivatives of the error wrt x.0 should not be zero between data points.

picewise_qudratic_fit_Kr.sm (82 KiB) downloaded 22 time(s).

2023-12-15 12_10_11-SMath Solver - [picewise_qudratic_fit_Kr.sm_].png

2023-12-15 12_09_29-SMath Solver - [picewise_qudratic_fit_Kr.sm_].png
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#8 Posted: 12/15/2023 8:51:31 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

hello everyone,


I see 3 plots, 3 correct plots but wrong.
Wrong ... explain:
plot 1000 points to get nice vertical discontinuity.
Jean

#9 Posted: 12/15/2023 9:14:50 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I see 3 plots, 3 correct plots but wrong.
Wrong ... explain:
plot 1000 points to get nice vertical discontinuity.
Jean



Worksheet66.sm (5 KiB) downloaded 24 time(s).

  • New Posts New Posts
  • No New Posts No New Posts