In calculus, any continuous function can be written as an infinite series using
ID: 3794150 • Letter: I
Question
In calculus, any continuous function can be written as an infinite series using the Taylor Series formula. The Taylor series for the exponential function is as follows: e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + ... + x^n/n! Write a MATLAB program which calculates the exact values for each of the following functions: e^1, e^3, and Squareroot e in each of the display formats discussed in class. Then, set the display format to long, and recalculate the exact values of the functions and their Taylor series approximation. The Taylor series approximation should be made for n = 6. For each function calculated and approximated, display the percent error using the formula: Percent error = Exact Value - Approximate Value/Exact Value X 100 %Explanation / Answer
clear all;
close all;
clc;
exact1=exp(1);
exact2=exp(3);
exact3=sqrt(exp(1));
y1=0;x=1;
for n =1:1:6
y1 = y1 +(x.^n)./factorial(n);
end
x=3;y2=0;
for n =1:1:6
y2 = y2 +(x.^n)./factorial(n);
end
x=0.5;y3=0;
for n =1:1:6
y3 = y3 +(x.^n)./factorial(n);
end
p1= ((exact1 - y1)./exact1).*100;
p2= ((exact2 - y2)./exact2).*100;
p3= ((exact3 - y3)./exact3).*100;
fprintf('percent error in first function is %d ',p1);
fprintf('percent error in second function is %d ',p2);
fprintf('percent error in third function is %d ',p3);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.