Matlab Code:
Problem 5:
% MATLAB Program that calculates Taylor series expansion of sin(x)
clc;
clear;
% Reading angle in degrees
angleDegrees = input("Enter angle in degress: ");
% Converting angle in to radians
angleRadians = (0.0174533) * angleDegrees;
% Initially assign value 1
EstError = 1;
% Variable n for series
n = 0;
% Assign 0 to series sum
SNew = 0;
SOld = 0;
% Iterate till E > 1E-8
while EstError > (1e-8)
% Calculating term
term = ( ((-1)^n) / (factorial((2*n) + 1)) ) * (
angleRadians ^ ((2*n) + 1) );
% Adding term
if n == 0
SOld = term; % Updating SOld
EstError = abs((SNew - SOld)/SOld);
% Calculating E
else
SNew = SOld + term; % CAdding term
to series
EstError = abs((SNew - SOld)/SOld);
% Calculating E
SOld = SNew; % Updating SOld
value
end
% Updating n value
n = n + 1;
end % End of while
% Printing resultant values
fprintf("\n The sin of %.2f is %.8f, providing an error equal to
%.2e \n", angleDegrees, SOld, EstError);
Sample Run:
________________________________________________________________________________________________
Problem 6:
% MATLAB Program that calculates Taylor series expansion of sin(x)
clc;
clear;
% Reading angle in degrees
angleDegrees = input("Enter angle in degress: ");
% Converting angle in to radians
angleRadians = (0.0174533) * angleDegrees;
% Initially assign value 1
EstError = 1;
% Assign 0 to series sum
SNew = 0;
SOld = 0;
% Iterate for loop from 1 to 15
for n=0:14
% Calculating term
term = ( ((-1)^n) / (factorial((2*n) + 1)) ) * (
angleRadians ^ ((2*n) + 1) );
% Adding term
if n == 0
SOld = term; % Updating SOld
EstError = abs((SNew - SOld)/SOld);
% Calculating E
else
SNew = SOld + term; % CAdding term
to series
EstError = abs((SNew - SOld)/SOld);
% Calculating E
SOld = SNew; % Updating SOld
value
end
end % End of while
% Printing resultant values
fprintf("\n The sin of %.2f is %.8f, providing an error equal to
%.2e \n", angleDegrees, SOld, EstError);
Sample Run:
_________________________________________________________________________________________
Problem 8:
function result = sinSeries_8(angleDegrees)
#MATLAB function that reads angle in degrees and
then calculates and returns value of sin(x)
% Reading user choice
ch = input("\n 1 - For Loop \t 2 - While Loop \t
Your Choice: ");
% Converting angle in to radians
angleRadians = (0.0174533) * angleDegrees;
% Initially assign value 1
EstError = 1;
% Variable n for series
n = 0;
% Assign 0 to series sum
SNew = 0;
SOld = 0;
% Using for loop
if ch == 1
% Iterate for loop from
1 to 15
for n=0:14
% Calculating term
term = ( ((-1)^n) / (factorial((2*n) + 1)) ) * ( angleRadians ^
((2*n) + 1) );
% Adding term
if n == 0
SOld = term; % Updating SOld
EstError = abs((SNew - SOld)/SOld); % Calculating E
else
SNew = SOld + term; % CAdding term to series
EstError = abs((SNew - SOld)/SOld); % Calculating E
SOld = SNew; % Updating SOld value
end
end % End of while
% Printing resultant
values
fprintf("\n The sin of
%.2f is %.8f using for loop, which provides an error equal to %.2e
\n", angleDegrees, SOld, EstError);
% Using while loop
else
% Iterate till E >
1E-8
while EstError >
(1e-8)
% Calculating term
term = ( ((-1)^n) / (factorial((2*n) + 1)) ) * ( angleRadians ^
((2*n) + 1) );
% Adding term
if n == 0
SOld = term; % Updating SOld
EstError = abs((SNew - SOld)/SOld); % Calculating E
else
SNew = SOld + term; % CAdding term to series
EstError = abs((SNew - SOld)/SOld); % Calculating E
SOld = SNew; % Updating SOld value
end
% Updating n value
n = n + 1;
end % End of
while
% Printing resultant
values
fprintf("\n The sin of
%.2f is %.8f using while loop, which provides an error equal to
%.2e \n", angleDegrees, SOld, EstError);
end
end
Sample Output:
Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+...
I need not in pic or handwriting, in keyboard Spring 19 (1) ESC 152 Programming with MATLAB Section 2 1) The Taylor series expansion for cos(x) is: coS(x). where x is in radians. Write a MATLAB program that determines cos (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 loop for adding the terms of the Taylor series. If a is the nth term...
Setup a program that will solve for sin x using the Taylor series expansion of x. Make sure the number of terms is some type of input. Calculate approximate 1. error Setup a program that will solve for sin x using the Taylor series expansion of x. Make sure the number of terms is some type of input. Calculate approximate 1. error
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
Problem 2. Write the Taylor series expansion for the following functions up to quadratic terms a. cos (x) about the point x*-pi/4. b. f(xx) 10x1 20x^x2 +10x3 +x 2x 5 about the point (1,1). Compare the approximate and exact values of the function at the point (1.2, 0.8)
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...
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...
2. (New ways to find Taylor series) It's not always easy to write down Taylor series representations by computing all the successive derivatives of a function as follows. (a) Find, by evaluating derivatives at 0, the first three nonzero terms in the Taylor series about 0 for the function g(x) -sin a2 in the text or class such as e", sin , and cos a (b) Use Taylor series expansions already es to find an infinite series representation expansion for...
Problem 1 MATLAB A Taylor series is a series expansion of a function f()about a given point a. For one-dimensional real-valued functions, the general formula for a Taylor series is given as ia) (a) (z- a) (z- a)2 + £(a (r- a) + + -a + f(x)(a) (1) A special case of the Taylor series (known as the Maclaurin series) exists when a- 0. The Maclaurin series expansions for four commonly used functions in science and engineering are: sin(x) (-1)"...
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
Write the Taylor series expansion of cos(x): Use the first three terms to calculate the value of cos(n/4). Use the decimal format with six significant digits (apply rounding at each step). Calculate the truncation error A- B-