{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw1sol

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

This preview shows pages 1–12. 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

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

View Full Document
%%%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)]);

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

View Full Document
%%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
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

{[ snackBarMessage ]}