Graphics Programs Reference
In-Depth Information
EXAMPLE 3.7
Write aprogram that interpolates between givendatapoints with the naturalcubic
spline. The programmust be able to evaluate the interpolantformorethan one value
of x .As a test, use datapoints specified in Example 3.4 and compute the interpolant
at x
=
1
.
5 and x
=
4
.
5 (duetosymmetry, these values shouldbeequal).
Solution The program belowprompts for x ;it isterminatedbypressing the “return”
key.
% Example 3.7 (Cubic spline)
xData = [1; 2; 3; 4; 5];
yData = [0; 1; 0; 1; 0];
k = splineCurv(xData,yData);
while 1
x = input('x = ');
if isempty(x)
fprintf('Done'); break
end
y = splineEval(xData,yData,k,x)
fprintf('\n')
end
Running the program produces the following results:
x=1.5
y=
0.7679
x=4.5
y=
0.7679
x=
Done
PROBLEM SET 3.1
1.
Given the datapoints
x
1
.
2
0
.
3
1
.
1
y
5
.
76
5
.
61
3
.
69
determine y at x
=
0 using (a)Neville's method and (b) Lagrange's method.
Search WWH ::




Custom Search