rahul.6sept
Full Member level 5
- Joined
- Nov 17, 2006
- Messages
- 243
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,298
- Location
- Guwahati, India
- Activity points
- 2,889
What is the Algorithm for calculating cosine of a number ?
Following posts moved from original thread:
---------------
Dear All,
In the folowing code I'm not getting it correct.
Regards,
Rahul
Following posts moved from original thread:
---------------
Dear All,
In the folowing code I'm not getting it correct.
Code:
function [cosVal] = maclaurinCos(x,n)
% To Compute approximation of cos(x) using MacLaurin
% Series upto the n-th order term (x^n/n!)
numerator = x.^[1:n];
denom = cumprod(1:n);
vec = [1, numerator./denom];
terms=0;
for i=1:n
terms=((-1)^(2*n).*vec);
cosVal=cumsum(terms);
end
disp(['The value of Cos x is= ',num2str(cosVal)]);
Regards,
Rahul
Last edited by a moderator: