Search code examples
programming-languagestrigonometry

how to implement trigonometric expressions using a programming language?


*Expression: 
    -(sqrt((a0+a1 cos wt +a2 cos 2wt )^2 +(a1sin wt +a2 sin 2wt)^2
    - ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
    - sqrt ((1+b1cos wt+b2 cos 2wt)^2 +(b1 sin wt+b2 sin2 wt )^2 

*variables:
    - a0=.2
    - a1=1.2
    - a2=a0=.2
    - b1=1.6
    - b2=.8
    - F=32KHZ

*Question:

  • I am supposed to use a programming language (not matlab) to implement this exp and observe the o/p signal .... how can I do that and with what language if its even possible?

Solution

  • In C#, you can use System.Math, I believe it has every function you need:

    • Abs
    • Exp
    • Sin
    • Cos
    • Sqrt
    • ... a lot of other methods ...

    Data type depends on accuarcy you need, you can use decimal data type.

    Example:

    decimal a0 = 0.2;
    decimal a1 = 1.2;
    
    decimal result = Math.Cos(a0) * a1 - Math.Sqrt(a1);
    

    Basically, most programming languages have some sort of math library, which should contain those functions.