Would the use of cubic splines increase the number of data points to interpolate from result in smaller error...
$begingroup$
I am implementing the cubic spline method to interpolate the function:
$$f(x)=sin(x); -π≤0≤π$$
I am using this paper by Antony Jameson to construct my code, with a few modifications to correct the various typos on that paper. I am using uniformly spaced anchor points and natural spline boundary conditions, and I am breaking the range of $-π ≤ 0 ≤ π$ into $100$ splines/$101$ points.
When I set the number of data points to interpolate from to be $N=4$ and $N=8$ and compared it to the actual graph of the function, the resulting graph looked like this:
which is fine and dandy. However, when I set the number of data points to be $N=10$ and $N=16$, the result is not as good:
As we can see from the second graph, the interpolation produces zero values on the positive end of the graph when I input $10$ and $16$ data points. When I checked the value of my interpolation, I found that the last three spline-ends yield zeroes like this:
$$smallbegin{bmatrix}
-0.00000 & -0.06274 & -0.12524 & cdots & 0.24669 & 0.18695 & 0.00000 & 0.00000 & 0.00000\
end{bmatrix}$$
I have scoured the net and found something called Runge's phenomenon, and it seems that my implementation of the cubic spline has run into that phenomenon. However, when reading further, I have found that the phenomenon should not occur in cubic splines.
What am I doing wrong? Is there something wrong with my implementation, or is that phenomenon occurs to everyone applying the cubic spline to the sine function?
interpolation spline
$endgroup$
add a comment |
$begingroup$
I am implementing the cubic spline method to interpolate the function:
$$f(x)=sin(x); -π≤0≤π$$
I am using this paper by Antony Jameson to construct my code, with a few modifications to correct the various typos on that paper. I am using uniformly spaced anchor points and natural spline boundary conditions, and I am breaking the range of $-π ≤ 0 ≤ π$ into $100$ splines/$101$ points.
When I set the number of data points to interpolate from to be $N=4$ and $N=8$ and compared it to the actual graph of the function, the resulting graph looked like this:
which is fine and dandy. However, when I set the number of data points to be $N=10$ and $N=16$, the result is not as good:
As we can see from the second graph, the interpolation produces zero values on the positive end of the graph when I input $10$ and $16$ data points. When I checked the value of my interpolation, I found that the last three spline-ends yield zeroes like this:
$$smallbegin{bmatrix}
-0.00000 & -0.06274 & -0.12524 & cdots & 0.24669 & 0.18695 & 0.00000 & 0.00000 & 0.00000\
end{bmatrix}$$
I have scoured the net and found something called Runge's phenomenon, and it seems that my implementation of the cubic spline has run into that phenomenon. However, when reading further, I have found that the phenomenon should not occur in cubic splines.
What am I doing wrong? Is there something wrong with my implementation, or is that phenomenon occurs to everyone applying the cubic spline to the sine function?
interpolation spline
$endgroup$
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07
add a comment |
$begingroup$
I am implementing the cubic spline method to interpolate the function:
$$f(x)=sin(x); -π≤0≤π$$
I am using this paper by Antony Jameson to construct my code, with a few modifications to correct the various typos on that paper. I am using uniformly spaced anchor points and natural spline boundary conditions, and I am breaking the range of $-π ≤ 0 ≤ π$ into $100$ splines/$101$ points.
When I set the number of data points to interpolate from to be $N=4$ and $N=8$ and compared it to the actual graph of the function, the resulting graph looked like this:
which is fine and dandy. However, when I set the number of data points to be $N=10$ and $N=16$, the result is not as good:
As we can see from the second graph, the interpolation produces zero values on the positive end of the graph when I input $10$ and $16$ data points. When I checked the value of my interpolation, I found that the last three spline-ends yield zeroes like this:
$$smallbegin{bmatrix}
-0.00000 & -0.06274 & -0.12524 & cdots & 0.24669 & 0.18695 & 0.00000 & 0.00000 & 0.00000\
end{bmatrix}$$
I have scoured the net and found something called Runge's phenomenon, and it seems that my implementation of the cubic spline has run into that phenomenon. However, when reading further, I have found that the phenomenon should not occur in cubic splines.
What am I doing wrong? Is there something wrong with my implementation, or is that phenomenon occurs to everyone applying the cubic spline to the sine function?
interpolation spline
$endgroup$
I am implementing the cubic spline method to interpolate the function:
$$f(x)=sin(x); -π≤0≤π$$
I am using this paper by Antony Jameson to construct my code, with a few modifications to correct the various typos on that paper. I am using uniformly spaced anchor points and natural spline boundary conditions, and I am breaking the range of $-π ≤ 0 ≤ π$ into $100$ splines/$101$ points.
When I set the number of data points to interpolate from to be $N=4$ and $N=8$ and compared it to the actual graph of the function, the resulting graph looked like this:
which is fine and dandy. However, when I set the number of data points to be $N=10$ and $N=16$, the result is not as good:
As we can see from the second graph, the interpolation produces zero values on the positive end of the graph when I input $10$ and $16$ data points. When I checked the value of my interpolation, I found that the last three spline-ends yield zeroes like this:
$$smallbegin{bmatrix}
-0.00000 & -0.06274 & -0.12524 & cdots & 0.24669 & 0.18695 & 0.00000 & 0.00000 & 0.00000\
end{bmatrix}$$
I have scoured the net and found something called Runge's phenomenon, and it seems that my implementation of the cubic spline has run into that phenomenon. However, when reading further, I have found that the phenomenon should not occur in cubic splines.
What am I doing wrong? Is there something wrong with my implementation, or is that phenomenon occurs to everyone applying the cubic spline to the sine function?
interpolation spline
interpolation spline
edited Dec 8 '18 at 10:54
sagungrp
asked Dec 8 '18 at 10:36
sagungrpsagungrp
11
11
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07
add a comment |
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3030943%2fwould-the-use-of-cubic-splines-increase-the-number-of-data-points-to-interpolate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3030943%2fwould-the-use-of-cubic-splines-increase-the-number-of-data-points-to-interpolate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $cos x$.)
$endgroup$
– Oscar Lanzi
Dec 8 '18 at 10:45
$begingroup$
Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value.
$endgroup$
– sagungrp
Dec 8 '18 at 10:51
$begingroup$
Are you using single precision floating number in your codes? If yes, try using double precision floating numbers.
$endgroup$
– fang
Dec 8 '18 at 22:07