# #6 (40 points). In this problem, you will implement a code for the ...

## Transcribed Text

#6 (40 points). In this problem, you will implement a code for the natural cubic spline interpolation of the data obtained from 1 f(x) = defined on [-1,1]. - 1 + 25 x² Let n be a positive integer and consider uniform nodal points x. = i.h - 1, h = 2/n (0 < i < n) a. Produce data b. Produce the corresponding tridiagonal matrix (for the computation of zi) which is saved in a matrix of dimension (n - 1) X (n - 1) or (n - 1) x 3. (See page 16 of Section 1.3 (Review of Linear Algebra).) C. Construct the corresponding right-hand side. d. Solve the linear system by either using a build-in function or composing a function for Gaussian elimination. e. Print out the quantities Z (0 i n ) for n = 5 and n = 10. f. Construct your spline function, for n = 8 to draw the figure. Attach your code along with the results.

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[    43447,       1038]
NotebookOptionsPosition[    42282,       1011]
NotebookOutlinePosition[    42625,       1026]
CellTagsIndexPosition[    42582,       1023]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"f", "[", "x_", "]"}], ":=",
RowBox[{"1", "/",
RowBox[{"(",
RowBox[{"1", "+",
RowBox[{"25",
SuperscriptBox["x", "2"]}]}], ")"}]}]}], ";"}]], "Input",
CellChangeTimes->{{3.8022915178323207`*^9, 3.8022915288400373`*^9}},

Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{
RowBox[{"CS", "[",
RowBox[{"n_", ",", "t_"}], "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
"h", ",", "x", ",", "L", ",", "A", ",", "rhs", ",", "i", ",", "z", ",",
"c", ",", "d", ",", "s"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{
RowBox[{"h", "=",
RowBox[{"2", "/", "n"}]}], ";", "\[IndentingNewLine]",
RowBox[{"x", "=",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{"i", "*", "h"}], "-", "1"}], ",",
RowBox[{"{",
RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"L", "=",
RowBox[{"Table", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"x", "[",
RowBox[{"[", "i", "]"}], "]"}], ",",
RowBox[{"f", "[",
RowBox[{"x", "[",
RowBox[{"[", "i", "]"}], "]"}], "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",",
RowBox[{"n", "+", "1"}]}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"TableForm", "[", "L", "]"}], ";", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{"A", "=",
RowBox[{"Normal", "[",
RowBox[{"SparseArray", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{
RowBox[{"Band", "[",
RowBox[{"{",
RowBox[{"1", ",", "1"}], "}"}], "]"}], "\[Rule]",
RowBox[{"2",
RowBox[{"h", "/", "3"}]}]}], ",",
RowBox[{
RowBox[{"Band", "[",
RowBox[{"{",
RowBox[{"1", ",", "2"}], "}"}], "]"}], "\[Rule]",
RowBox[{"h", "/", "6"}]}], ",",
RowBox[{
RowBox[{"Band", "[",
RowBox[{"{",
RowBox[{"2", ",", "1"}], "}"}], "]"}], "\[Rule]",
RowBox[{"h", "/", "6"}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"n", "-", "1"}], ",",
RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"rhs", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"f", "[",
RowBox[{"x", "[",
RowBox[{"[",
RowBox[{"i", "+", "2"}], "]"}], "]"}], "]"}], "+",
RowBox[{"f", "[",
RowBox[{"x", "[",
RowBox[{"[", "i", "]"}], "]"}], "]"}], "-",
RowBox[{"2",
RowBox[{"f", "[",
RowBox[{"x", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}], "]"}]}]}], ")"}], "/",
"h"}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",",
RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]", "\[IndentingNewLine]",
RowBox[{"z", "=",
RowBox[{"LinearSolve", "[",
RowBox[{"A", ",", "rhs"}], "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"z", " ", "=",
RowBox[{
RowBox[{"{", "0", "}"}], "~", "Join", "~", "z", "~", "Join", "~",
RowBox[{"{", "0", "}"}]}]}], ";", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{"c", "=",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"L", "[",
RowBox[{"[",
RowBox[{
RowBox[{"i", "+", "1"}], ",", "2"}], "]"}], "]"}], "/", "h"}],
"-",
RowBox[{
RowBox[{"z", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}], "*",
RowBox[{"h", "/", "6"}]}]}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"d", "=",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"-",
RowBox[{"L", "[",
RowBox[{"[",
RowBox[{"i", ",", "2"}], "]"}], "]"}]}], "/", "h"}], "+",
RowBox[{
RowBox[{"z", "[",
RowBox[{"[", "i", "]"}], "]"}], "*",
RowBox[{"h", "/", "6"}]}]}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"s", "=",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{
RowBox[{
SuperscriptBox[
RowBox[{"(",
RowBox[{"t", "-",
RowBox[{"x", "[",
RowBox[{"[", "i", "]"}], "]"}]}], ")"}], "3"], "/",
RowBox[{"(",
RowBox[{"6", "h"}], ")"}]}], "*",
RowBox[{"z", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}]}], "-",
RowBox[{
RowBox[{
SuperscriptBox[
RowBox[{"(",
RowBox[{"t", "-",
RowBox[{"x", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}]}], ")"}], "3"], "/",
RowBox[{"(",
RowBox[{"6", "h"}], ")"}]}], "*",
RowBox[{"z", "[",
RowBox[{"[", "i", "]"}], "]"}]}], "+",
RowBox[{
RowBox[{"c", "[",
RowBox[{"[", "i", "]"}], "]"}], "*",
RowBox[{"(",
RowBox[{"t", "-",
RowBox[{"x", "[",
RowBox[{"[", "i", "]"}], "]"}]}], ")"}]}], "+",
RowBox[{
RowBox[{"d", "[",
RowBox[{"[", "i", "]"}], "]"}], "*",
RowBox[{"(",
RowBox[{"t", "-",
RowBox[{"x", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}]}], ")"}]}]}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"Return", "[",
RowBox[{"{",
RowBox[{"z", ",", "s", ",", "L"}], "}"}], "]"}], ";"}]}],
"\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]"}]], "Input",
CellChangeTimes->{{3.802291530049346*^9, 3.8022915300623384`*^9}, {
3.802291560319058*^9, 3.802291602458931*^9}, {3.802292025462988*^9,
3.80229203316458*^9}, {3.802292104641263*^9, 3.802292179862895*^9}, {
3.8022922142756877`*^9, 3.802292342100909*^9}, {3.802292387653862*^9,
3.8022923949166884`*^9}, {3.802292473444751*^9, 3.8022926573046837`*^9}, {
3.802292887435566*^9, 3.8022930077495184`*^9}, {3.8022930396172915`*^9,
3.802293041318147*^9}, {3.802293092516841*^9, 3.802293093871069*^9}, {
3.802293215367982*^9, 3.802293274009925*^9}, {3.8022933509389067`*^9,
3.8022933531856174`*^9}, {3.802293460977957*^9, 3.802293474149419*^9}, {
3.802293580432829*^9, 3.802293581316324*^9}},
CellLabel->
"In[141]:=",ExpressionUUID->"39e0544f-7073-4850-8a55-89a7f31ee92a"],

Cell[CellGroupData[{

Cell[BoxData[
RowBox[{"CS", "[",
RowBox[{"5", ",", "t"}], "]"}]], "Input",
CellChangeTimes->{{3.8022933424167814`*^9, 3.8022933554433255`*^9}},
CellLabel->

Cell[BoxData[
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"0", ",",
FractionBox["1020", "247"], ",",
RowBox[{"-",
FractionBox["945", "247"]}], ",",
RowBox[{"-",
FractionBox["945", "247"]}], ",",
FractionBox["1020", "247"], ",", "0"}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"-",
FractionBox["5", "52"]}], " ",...

By purchasing this solution you'll be able to access the following files:
Solution.nb.

\$30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Numerical Analysis Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.