Question: Using MATLAB: %%%%%%%%%%%%%%%%%%%%% compute spline coefficients here %%%%%%%%%%%%%%% format long e %%%%%%%%%%%%%%%%%% call sineval function here %%%%%%%%%%%%%%%%% X = 250; sineval(X,a,b,c) X = -100; sineval(X,a,b,c)

Using MATLAB:

Using MATLAB: %%%%%%%%%%%%%%%%%%%%% compute spline coefficients here %%%%%%%%%%%%%%% format long e %%%%%%%%%%%%%%%%%%call sineval function here %%%%%%%%%%%%%%%%% X = 250; sineval(X,a,b,c) X = -100;

%%%%%%%%%%%%%%%%%%%%% compute spline coefficients here %%%%%%%%%%%%%%%

format long e

%%%%%%%%%%%%%%%%%% call sineval function here %%%%%%%%%%%%%%%%%

X = 250;

sineval(X,a,b,c)

X = -100;

sineval(X,a,b,c)

%%%%%%%%%%%%%%%%%%%%% plot spline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%number of points on which to plot. n = number of nodes

nplot = (n-1)*19+1;

xplot = zeros(nplot,1);

yplot = zeros(nplot,1);

%spacing between plot points

nspace = (x(n)-x(1))/(nplot-1);

k = 0;

for i = 1:n-1

for j = 1:19

k = k+1;

xplot(k) = x(i) + (j-1)*nspace;

yplot(k) = a(i) + b(i)*(xplot(k) - x(i)) + c(i)*(xplot(k) - x(i))^2;

end

end

xplot(nplot) = x(n);

yplot(nplot) = a(i) + b(i)*(x(n) - x(n-1)) + c(i)*(x(n) - x(n-1))^2;

plot(xplot,yplot)

figure

abserr = abs(yplot - sin(xplot));

plot(xplot,abserr)

function [y] = forsub(L,b)

%Forward-substitution

%accepts an nX1 vector b, an nXn lower triangular matrix L

%generates an nX1 solution vector y

n = size(b,1);

y = zeros(n,1);

y(1) = b(1);

for i = 2:n

y(i) = b(i);

for j = 1:i-1

y(i) = y(i) - L(i,j)*y(j);

end

end

In this exercise, you will be writing your own function, sineval, which will use a quadratic spline to compute approximations for the sine function at any real number. You are to compute the quadratic spline S(x) using evenly-spaced nodes x,,x..x, where 4.1-x. = for k = 1,2, , n-1 , and whose derivative is specified at x-The numbers yy are the corresponding function values to be interpolated. On each interval [x,x, S(x) =5,(x) = a, th(x-%)+6(x-x,), k=1,2, ,n-1 After applying the interpolation conditions, one obtains a.-y. ; k=12, , n-1 (1) and After applying the smoothness conditions, one obtains If S (x)v (derivative is specified to be v), then one obtains a=v, (4). In this exercise, you will be writing your own function, sineval, which will use a quadratic spline to compute approximations for the sine function at any real number. You are to compute the quadratic spline S(x) using evenly-spaced nodes x,,x..x, where 4.1-x. = for k = 1,2, , n-1 , and whose derivative is specified at x-The numbers yy are the corresponding function values to be interpolated. On each interval [x,x, S(x) =5,(x) = a, th(x-%)+6(x-x,), k=1,2, ,n-1 After applying the interpolation conditions, one obtains a.-y. ; k=12, , n-1 (1) and After applying the smoothness conditions, one obtains If S (x)v (derivative is specified to be v), then one obtains a=v, (4)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!