Question

In: Computer Science

Using MATLAB: 22/7 is a commonly used fraction that estimates pi. Unfortunately it is not very...

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

Solutions

Expert Solution

`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.


Related Solutions

Write a matlab program that determines the value of pi using the monte carlo technique. do...
Write a matlab program that determines the value of pi using the monte carlo technique. do this for a loop of multiple fixed points. (i.e 100-10000) Plot the computed value of pi and the difference from the true value as this number increases. Time the execution of your code for various numbers of points, and plot the precision vs the computational cost.
b) Methoxide ion, CH3O , and amide ion, NH2 , are very strong bases commonly used...
b) Methoxide ion, CH3O , and amide ion, NH2 , are very strong bases commonly used in organic solvents. However, both bases are
The most commonly used gadget that you should know of is a ding-dong doorbell using an...
The most commonly used gadget that you should know of is a ding-dong doorbell using an electromagnet. In order to make a door bell, please answer the following questions: List the items needed to make a door bell using common household stuff. Draw its labeled schematics, and explain its working principle Which Maxwell’s equation will you use to design the doorbell actuation Describe two ways to make the bell sound loud. List five commercial uses of electromagnets other than doorbell.
Pick 7 commonly used medications for the nervous system Know pediatric dose indication for example Amoxicillin...
Pick 7 commonly used medications for the nervous system Know pediatric dose indication for example Amoxicillin Pregnancy category/what would be side-effects if given to a pregnant woman. List the adverse or serious effects. You will do this for each of the medication Olympic assignments.
Identify the different types of plans commonly used in the business context. Using examples from any...
Identify the different types of plans commonly used in the business context. Using examples from any published news sources, when each type of plan be most effective to use? 250 or less
MIS445- Discussion Topic: Confidence intervals and p-values are commonly used in business decision making. Using the...
MIS445- Discussion Topic: Confidence intervals and p-values are commonly used in business decision making. Using the CSU-Global Library, identify at least two business journals (or articles) that have used confidence intervals and/or p-values. For each journal (or article), describe: the problem statement the parameter(s) of interest the conclusion and/or decision.   In addition, state the sample size. If they are using a confidence interval, state the confidence level and margin of error. If they are using the p-value, state the hypotheses,...
Discrete math 1) Using MatLab (any language is fine just say what language is used). function...
Discrete math 1) Using MatLab (any language is fine just say what language is used). function d=lemma_gcd(a,b) %This program will return the greatest common divisor for input variables a %and b where a and b are integers such that they are not both 0. It uses %Lemma 4.8.3 on page 225. %Note: gcd(a,b)=gcd(-a,b)=gcd(a,-b)=gcd(-a,-b), so a=abs(a); b=abs(b); %This following section sets up the arrays we will use to store the %changing values of our variables as a sequence. "c" will be...
USING MATLAB.... a.) Create anonymous functions: fa(x)=sin(x^2) fb(x)=sin^2(x) b.) Evaluate them both at x=1/2 pi c.)Evaluate...
USING MATLAB.... a.) Create anonymous functions: fa(x)=sin(x^2) fb(x)=sin^2(x) b.) Evaluate them both at x=1/2 pi c.)Evaluate them both at x=(0,1,2,...,10)^T d.) Calculate fa(fb(2)) and fb(fa(2))
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT