The function sin(x) can be written as a Taylor series by:
Write a user-defined function file that calculates sin(x) by using the Taylor series. For the function name and arguments use y = Tsin(x,n). The input arguments are the angle x in degrees and n the number of terms in the series. Use the function to calculate sin(150 ) using R no of terms (where R is last digit of registation no; use 10 if last digit zero & use 11 if last digit is 1)
%the file with function
function y = Tsin(x,n)
for j = 1:n
fact=1;
max=2*n+1;
for j = 1:max
fact=fact*j;
end
elem=(-1)^n*x^(2*n+1)/fact
y=y+elem;
end
%the calling of the function in other file
R=8; %the example
Tsin(150,R);
%the result
ans = -0.714876
Comments
Leave a comment