Question: % define the range nn = 2 0 ; % define the loop for calculation of error sum 1 = 0 ;sum 2 = 0

%define the range
nn=20;
% define the loop for calculation of error
sum1=0;sum2=0;
for ii=1:nn;
% formula 1 and 2 values
sum1=0;sum2=0
for jj=1:ii
sum1=sum1+(-1)^(jj-1)*4^(jj-1)/factorial(jj-1);
sum2=sum2+4^(jj-1)/factorial(jj-1);
end
f_1_val(ii)=sum1;
f_2_val(ii)=1/sum2;
% formula 1 and 2 true errors
e_t_1(ii)=abs(f_1_val(ii)-exp(-4))/exp(-4)*100;
e_t_2(ii)=abs(f_2_val(ii)-exp(-4))/exp(-4)*100;
end;
% formula 1 and 2 relative approxilate errors
e_a_1=[];
e_a_2=[];
e_a_1(1)=0;
e_a_2(1)=0;
for kk=2:nn;
e_a_1(kk)=abs(f_1_val(kk-1)-f_1_val(kk))/exp(-4)*100;
e_a_2(kk)=abs(f_2_val(kk-1)-f_2_val(kk))/exp(-4)*100;
end
T=table(f_1_val',e_t_1',e_a_1',f_2_val',e_t_2',e_a_2');
filename='C:\Users\user\Documents\MATLAB\rel_tru_error.xlsx';
writetable(T,filename,'sheet',1,'WriteVariableNames',false);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!