Question

Write a computer program that takes as input a floating point number x in the interval...

Write a computer program that takes as input a floating point number x in the interval [−π, π], and an integer n in the range 1, 2, ..., 10, and calculates sin(x) using the Taylor series definition within an accuracy of 10−n . Indicate your programming language of choice, and include a screen shot of your test cases.

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

x=input('Enter a floating no between -pi and pi : ');
n=input('Enter an integer between 1 and 10 : ');
tol=10^-n;
sin_val=0;
i=0;
error=1;
while(error>tol)
nw_sin_val=sin_val;
sin_val=sin_val+(-1)^i*x^(2*i+1)/factorial(2*i+1);
i=i+1;
error=abs(nw_sin_val-sin_val);
end
disp('The Value of sin(x) is : ')
disp(vpa(sin_val))

Add a comment
Know the answer?
Add Answer to:
Write a computer program that takes as input a floating point number x in the interval...
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
  • Write in Python 3 Write a program that takes the value of an angle x in...

    Write in Python 3 Write a program that takes the value of an angle x in degrees, such that 0 s x <90, and calculates approximate value of sine of the given angel using the following series sin(x)-x-for all x The series given above has infinite number of terms. However, you can only include a finite number of terms in the series. The absolute value of each subsequent term is smaller than that of the term calculated before it. The...

  • 1.) (25 pts.) Write a MicroBlaze assembly language program that takes in a list of 10 integers an...

    1.) (25 pts.) Write a MicroBlaze assembly language program that takes in a list of 10 integers and calculates and displays the mean (average) using floating-point instructions. Include in your HW submission a complete listing of your assembly code. 1.) (25 pts.) Write a MicroBlaze assembly language program that takes in a list of 10 integers and calculates and displays the mean (average) using floating-point instructions. Include in your HW submission a complete listing of your assembly code.

  • Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four...

    Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four nonzero terms of the Taylor series for sin(x) with c=0. Your program should not use any arrays, the exponentiation operator or the factorial function. Print out your program and include the output upon execution for the special case where x = 1. How many nonzero terms of the above Taylor series are needed to guarantee that the sum approximates sin(x) to within .0001 for...

  • (Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points wit...

    (Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points with evenly spaced nodes from x1 = a to xm = b, and values from f(x); • location z satisfying x2 < z < xm−1, where h = (b − a)/(m − 1); and outputs the value of the interpolaton polynomial using only...

  • Program has to be in C# language Write a computer program that takes two sets (let...

    Program has to be in C# language Write a computer program that takes two sets (let the user determine the cardinality of each set and enter them manually) and calculates the following operations: Union Intersection Difference (set1 - set2) Cartesian product (set2 X set1) Check whether set2 is a subset of set1 or set1 is a subset of set2 Find the powerset of set1 and print out its elements and cardinality

  • USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number s...

    USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...

  • Write a C function called display_dollar which takes a floating point number as input, and displays...

    Write a C function called display_dollar which takes a floating point number as input, and displays this is a dollar value to the screen. This means that it should have a ‘$’ in front of it, and be displayed to exactly two decimal places in non-scientific form. Your function should not put spaces or newlines before or after the output?

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • a.) Write a C++ program that calculates the value of the series sin x and cos...

    a.) Write a C++ program that calculates the value of the series sin x and cos x, sin 2x or cos 2x where the user enters the value of x (in degrees) and n the number of terms in the series. For example, if n= 5, the program should calculate the sum of 5 terms in the series for a given values of x. The program should use switch statements to determine the choice sin x AND cos x, sin...

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

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
ADVERTISEMENT