hw1sol

hw1sol - accuracy N = input('Your input N is beyond machine...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
%%%problem 5 clear all; maxtotal = 5280; % maximum sum total = 0; for ii=1:99 total = total + ii^2; % sum of squares if(total> maxtotal) % sum is greater than max sum, exit the loop break; end end % display the number of n's and its sum disp(['Value of n is : ' num2str(ii)]); disp(['Sum of n values is : ' num2str(total)]);
Background image of page 11

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

View Full DocumentRight Arrow Icon
%%problem 6 function [terms,approximation] = add_sine_terms(x,N) %this fucntion adds successive terms of the Taylor series of sine untill a %required level of accuracy is achieved. %Input: % x: is the number of radian whose sine is to be found(in the prob, it is 1.5) % N : required significant figures) %output: % terms: no. of terms added %approx: actual approx to the sine value Tol = 10^(-N); % required error while(1) if(Tol < eps) % check if the required error is less than machine
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: accuracy N = input('Your input N is beyond machine accuracy.Enter lesser N : '); Tol = 10^(-N); % new required error break; else % if req. error is more eps, break the loop break; end end approx_old = x; %first term of sine series is set as initial value %add the remaining additional terms for n=2:1000 approx_new = approx_old + ((-1)^(n+1))*(x^(2*n-1))/factorial(2*n-1); RE = abs((approx_new-approx_old)/approx_old) ;% relative error if(RE <= Tol) % if the required tolerance is met, break break; end approx_old = approx_new; end %number of terms & final approximation terms = n; approximation = approx_new; disp(['Number of terms added : ' num2str(terms)]); disp(['Final approximation is : ' num2str(approximation,15)]); disp(['Relative error is : ' num2str(RE,15)]);...
View Full Document

This homework help was uploaded on 04/07/2008 for the course ME 17 taught by Professor Milstein during the Spring '07 term at UCSB.

Page1 / 12

hw1sol - accuracy N = input('Your input N is beyond machine...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online