{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw4s - CME302 Homework 4 Computer Exercise Solutions A.M.B...

This preview shows pages 1–9. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CME302 Homework 4 Computer Exercise Solutions A.M.B. October 15, 2009 (T&B 13.3) Figure 1 plots the results of three methods of evaluating the poly- nomial. First, for illustrative purposes, I use a bad method: using pow (implemented in Matlab as .^ ) to evaluate the powers x n individually, multiplying by the polynomial coefficient, and summing. This method is inefficient and incurs more numerical error than the next. Over the domain of interest, the variance of its error is approximately four times that of the next method, Horner’s scheme. Horner’s scheme is based on the following idea: ax 2 + bx + c = ( ax + b ) x + c. Hence one can first compute f ax + b and then compute f fx + c . The code used in this exercise follows: function p13p3 % Set up problem c = [1 -18 144 -672 2016 -4032,... 5376 -4608 2304 -512]; nc = length(c); x = 1.920:.001:2.08; nx = length(x); p = zeros(3,nx); % Use pow: bad idea for(i = 0:nc-1) p(1,:) = p(1,:) + c(nc-i)*x.^i; end % Horner’s method: good idea in general case p(2,:) = c(1); for(i = 2:length(c)) p(2,:) = p(2,:).*x + c(i); end % (x - 2)^9 p(3,:) = (x - 2).^9; % Plot % omitted % Variance of pow and Horner fprintf(1,’%e %e\n’,...
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

hw4s - CME302 Homework 4 Computer Exercise Solutions A.M.B...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online