Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is the Algorithm for calculating a cosine of a number?

Status
Not open for further replies.

rahul.6sept

Full Member level 5
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.
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:

Re: What is the Algorithm for calculating the cube root of a number?

The function you posted above doesn't matches anyone of both the 2 algorithms ( Newton, Halley ) available at the link suggested. You have to ellaborate your questions, as well take into account what has already been answered.
 

Re: What is the Algorithm for calculating the cube root of a number?

Let me explain the algorithm:

x^3=a; we want to know x.

Follow Newton Raphson method:

x=a/(x^2); start with x=1;
x=a; this is the first iteration;
x_old=(1+a)/2; take the midpoint of the two;
x_new=a/(x_old^2); we get the next iteration;
see x_old and x_new are close enough; if yes then stop; else continue;
x_old=(x_new+x_old)/2;
(use x*x instead of x^2);

What is the above code (you have posted) supposed to do?
 

Re: What is the Algorithm for calculating cosine of a number ?

Hi Andre and C_mitra,

The cube root problem is solved. This is a different one. I want to determine the cos x using maclaurin series. I'm getting the output. But it is not correct.

Regards,

Rahul
 

Re: What is the Algorithm for calculating cosine of a number ?

Hi,

Maybe a confusion with radians and degree?

Klaus
 

Re: What is the Algorithm for calculating cosine of a number ?

Sine and cosines are usually not computed using the standard series approximation because the series converges poorly (slowly). They are best computed using the Pade approximation (https://mathworld.wolfram.com/PadeApproximant.html).

If you still want to compute the series approx, find a recursion relation first. AND AS pointed out by KlausST, the argument must be in radians.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top