check_hw1p2 - xs = sym(x,'f'); if nargin < 2 %...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% relerr = check_hw1p2(x,d) % % Compare cos(x^2)-cos(x) computed with MATLAB's variable precision % package in d digits worth of precision to the value computed by hw1p2, % and return the relative error. If d is not provided, use the default % precision (see the "digits" command). function [relerr, abserr] = check_hw1p2(x,d) % Convert the floating point value of x into % an exactly equivalent symbolic representation
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: xs = sym(x,'f'); if nargin < 2 % Default number of digits for var prec fv = vpa( cos(xs^2)-cos(xs) ); else % Specify number of digits fv = vpa( cos(xs^2)-cos(xs), d ); end fv = double(fv); % Compute with our routine f = hw1p2(x); % Compute the relative error and return relerr = abs( (fv-f)/fv ); abserr = abs((fv-f));...
View Full Document

This note was uploaded on 03/12/2012 for the course CS 3220 taught by Professor Marschner during the Spring '09 term at Cornell University (Engineering School).

Ask a homework question - tutors are online