**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# Is it possible to specify the 'order' of a smoothing spline?

20 views (last 30 days)

Show older comments

Hello,

I need to use smoothing splines. The matlab command 'csaps' can only be used for the case of a cubic smoothing

spline. On the other hand, the command '[...] = spaps(x,y,tol,[],m)' might be helpful to choose the order. But, there are a

range of difficulties with this command. First, we have to specify the tolerance 'tol' (I do not like to specify anything like tolerance or

smoothing parameter and woulds like the algorithm to choose the default). Second, m can only be 1(linear case), 2(cubic case), or 3 (

the quintic case). In my work I really need to use the 'quadratic smoothin splines'.

If I would like to do 'spline interpolation', instead, I could use the command 'spapi(k,x,y)' and choose k=3 for the case of quadratic spline interpolation. Is there a similar matlab command for smoothing splines? Something like 'spaps(k,x,y)' with no extra inputs like 'tolerance' or 'smoothing parameter' or 'weight'?

If MATLAB does not have the above-mentioned capability then this is a really 'annoying problem' which could be easily prevented by

the developers of spline toolbox. You might think that cubic smoothing splines are sufficient and there really is no need for a parabolic smoothing splines. If you are interested I can give you some important mathematical problems which really need the quadratic smoothing splines.

Any idea?

Thanks in advance!

Babak

##### 13 Comments

Bruno Luong
on 14 Aug 2022

Mohammad Shojaei Arani
on 14 Aug 2022

Thanks Bruno,

I will definitely submit an enhancement request.

Do you have any idea for the question I posed?

Bruno Luong
on 14 Aug 2022

I'm no sure to understand the question since your description seems to focus on lack flexibility of matlab stock function.

If you can synthetize your need independently to TMW existing function it would better for me for grab it.

Torsten
on 14 Aug 2022

The OP is searching for the possibility to get a piecewise quadratic smoothing spline for his data.

Bruno Luong
on 14 Aug 2022

Edited: Bruno Luong
on 14 Aug 2022

Actually I'm confuse by the doc page of spaps

"m: Derivative order, specified as a scalar. This value must be either 1 for a piecewise linear smoothing spline, 2 for the default cubic smoothing spline, or 3 for a quintic smoothing spline."

I actually don't know why m is called "Derivative order". What I know is a spline is a piecewise polynomial (along a fiven dimention), and the poynomial order is

- linear
- quadratic
- cubic
- quartic
- quintic

I cannot make any head and tail with this TMW doc page (it's not the first time), the relation between m and what the description is odd to me. They throw in the doc some momenclature (here "derivative order") obviously not standard and without proper definition.

Mohammad Shojaei Arani
on 14 Aug 2022

Hi Tortsten,

Good help! As always!

You are right. For now, I can use smoothing least-squares splines (rather than smoothing splines) since it supports what I need. I can use the command spline = spap2(knots,k,x,y), and let knots =x, and choose k=3 for parabolic splines. This is great!

However, I believe it is important to also have a similar command for the case of 'Smoothing splines' as they are more popular and, therefore, 'aparently' do a slightly better job than least-squares approximations. So, I believe that the spline toolbox should have a command like spapi(k,x,y), in order to be complete.

Mohammad Shojaei Arani
on 14 Aug 2022

Hi Torsten and Bruno,

I agree with Bruno that the spline toolbox is a bit 'disorganized' in the sense that sometimes it is

a bit confusing. Of course, I respect those who made such a wonderful and important package and

it is really a lot of work they had to do. But, I think, they could make it more complete and choose more 'sensible'

names for the convenience of users. I think specifying the order of splines using K is a bit confusing to users (K=4 means cubic, K=3 means quadratic, etc). Perhaps, it would be more understrandable if they make it using flags (the flag 'cubic' means cubic spline, etc). Another issue is their evaluations which use different commands. For smoothing splines we have to use the command 'ppval' while for least-squares we have to use 'fnval'. I understand, that these make sense for mathematicians but these are confusing to typical users (also a bit annoying for a mathematician like me since I keep 'forgetting' when to use ppval and when to use fnval). I nknow that there is ppform and B-form but they could hide these and use a single command instead of 2. Another confusing issue which I remember is that they are not very careful with names 'knots' and 'breaks' (based on Wikipedia, knots means the sequence of x-data we choose for the splines [x1 x2 x3 ... xn] while breaks is refered to each sub-intervbal, so, [x4 x5] is the fifth break. I see that they sometimes are not careful with these)

And, again, it is really important to have a command like spapi(k,x,y) similar to what we have for the least-squares approximations.

Thanks again!

Torsten
on 14 Aug 2022

Bruno Luong
on 14 Aug 2022

Mohammad Shojaei Arani
on 14 Aug 2022

Yes Bruno,

Quadratic smoothing spline implies that the smoothing approximation should be quadratic on each sub-interval or break. I cannot answer your question "What kind of smoothness do you want" since I never studied the mathematics of smoothing splines. Forget about this.

The person who made the command csaps(x,y) is definitely able to do the same job for smoothing quadratic splines . Since he/she solved the harder cubic problem he/she should be able to solve the easier parabolic problem.

We need a command like spapi(k,x,y), where

k=4 is related to smoothing cubic splines (this is actually equivalent to csaps(x,y)),

k=3 is realted to 'smoothing quadratic splines' (NOT DONE, UNFORTUNATELY)

k=2 is related to 'smoothing linear spline' (NOT DONE, UNFORTUNATELY)

If would be nice if k can be higher to cover the cases of 'Quartic' (k=5) and 'Quintic' (k=6).

VERY IMPORTANT:

Any command about splines MUST also come with its pp-form (or B-form). This allows the user to use the command fnder(pp,1 or 2 or 3 or ...) to find the derivative as well as higher derivatives of spline function under study. Often, when we use the splines we also need information about the derivative(s) if the spline interpolant or approximant.

### Accepted Answer

Bruno Luong
on 14 Aug 2022

See if this can helps you

##### 6 Comments

Mohammad Shojaei Arani
on 14 Aug 2022

Thanks Bruno,

Your package seems 'lovely'! I need to spend time and work on it.

The point in my comments is this: "Mathworks sholud try to make its packages as complete as possible and

as fast as possible". If I would have access to a quntum computer I would never bother you. I would, then, use cubic splines and would not even think to use parabolic splines.

I will contact TMW developers!

Bruno Luong
on 14 Aug 2022

Edited: Bruno Luong
on 14 Aug 2022

Mohammad Shojaei Arani
on 14 Aug 2022

Torsten
on 14 Aug 2022

Edited: Torsten
on 14 Aug 2022

If I would have access to a quntum computer I would never bother you. I would, then, use cubic splines and would not even think to use parabolic splines.

You are kidding, aren't you ? My guess is that you will not even notice the difference in in computation time if you use parabolic instead of cubic spline interpolation/approximation.

Mohammad Shojaei Arani
on 15 Aug 2022

Hi Torsten,

You are right. The computational difference between a linear, quadratic, cubic, quartic, quintic, etc are just nothing. I agree with you.

But, my problem has a completely different nature. In short, imagine you wish to estimate a function f which should satisfy an equation like F(f,df,d2f,d3f,d4f, ...,dnf)=0 . A smart idea is to approximate f with a spline. If I use a cubic spline then I have to deal with an equation of type F(f,df,d2f,d3f) = 0 while if I approximate f with a parabolic spline then I only need to deal with F(f,df,d2f) = 0 (well, linear spline is not very nice, so I avoid it).

Now, imagine that I also have to design a global optimization problem to estimate the parameters of f where I cannot benifit from typical optimization procedures which work based on gradient descent (the reason is long, so I skip this), so I have a non-smooth objective function and therefore am only limitted to use non-gradient based optimization algorithms like genetic algorithm which are not fast unfortunately.

Long story short, if I use parabolic splines life is much better!

but with a quantum computer life is perfect!

### More Answers (0)

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)