In: Computer Science
Using MATLAB: 22/7 is a commonly used fraction that estimates pi. Unfortunately it is not very
accurate. Using a maximum of three digits in the numerator and denominator, find
the fraction that is the closest approximation to pi. Have the computer output the
numerator, denominator, and the true percent error
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
clear, clc
num=1;
den=1;
min=10;
for i=1:1000
for j=1:1000
if(abs(i/j-pi)<min)
min=abs(i/j-pi);
num=i;
den=j;
end
end
end
fprintf('Fraction is %d/%d, true percent
error=%.4e\n',num,den,abs(num/den-pi)/pi*100)
Kindly revert for any queries
Thanks.