3. You are given a function f(x 2r3r on the interval -2,2] and you want to calcu
ID: 3600657 • Letter: 3
Question
3. You are given a function f(x 2r3r on the interval -2,2] and you want to calculate the first derivative of this function at the points on this interval. Write a MATLAB program that (a) Given the number N of subintervals, calculates the first derivative of the function, fi, at each point zi, including the boundary points, with the first-order accuracy (this can be done as a self-written MATLAB function). You can use any formula of O(h) of your choice. (b) Given the number N of subintervals, calculates the first derivative of the function, f, at each point r, including the boundary points, with the second-order accuracy (this can be done as a self-written MATLAB function). You can use any formula of O(h2) of your choice. (c) Calculates two measures of error defined as The first error is called the error in infinity norm (max stands for the maximum value among all the points), and the second error is called the error in L2 norm. Here f(i) is the true value of derivative at the given point Run your program with the number of intervals N equal to 8, 16, 32, 64 and document the E and El errors for each run. Plot EL versus N, in log-log plot, for both the O(h) and O(h2) derivatives on the same plot. Also, plot ELa versus N, in log-log plot, for both the O(h) and O(h2) derivatives (on the same plot, but different from ELerrors). Estimate the order of accuracy for each derivative from the two plots. Discuss if you obtain the expected order of convergence, for both error measures.Explanation / Answer
<div id="jqxgrid"></div>
Javascript:
// prepare the data
function format(input, format, sep) {
var output = "";
var idx = 0;
for (var i = 0; i < format.length && idx < input.length; i++) {
output += input.substr(idx, format[i]);
if (idx + format[i] < input.length) output += sep;
idx += format[i];
}
output += input.substr(idx);
return output;
}
var source =
{
datafields: [
{ name: 'CustomerID' },
{ name: 'CompanyName' },
{ name: 'ContactName' },
{ name: 'Indicator', type: 'string' },
{ name: 'Address' },
{ name: 'City' },
{ name: 'Country' }
],
localdata: [{ "CustomerID": "ALFKI", "CompanyName": "Alfreds Futterkiste", "ContactName": "Maria Anders", "Indicator": "11111111111"}, { "CustomerID": "ANATR", "CompanyName": "Ana Trujillo Emparedados y helados", "ContactName": "Ana Trujillo", "Indicator": "22222222222"}]
};
var local_length = source.localdata.length;
var dataAdapter = new $.jqx.dataAdapter(source);
var columnCheckBox = null;
var updatingCheckState = false;
$("#jqxgrid").jqxGrid(
{
width: 850,
height: 250,
source: dataAdapter,
columnsresize: true,
filterable: true,
sortable: true,
enabletooltips: true,
showfilterrow: true,
pageable: true,
enablebrowserselection: true,
pagesize: 5,
editmode: 'dblclick',
editable: true,
selectionmode: "singlerow",
autoheight: true,
altrows: true,
columns: [
{ text: 'Company Name', datafield: 'CompanyName', width: 250
},
{ text: 'Contact Name', datafield: 'ContactName', width: 150 },
{ text: 'Indicator', datafield: 'Indicator', width: 180, cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties, rowdata) {
var foo = value.toString().replace(/-/g, ""); // remove hyphens
// You may want to remove all non-digits here
// var foo = $(this).val().replace(/D/g, "");
var foo = format(foo, [5, 4, 2], "-");
var answer = foo;
return '<span>' + answer + '</span>';
}, createfilterwidget: function (column, columnElement, widget) {
widget.on('keydown', function (event) {
});
} },
{ text: 'City', datafield: 'City', width: 120 },
{ text: 'Country', datafield: 'Country'}
]
});
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.