JSXGraph logo
JSXGraph
JSXGraph share

Share

Cubic spline interpolation
QR code
<iframe 
    src="http://jsxgraph.org/share/iframe/cubic-spline-interpolation" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Cubic spline interpolation" 
    allowfullscreen
></iframe>
This code has to
<input type="button" value="Add point" onClick="addPoint()">

<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution 4.0 International License.
    https://creativecommons.org/licenses/by/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    const board = JXG.JSXGraph.initBoard(BOARDID, {boundingbox: [-5, 10, 7, -5], axis:true});
    
    // Create 4 initial points
    var p = [];
    p[0] = board.create('point', [-1,2], {size: 4});
    p[1] = board.create('point', [0,-1], {size: 4});
    p[2] = board.create('point', [1,0], {size: 4});
    p[3] = board.create('point', [2,1], {size: 4});
    
    // Cubic spline 
    var c = board.create('spline', p, {strokeWidth:3});
    
    // Add tangent
    var g = board.create('glider', [1.5, 0, c], {name:'', face:'<>', color: 'blue'});
    var t = board.create('tangent', [g], {dash:2, strokeColor:'#aa0000'});
         
    var addPoint = function() {
        p.push(board.create('point', [(Math.random() - 0.5) * 10, (Math.random() - 0.5) * 3], {size: 4}));
        board.update();
        board.update();
    }           
    
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

const board = JXG.JSXGraph.initBoard(BOARDID, {boundingbox: [-5, 10, 7, -5], axis:true});

// Create 4 initial points
var p = [];
p[0] = board.create('point', [-1,2], {size: 4});
p[1] = board.create('point', [0,-1], {size: 4});
p[2] = board.create('point', [1,0], {size: 4});
p[3] = board.create('point', [2,1], {size: 4});

// Cubic spline 
var c = board.create('spline', p, {strokeWidth:3});

// Add tangent
var g = board.create('glider', [1.5, 0, c], {name:'', face:'<>', color: 'blue'});
var t = board.create('tangent', [g], {dash:2, strokeColor:'#aa0000'});
     
var addPoint = function() {
    p.push(board.create('point', [(Math.random() - 0.5) * 10, (Math.random() - 0.5) * 3], {size: 4}));
    board.update();
    board.update();
}           

Cubic spline interpolation

A cubic spline function graph through given points is constructed. Points can be added by clicking on "Add point".
<input type="button" value="Add point" onClick="addPoint()">
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {boundingbox: [-5, 10, 7, -5], axis:true});

// Create 4 initial points
var p = [];
p[0] = board.create('point', [-1,2], {size: 4});
p[1] = board.create('point', [0,-1], {size: 4});
p[2] = board.create('point', [1,0], {size: 4});
p[3] = board.create('point', [2,1], {size: 4});

// Cubic spline 
var c = board.create('spline', p, {strokeWidth:3});

// Add tangent
var g = board.create('glider', [1.5, 0, c], {name:'', face:'<>', color: 'blue'});
var t = board.create('tangent', [g], {dash:2, strokeColor:'#aa0000'});
     
var addPoint = function() {
    p.push(board.create('point', [(Math.random() - 0.5) * 10, (Math.random() - 0.5) * 3], {size: 4}));
    board.update();
    board.update();
}           

license

This example is licensed under a Creative Commons Attribution 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.