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