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

Write a program that declares two variables: x is the value of the argument h is

ID: 3735134 • Letter: W

Question

Write a program that declares two variables:

x is the value of the argument

h is the accuracy that you want

test the program with

x= 1; h= .00001

print out the approximation using as many terms of the Maclaurin series that you need, but no more than that, to get within the required accuracy

while you are at it you might as well also print out Sine(x) BUT do not use the value of Sin(X) to determine the accuracy of the approximation.

I wrote a program but cant figure out why its not running. Can someone please help me.

<html><script>
x = 1; h = 0.00001;
function factorial(n) {
if (n === 0) {
return 1
return n*factorial(n-1)}
sum=0;
term=x;
terms=0;
while (terms < 99 && Math.abs(term) > h)
term = (-1)*((n-1)/2)*(x*(n)/factorial(n) {terms=terms+1;
sum=sum+term;}
</script></html>

Explanation / Answer

After made some modifications in code. It working fine for me. Please find the below code.

<html>
<p id="demo"></p>
<script>
var x = 1; var h = 0.00001;
function factorial(n) {
if (n === 0) {
return 1
return n*factorial(n-1)}
var sum=0;
var term=x;
var terms=0;
while (terms < 99 && Math.abs(term) > h)
term = (-1)*((n-1)/2)*(x*(n)/factorial(n))
terms=terms+1;
sum=sum+term;
}
document.getElementById("demo").innerHTML = factorial(0);
console.log(factorial(0));
</script>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote