Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the following points, p = [[0,3.8414709848078967],[0.6931471805599453,6.6

ID: 3829731 • Letter: I

Question

I have the following points,

p = [[0,3.8414709848078967],[0.6931471805599453,6.6818861490654635],[1.0986122886681098,7.5355691627323065],[1.3862943611198906,7.788374949171635],[1.6094379124341003,8.478827375073264],[1.791759469228055,9.887622378713294],[1.9459101490553132,11.440627194940042],[2.0794415416798357,12.307124413342725]]

which I need to input into the following Lagrange Interpolation program (I just don't know where to place them):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Lagrange Output</title>
</head>
<body>
<section>
<h1>Lagrange</h1>
<div id="output"></div>

</section>
<script>

var Lagrange = function(x1, y1, x2, y2) {
this.xs = [x1, x2];
this.ys = [y1, y2];
this.ws = [];
this._updateWeights();
}

Lagrange.prototype.addPoint = function(x, y) {
   this.xs.push(x);
   this.ys.push(y);
   this._updateWeights();
   return this.xs.length-1;
}
//changes a previously added point.
Lagrange.prototype.changePoint = function(index, x, y) {
   this.xs[index] = x;
   this.ys[index] = y;
   this._updateWeights();
}
// Recalculate barycentric weights.
Lagrange.prototype._updateWeights = function() {
   var k = this.xs.length;
   var w;
   for (var j = 0; j < k; ++j) {
       w = 1;
       for (var i = 0; i < k; ++i) {
           if (i != j) {
               w *= this.xs[j] - this.xs[i];
           }
       }
       this.ws[j] = 1/w;
   }
}

// Calculate L(x)
Lagrange.prototype.valueOf = function(x) {
   var a = 0;
   var b = 0;
   var c = 0;
   for (var j = 0; j < this.xs.length; ++j) {
       if (x != this.xs[j]) {
           a = this.ws[j] / (x - this.xs[j]);
           b += a * this.ys[j];
           c += a;
       } else {
           return this.ys[j];
       }
   }
   return b / c;
}


var printValue = function(val) {
   var outputDiv = document.getElementById("output");
   outputDiv.innerHTML += "<p>" + val + "</p>";
}

var l = new Lagrange(0,0,1,1);
var index = l.addPoint(0.5, 0.8);
printValue(l.valueOf(0.1));
l.changePoint(index, 0.5, 0.1);
printValue(l.valueOf(0.1));

// whatever value is required.. just call printValue(<value>)

</script>
</body>
</html>

Can someone please show me where in this Lagrange interpolation program these points should go such that when I open the program with a browser an output will appear. I only need one output and that output should appear on the screen like this:

f(1.5)= an answer given by set of points

Explanation / Answer

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Lagrange Output</title>
</head>
<body>
<section>
<h1>Lagrange</h1>
<div id="output"></div>

</section>
<script>
var Lagrange = function(x1, y1, x2, y2) {
this.xs = [x1, x2];
this.ys = [y1, y2];
this.ws = [];
this._updateWeights();
}
Lagrange.prototype.addPoint = function(x, y) {
this.xs.push(x);
this.ys.push(y);
this._updateWeights();
return this.xs.length-1;
}
//changes a previously added point.
Lagrange.prototype.changePoint = function(index, x, y) {
this.xs[index] = x;
this.ys[index] = y;
this._updateWeights();
}
// Recalculate barycentric weights.
Lagrange.prototype._updateWeights = function() {
var k = this.xs.length;
var w;
for (var j = 0; j < k; ++j) {
w = 1;
for (var i = 0; i < k; ++i) {
if (i != j) {
w *= this.xs[j] - this.xs[i];
}
}
this.ws[j] = 1/w;
}
}
// Calculate L(x)
Lagrange.prototype.valueOf = function(x) {
var a = 0;
var b = 0;
var c = 0;
for (var j = 0; j < this.xs.length; ++j) {
if (x != this.xs[j]) {
a = this.ws[j] / (x - this.xs[j]);
b += a * this.ys[j];
c += a;
} else {
return this.ys[j];
}
}
return b / c;
}

var printValue = function(val) {
var outputDiv = document.getElementById("output");
outputDiv.innerHTML += "<p>" + val + "</p>";
}
var l = new Lagrange(0,3.8414709848078967,0.6931471805599453,6.6818861490654635);
var index = l.addPoint(1.0986122886681098,7.5355691627323065);
index = l.addPoint(1.3862943611198906,7.788374949171635);
index = l.addPoint(1.6094379124341003,8.478827375073264);
index = l.addPoint(1.791759469228055,9.887622378713294);
index = l.addPoint(1.9459101490553132,11.440627194940042);
index = l.addPoint(2.0794415416798357,12.307124413342725);

printValue(l.valueOf(1.5));

// whatever value is required.. just call printValue(<value>)
</script>
</body>
</html>

new Lagrange () function is to initiate the lagrange calculation with first two points.

addPoint() is to add more points to the calculation.

valueOf() function is to evaluate the f(x).

printValue() function is to print the values on the screen.