Professional Documents
Culture Documents
CENG 202-Tutorial1
CENG 202-Tutorial1
CENG 202-Tutorial1
TUTORIAL 1
Q.1 Expand the following functions about a=0 using Taylor’s series. Then write a Matlab
code to calculate approximate values, true values and the relative true errors of the
function for given specific values. Do the calculations for number of terms ranging from
1-5.
a) f(x) = cos(x) calculate the function value at x
4
b) g(x) = sin(x) calculate the function value at x
4
Q.2 Expand the following function to Taylor series around a=0 until fifth terms
1
f ( x)
x 1
Then write a Matlab program to calculate the approximate values of the function and
relative true errors at x=0.5 for each terms ranging from 1-5.
f(x)=Cos(x)
g(x)=Sin(x)
h(x)=
n=input('enter n');
x=input('enter x');
expx=0;
ex=exp(x);
disp(['n expx error'])
for i=1:n;
k=i-1;
expx=expx+ (x^k)/factorial(k);
error=abs((ex-expx)/ex);
disp([i expx error])
end