Question

Calculate ? using the approximation n! n ! is the factorial: n!-1 × 2 × 3 × × n. |1×3 x-..×n, nis odd n!! is the semifactorial: n!!-12 x 4 x x n, n is even not to be confused with (n!)!, 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 × 3 × 5 × 7 = 105, and 8!! 2 x 4 x 6 x 8-384. MATLAB has a built-in factorial function, but you are required to write the semifactorial function yourself. The sum given above goes to infinity. Your MATLAB function should take a single input argument which specifies how many terms of the summation should be computed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of code

Output

Code to Copy

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp('Input n')

n = input()

res = 0;

% calculate the product

for k= 1:n

f =(factorial1(k)/factorial2(2*k+1));

res = res+f;

end

res = 2*(1+res)

function fact = factorial1(num1)

fact = 1;

% calculate the factrial of num1

for i= 1:num1

fact = fact* i;

end

end

function fact1 = factorial2(num2)

fact1 = 1;

j=num2;

k=num2;

%calculate semifactorial of num2

for i= 1:ceil(num2/2)

% if num2 is even then compute 4*2..

if mod(num2,2)==0

fact1 = fact1*j;

j = j-2;

else

% fi num2 is odd then compute 7*5*3*1..

fact1 = fact1*k;

k = k-2;

end

end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Calculate ? using the approximation n! n ! is the factorial: n!-1 × 2 × 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT