Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Suppose you are given a set of data points (Ij, yj) in the plane that describe a curve that is not a function of

image text in transcribedimage text in transcribedimage text in transcribed

4. Suppose you are given a set of data points (Ij, yj) in the plane that describe a curve that is not a function of r, and we want to interpolate the data. The basic idea is to think of the curve as parametrized by arclength 1: ((1), y()). Here we used to denote arclength in lieu of the typical s, since s was earlier used for slope (derivative) information. Thus the discrete data correspond to discrete values of arclength tj. That is, x; = x(;) and y; = y(1;). To determine ; we use the arclength of the piecewise linear interpolant. For example, the data (21,41) = (1,1) (22, y2) = (2, 2) (23, 93) = (1, 4) is viewed as corresponding to arclength values 11 = 0, 12 = 12, 13 = V2 + V5. Once we have determined the tj, we can fit a cubic spline through {(1;, X;)}}=1 and a second cubic spline through {(1;, y;)})=1, and then plot the resulting curve. An interesting example of the technique is the need to approximate curves for the automatic control of sewing machines. Consider the following data. x-[4.7 4.0 4.6 2.3 2.3 4.7 4.1 8.3 6.0 8.6 7.8 5.4 5.4 4.7); y-[1.3 1.9 2.5 3.1 3.9 3.1 5.8 5.8 3.0 2.9 2.0 2.4 1.5 1.3); Fit the data (as a function of arclength) by with two natural cubic splines and then plot (x(1), y()) as well as the data points. For this you will need the functions eval-pwpoly and pwchermite coeffs available on the web-site. N = % Evaluates piecewise polynomials. The vector x sections off % bins, each with a piecewise polynomial defined thereon. If length(x), then the matrix C is (N-1)-by-(P+1), where P % is the degree of the polynomial on each bin. Coefficients % in the matrix C are assumed to come from a Newton-like % basis which allows Horner's rule for evaluation. The Horner % geometric multiples for consecutive basis functions alternate % between (x-x_L) and (x-x_R). Polynomials are evaluated at X. % 20080214: Akil Narayan, rewrite 20101027 SRL % function[Y] = eval_pwpoly(x,c,x) function[Y] eval_pwpoly(x,C,X) Y = zeros(size()); N length(x); % Number of bins = N-1. if size(0,1)-=(N-1); % Argument check. error('# of rows of C must be equal to length(x)-1'); end if X(1) x(end) error('trying to extrapolate with piecewise polynomial'); end P = size(C,2)-1; % Polynomial order. [n bins] = histc(x,x); bins (bins==N) N-1; % histc is a little off, so correct. Y = for a C([bins], end); % Perform Horner evaluation: sideflag (mod(P,2)==1); % false = left, true = right. = 1:P; if sideflag; Y = Y.*(x-x(bins)) + C(bins, end-9); else Y = Y.*(X-x(bins+1)) + C(bins, end-a); end sideflag -sideflag; end % Calculates the piecewise-cubic Hermite interpolation % coefficients from the nodal data set (x,y,s). s are % the slope values at x. C is a 4-by-(length(x)-1) % matrix with the cubic coefficients corresponding to a Newton-type basis with alternating geometric % multiples of (x-x_L) and (x-x_R) as the Horner additions. % 20080214: acn rewrite 20101027 srl % function[C] pwchermite_coeffs (x,y,s); function[C] = pwchermite_coeffs(x,y,s); N = length(x); % Argument check if -((N==length(y))&(N==length(s))); error('Inputs x, y, and s must be of the same size'); end C = zeros([N-1 4]); % Allocate output inds dx = 1: (N-1); x(inds+1) % Precompute interval widths x(inds); C(:,1) y(inds); % Explicitly-calculated coefficients C(:,2) = (y(inds+1)-y(inds))./dx; C(:,3) = (C(:,2) - s(inds)). /dx; C(:,4) (s(inds+1) - C(:,2) C(:,3). *dx)./(dx.^2); = 4. Suppose you are given a set of data points (Ij, yj) in the plane that describe a curve that is not a function of r, and we want to interpolate the data. The basic idea is to think of the curve as parametrized by arclength 1: ((1), y()). Here we used to denote arclength in lieu of the typical s, since s was earlier used for slope (derivative) information. Thus the discrete data correspond to discrete values of arclength tj. That is, x; = x(;) and y; = y(1;). To determine ; we use the arclength of the piecewise linear interpolant. For example, the data (21,41) = (1,1) (22, y2) = (2, 2) (23, 93) = (1, 4) is viewed as corresponding to arclength values 11 = 0, 12 = 12, 13 = V2 + V5. Once we have determined the tj, we can fit a cubic spline through {(1;, X;)}}=1 and a second cubic spline through {(1;, y;)})=1, and then plot the resulting curve. An interesting example of the technique is the need to approximate curves for the automatic control of sewing machines. Consider the following data. x-[4.7 4.0 4.6 2.3 2.3 4.7 4.1 8.3 6.0 8.6 7.8 5.4 5.4 4.7); y-[1.3 1.9 2.5 3.1 3.9 3.1 5.8 5.8 3.0 2.9 2.0 2.4 1.5 1.3); Fit the data (as a function of arclength) by with two natural cubic splines and then plot (x(1), y()) as well as the data points. For this you will need the functions eval-pwpoly and pwchermite coeffs available on the web-site. N = % Evaluates piecewise polynomials. The vector x sections off % bins, each with a piecewise polynomial defined thereon. If length(x), then the matrix C is (N-1)-by-(P+1), where P % is the degree of the polynomial on each bin. Coefficients % in the matrix C are assumed to come from a Newton-like % basis which allows Horner's rule for evaluation. The Horner % geometric multiples for consecutive basis functions alternate % between (x-x_L) and (x-x_R). Polynomials are evaluated at X. % 20080214: Akil Narayan, rewrite 20101027 SRL % function[Y] = eval_pwpoly(x,c,x) function[Y] eval_pwpoly(x,C,X) Y = zeros(size()); N length(x); % Number of bins = N-1. if size(0,1)-=(N-1); % Argument check. error('# of rows of C must be equal to length(x)-1'); end if X(1) x(end) error('trying to extrapolate with piecewise polynomial'); end P = size(C,2)-1; % Polynomial order. [n bins] = histc(x,x); bins (bins==N) N-1; % histc is a little off, so correct. Y = for a C([bins], end); % Perform Horner evaluation: sideflag (mod(P,2)==1); % false = left, true = right. = 1:P; if sideflag; Y = Y.*(x-x(bins)) + C(bins, end-9); else Y = Y.*(X-x(bins+1)) + C(bins, end-a); end sideflag -sideflag; end % Calculates the piecewise-cubic Hermite interpolation % coefficients from the nodal data set (x,y,s). s are % the slope values at x. C is a 4-by-(length(x)-1) % matrix with the cubic coefficients corresponding to a Newton-type basis with alternating geometric % multiples of (x-x_L) and (x-x_R) as the Horner additions. % 20080214: acn rewrite 20101027 srl % function[C] pwchermite_coeffs (x,y,s); function[C] = pwchermite_coeffs(x,y,s); N = length(x); % Argument check if -((N==length(y))&(N==length(s))); error('Inputs x, y, and s must be of the same size'); end C = zeros([N-1 4]); % Allocate output inds dx = 1: (N-1); x(inds+1) % Precompute interval widths x(inds); C(:,1) y(inds); % Explicitly-calculated coefficients C(:,2) = (y(inds+1)-y(inds))./dx; C(:,3) = (C(:,2) - s(inds)). /dx; C(:,4) (s(inds+1) - C(:,2) C(:,3). *dx)./(dx.^2); =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Accounting

Authors: Donald E. Kieso, Jerry J. Weygandt, Terry D. Warfield

18th Edition

1119790972, 9781119790976

More Books

Students also viewed these Accounting questions

Question

What areas of knowledge do I have?

Answered: 1 week ago

Question

What are possible safety concerns? Explain.

Answered: 1 week ago

Question

What would you do if you were in Margarets shoes?

Answered: 1 week ago