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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Calculate ? using the approximation n! n ! is the factorial: n!-1 × 2 × 3...
Written in expanded form, the usual factorial function is n! = n middot (n - 1) middot (n - 2) ... 3 middot 2 middot 2 middot 1. The difference between elements in the product is always 1. It can be writ in recursive form as n! = n middot (n - 1)! (e.g., 10! = 10 middot 9!, 23! * 23 middot 22!, 4! = 4 3!, etc.). The purpose of this problem is to generalize the factorial function...
Special Problem: Automated Factorial Create a MATLAB function called xfact that uses a loop to calculate the factorial of an integer. Your function should take a single integer input. Your function should compute the factorials of every integer from 1 to the integer provided by the input. Test your function by prompting the user to enter an integer N and, using a loop create an array named X of length N that contains the factorials of the numbers 1 to...
Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...
Convince yourself that the Maclaurin Series for cos(x) is:
A. Write a function script called cos_series
that takes that takes as its inputs, x and N and has output given
by the sum in the N-term Maclaurin Series approximation for Cos(x).
Hint: try a “for loop” and set “format long” in
your code. You may use the MATLAB built-in function factorial()
B. Check your code by finding the 2-terms,
3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series
approximations every 30 degrees...
Problem 5. Consider least squares polynomial approximation to f(x) = cos (nx) on x E [-1,1] using the inner product 1. In finding coefficients you will need to compute the integral By symmetry, an 0 for odd n, so we need only consider even n. (a) Make a change of variables and use appropriate identities to transform the integral for a to cos (Bcos 8)cos (ne) de (b) The Bessel function of even order, (x), can be defined by the...
In C++ using the while loop..
Compute factorial of a number Factorial of n = 1*2*3 *n 702
Which is the best approximation of the summation 1 + 1/2 + 1/3 + ... + 1/n obtained during our analysis of the average case of Quick Sort (and BST)? A Θ(log log n) B Θ(log n) C Θ(n) D Θ(n log n) E Θ(1/n!) F Θ(n!)
For the function y 1-x for 0 s x s 1 Graph the function's 3 periods 1) Find its formulas for the Fourier series and Fourier coefficients 2) Write out the first three non-zero terms of the Fourier Series 3) 4) Graph the even extension of the function 5) Find the Fourier series and Fourier coefficients for the even extension 6) Write out the first three non-zero terms of the even Fourier series 7) Graph the odd extension of the...
USING PYTHON PLEASE
Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...
8. The Maclaurin series (a special case of the Taylor series that is discussed later in this class) allows us to express a differentiable, analytic function as an infinite degree polynomial. Here is the degree seven polynomial approximation of the sine: x3 x5 x? 3! 5! 7! + Use Matlab to generate a plot of sin(x) (solid blue line) and its polynomial approximation (dashed red line) for x = 0 to 31/2 and y from -1.5 to 2. Use the...