Question

An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+ Create a function named sin_taylor in MATLAB. This function takes two inputs. First input is the angle, and the second input determines the number of terms in Taylor series for approximation. Check the fidelity of your function by running sin-taylor( 7) and compare it with the exact value of it. Hint: “factorial is a built-in function that you can use for calculating factorial of an integer number. Use MATLAB documentation to find more about it. 3! 5!7!

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

---------------------------------------------sin_taylor.m-----------------------------------------

function [ans] = sin_taylor(x, n)

    ans = 0;

   

   

   

    for i = 1 : n

       

        % if the term is an even term

        if mod(i, 2) == 0

           

            ans = ans - ( x ^ ( 2 * i - 1 ) ) / factorial( 2 * i - 1 );

           

        % if the term is an odd term

        else

           

            ans = ans + ( x ^ ( 2 * i - 1 ) ) / factorial( 2 * i - 1 );

           

        end

       

    end

end

-----------------------------------------main.m---------------------------------------------

sin_x = sin_taylor(pi / 6 , 7);

disp(sin_x);

Sample Output:

0.5000

Add a comment
Know the answer?
Add Answer to:
An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+...
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
  • 8. The Maclaurin series (a special case of the Taylor series that is discussed later in...

    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...

  • Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+...

    Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o E- (-1) . 2n +1 no (2n+1)! !57 where x is in radians. Write a MATLAB program that determines sin(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a while loop for adding the terms of the Taylor series. If an n is the nth term in...

  • Use substitution to find the Taylor series at x = 0 of the function 16 sin(-x)....

    Use substitution to find the Taylor series at x = 0 of the function 16 sin(-x). What is the general expression for the nth term in the Taylor series at x = 0 for 16 sin (-x)? 00 (Type an exact answer.) no

  • MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value...

    MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value with the matlab built-in function for cos). How many iterations does it take to get to 4- decimal place agreement? (hint: help factorial) 2! 4! 6!

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    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...

  • This is the given code: /** * This program uses a Taylor Series to compute a...

    This is the given code: /** * This program uses a Taylor Series to compute a value * of sine. * */ #include<stdlib.h> #include<stdio.h> #include<math.h> /** * A function to compute the factorial function, n!. */ long factorial(int n) { long result = 1, i; for(i=2; i<=n; i++) { result *= i; } return result; } int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: %s x n ", argv[0]); exit(1); } double x = atof(argv[1]); int...

  • Use power series operations to find the Taylor series at x = 0 for the following...

    Use power series operations to find the Taylor series at x = 0 for the following function. 9xex The Taylor series for e* is a commonly known series. What is the Taylor series at x = 0 for e? 00 Σ (Type an exact answer.) n=0 नि

  • 1. (A) Use the Taylor series expansion for the sin x to estimate sin(t/4) for the...

    1. (A) Use the Taylor series expansion for the sin x to estimate sin(t/4) for the acceptable relative errors of 0.25 and 0.0025 .5 3 9 х* sin x x 3! х> 5! 7! 9! Please use the table formatting u to solve the problem

  • The Taylor polynomial approximation pn (r) for f(x) = sin(x) around x,-0 is given as follows: TL ...

    The Taylor polynomial approximation pn (r) for f(x) = sin(x) around x,-0 is given as follows: TL 2k 1)! Write a MATLAB function taylor sin.m to approximate the sine function. The function should have the following header: function [p] = taylor-sin(x, n) where x is the input vector, scalar n indicates the order of the Taylor polynomials, and output vector p has the values of the polynomial. Remember to give the function a description and call format. in your script,...

  • 2. Use the definition of Taylor series to find the Taylor series of f(x)=sin(2x), centered at...

    2. Use the definition of Taylor series to find the Taylor series of f(x)=sin(2x), centered at ca. You need not write your answer in summation notation, but you do need to list at least 4 nonzero terms. 4

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