---------------------------------------------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
An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+...
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+ = 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). 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 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_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 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 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 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 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 ca. You need not write your answer in summation notation, but you do need to list at least 4 nonzero terms. 4