2. Calculate using the approximation 0o n! 2 +1 n=0 n! is the factorial: n! = 1
ID: 3585312 • Letter: 2
Question
2. Calculate using the approximation 0o n! 2 +1 n=0 n! is the factorial: n! = 1 × 2 × 3 × × n. n!! is the ser ifactorial: n!! ={2x3x xin nisoden not to be confused with (n!)! 2×4×.. × n, nis even, which is the factorial function iterated twice. The semifactorial of n is the product of the integers between 1 and n which have the same parity (even or odd) as n. For example, 7!! = 1 X3x5x7-105, and 8!!-2x4x6x8-384. MATLAB has a built-in factorial function, but you will need to write the semifactorial function yourself. The sum given above goes to infinity. Your MATLAB function should takc a singlc input argument which specifies how many terms of the summation should be computed.Explanation / Answer
function semi = semifactorial(n)
semi = 1;
while n > 0
semi = semi*n;
n = n-2;
end
end
function cPi = calculatePie(n)
cPi = 0;
for i = 0:n
cPi = cPi + factorial(i)/semifactorial(2*i + 1);
end
cPi = cPi*2;
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.