% % this code implements formulas from Project 1. Problem 1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% format long n=10; % this implementes formula (1) x=2; for i=1:1:n x=sqrt(2-sqrt(4-x^2)); end x=x*(2^n); %% this line prints the result on the screen fprintf(1,'Computed: %13.12f Stored %13.12f Error: %13.12f \n \n', x,pi, abs(x-pi)); n=10; % this implementes formula (1) y=2; for i=0:1:n y=2*y/sqrt(2+sqrt(4-y^2/4^i)); end %% this line prints the result on the screen fprintf(1,'Computed: %13.12f Stored %13.12f Error: %13.12f \n \n', y, pi, abs(y-pi));