Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a function named fact to calculate the factorial of a number. 2)The inf

ID: 3553541 • Letter: 1

Question

1)Write a function named fact to calculate the factorial of a number.

2)The infinite Maclaurin series to calculate the sine of an angle in radians is:

   (sin(x) = x-x^{3}/3! + x^{5}/5!+x^{7}/7!+x^{9}/9!- . ....)   

Write a function, named sine, to calculate the sine of an angle using the above Maclaurin series. Use your fact function from problem 1 in your sine function. Iterate the terms until the difference between the previous term and the current term is less than 10-5. Write a program that asks for an angle to be input, passes that angle to the sine function, and displays the result to five decimal places as:

The sine of ____ is ______.

If 0.3 is entered as the angle, the result would be:

The sine of 0.30000 is 0.29552.

*Full all points please answer both question, please, and Thank You!

Explanation / Answer

One way of testing if an input value is to test whether it's equal to its floor function, floor(x).
Here's my function:

function [y] = fact(x)
y = 1;

if x < 0
y = 'Input must not be negative!';
elseif x ~= floor(x)
y = 'Input must be an integer!';
elseif x == 0
y = 1;
else
for i = 1: x
y = i*y;
end
end

return



2)

The trigonometric function sin(x) can be approximated by the infinite series sin(x) = x^1/1!