Question

In: Mechanical Engineering

for loop practice – Taylor Series!The moment you finish implementing the trigonometric functions, you realize that...

for loop practice – Taylor Series!The moment you finish implementing the trigonometric functions, you realize that you have forgotten your favorite function: the exponential! The Taylor Series for the exponential function is 푒푥=1+푥1!+푥22!+푥33!+...,‒∞<푥<∞a) Using a for loop, compute and display the error of the Taylor series when using 12 and 15 terms, each as compared to the exponential function when evaluated at x = 2. b) Can you figure out how to compute and display the number of terms necessary for this function to have an error within your allowed range of 0.001 when evaluated at x = 3. Display this error. For MATLAB

Solutions

Expert Solution

a.) I am providing both screenshot and copy paste code and output for this part below-

clear
clc

% defined the exponential fucntion
f=@(x)exp(x);
%take a variable named sum to collect values of taylor series
sum=0;
% x value at which the taylor series evaluated
x=2;

% for loop for 12 terms of taylor series
for n=0:11
sum=((f(0))*(x^n))/(factorial(n))+sum;
end

% printing values on command window
fprintf('The error in the computed values using 12 terms in taylor series is %f\n\n',abs(f(x)-sum))
sum=0;
% for loop for 15 terms of taylor series
for n=0:14
sum=((f(0))*(x^n))/(factorial(n))+sum;
end
% printing values on command window
fprintf('The error in the computed values using 15 terms in taylor series is %f\n\n',abs(f(x)-sum))

----------------------------------------------------------------------------------------------------------------------------------------

Screenshot of same code-

Output-

b.) I am providing both screenshot and copy paste code and output for this part below-

clear
clc

% defined the exponential fucntion
f=@(x)exp(x);
%take a variable named sum to collect values of taylor series
sum=0;
% x value at which the taylor series evaluated
x=3;
n=0;
% initial value of error assumed to run the while loop
error=1;
% while loop to calculate the no of terms terms of taylor series
while error>=.001
sum=((f(0))*(x^n))/(factorial(n))+sum;
error=abs(f(x)-sum);
n=n+1;
end

% printing values in command window
fprintf('The number of terms needed in series to get the error =0.001 is %d\n\n',n)

----------------------------------------------------------------------------------------------------------------------------------------

Screenshot of above code-

Output-


Related Solutions

Analyticity of trigonometric functions (a) Directly from the definition, construct the Taylor Series centered at x...
Analyticity of trigonometric functions (a) Directly from the definition, construct the Taylor Series centered at x = 0 for the function f(x) = cos(x). (b) Show that this series converges for all x ∈ R. (c) Show that this series converges to cos(x) for all x ∈ R.  
Find the Taylor series or polynomial generated by the following functions a. )f(x) √ x centred...
Find the Taylor series or polynomial generated by the following functions a. )f(x) √ x centred at x=4 , of order 3 b.) f(x) cosh x= e^x+e^-x/(2), centred at x=0 c.) f(x) = x tan^-1x^2 , centred at x=0 d.) f(x) = 1/(√1+x^3) , centred at x=0 , of order 4 e.) f(x) = cos(2x+pie/2) centred at x= pie/4
(e) Find the first 4 terms of the Taylor series for the following functions (i) ln...
(e) Find the first 4 terms of the Taylor series for the following functions (i) ln x centered at x0 = 1 . [8] (ii) sin x centered at x0 = π 4
You are a physician practice administrator. After completing inventory of needed supplies, you realize that you...
You are a physician practice administrator. After completing inventory of needed supplies, you realize that you have about three times more than what is needed based on demand. You need to meet with the providers to discuss the situation, prove the inventory is excessive, as well as provide some solutions. What are some items that you might include in this presentation to win over the physicians?
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings,...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings, and improve your skills with for loops. The methods you will write will be part of a short trivia game, feel free to try it out after you finish.   import java.util.Scanner; public class Trivia { //TODO: isLeapYear //TODO: isPrime //TODO: aWord //TODO: reverse public static void main(String[] args){ Scanner answers = new Scanner(System.in); int score = 0; System.out.println("What year is a Leap Year?"); //...
The Problem Below are a series of problems you need to solve using recursive functions. You...
The Problem Below are a series of problems you need to solve using recursive functions. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. Implementation Each recursive function MUST have a wrapper function enclosing it where you will do input/output file processing as well...
What do you feel is your biggest barrier to implementing evidence base practice in your workplace?...
What do you feel is your biggest barrier to implementing evidence base practice in your workplace? What is your professional responsibility in terms of evidence base practice? Outline a plan, including one goal ( with time frame) for addressing and overcoming this barrier.
Steps of evidenced based practice are critical when implementing change. How would you go about securing...
Steps of evidenced based practice are critical when implementing change. How would you go about securing the best evidence? What are you looking for?
Here is a program that computes Fibonacci series. Can you add comments to variables and functions...
Here is a program that computes Fibonacci series. Can you add comments to variables and functions of every functions? For example, what are these variables meaning? What "for" function do on this program? Describe important section of code to text file. For example, which section of this code important? Why? Thank you all of help. #include<iostream> using namespace std; int main() { int arr[100]; int n1, n2; cin>>n1; arr[0] = 0; arr[1] = 1; for(int i = 2;i<n1;i++){ arr[i] =...
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and...
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and c) Laplace transform? If yes, find them, if not, explain why you can not. A, x(t) = -1+cos(2t) + sin(pai*t+1)                                               (4-1) B, x(t) = 2d(t) cos(2t) +d(t-1.5p) sin(2t)                                          (4-2) C, x(t) = 1+cos(1.5t) + cos(4t)                                           (4-3)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT