# ctgmath

***

**1. Vector Length Calculation**

```cpp
#include <ctgmath>
int main() {
  double x = 2, y = 3, z = 4;
  double length = sqrt(x * x + y * y + z * z);
  std::cout << "Vector length: " << length << std::endl;
  return 0;
}
```

**2. Triangle Area Calculation**

```cpp
#include <ctgmath>
int main() {
  double a = 5, b = 7, c = 9;
  double s = (a + b + c) / 2;
  double area = sqrt(s * (s - a) * (s - b) * (s - c));
  std::cout << "Triangle area: " << area << std::endl;
  return 0;
}
```

**3. Circle Area Calculation**

```cpp
#include <ctgmath>
int main() {
  double radius = 3.5;
  double area = M_PI * radius * radius;
  std::cout << "Circle area: " << area << std::endl;
  return 0;
}
```

**4. Sphere Volume Calculation**

```cpp
#include <ctgmath>
int main() {
  double radius = 4;
  double volume = (4 / 3) * M_PI * pow(radius, 3);
  std::cout << "Sphere volume: " << volume << std::endl;
  return 0;
}
```

**5. Angle Conversion**

```cpp
#include <ctgmath>
int main() {
  double degrees = 60;
  double radians = degrees * M_PI / 180;
  std::cout << "Radians: " << radians << std::endl;
  return 0;
}
```

**6. Numerical Integration (Trapezoidal Rule)**

```cpp
#include <ctgmath>
int main() {
  double a = 0, b = 1;
  double f(double x) { return x * x; }
  double h = (b - a) / 100;
  double sum = 0;
  for (int i = 1; i < 100; i++) {
    sum += f(a + i * h);
  }
  double integral = (h / 2) * (f(a) + 2 * sum + f(b));
  std::cout << "Numerical integral: " << integral << std::endl;
  return 0;
}
```

**7. Gaussian Distribution**

```cpp
#include <ctgmath>
int main() {
  double mean = 0, stddev = 1;
  double x = 0.5;
  double probability = exp(-pow(x - mean, 2) / (2 * pow(stddev, 2))) / (stddev * sqrt(2 * M_PI));
  std::cout << "Probability: " << probability << std::endl;
  return 0;
}
```

**8. Hyperbolic Functions**

```cpp
#include <ctgmath>
int main() {
  double x = 1.5;
  double sinh = sinh(x);
  double cosh = cosh(x);
  double tanh = tanh(x);
  std::cout << "sinh(" << x << "): " << sinh << std::endl;
  std::cout << "cosh(" << x << "): " << cosh << std::endl;
  std::cout << "tanh(" << x << "): " << tanh << std::endl;
  return 0;
}
```

**9. Error Function**

```cpp
#include <ctgmath>
int main() {
  double x = 0.5;
  double erf = erf(x);
  std::cout << "erf(" << x << "): " << erf << std::endl;
  return 0;
}
```

**10. Bessel Functions**

```cpp
#include <ctgmath>
int main() {
  double x = 2;
  double order = 0.5;
  double bessel = j0(x);  // Bessel function of the first kind, order 0
  std::cout << "J0(" << x << "): " << bessel << std::endl;
  return 0;
}
```

**11. Gamma Function**

```cpp
#include <ctgmath>
int main() {
  double x = 5;
  double gamma = tgamma(x);
  std::cout << "Gamma(" << x << "): " << gamma << std::endl;
  return 0;
}
```

**12. Beta Function**

```cpp
#include <ctgmath>
int main() {
  double a = 2, b = 3;
  double beta = beta(a, b);
  std::cout << "Beta(" << a << ", " << b << "): " << beta << std::endl;
  return 0;
}
```

**13. Legendre Polynomial**

```cpp
#include <ctgmath>
int main() {
  int n = 3;
  double x = 0.5;
  double legendre = lgamma(n + 1) / lgamma(2 * n + 1) * pow((1 - x) / 2, n) * pow((1 + x) / 2, n);
  std::cout << "P3(" << x << "): " << legendre << std::endl;
  return 0;
}
```

**14. Hermite Polynomial**

```cpp
#include <ctgmath>
int main() {
  int n = 4;
  double x = 3;
  double hermite = pow(2, n) * pow(x, n) * exp(-pow(x, 2) / 2) * (-1 + pow(x, 2)) / 2;
  std::cout << "H4(" << x << "): " << hermite << std::endl;
  return 0;
}
```

**15. Laguerre Polynomial**

```cpp
#include <ctgmath>
int main() {
  int n = 5;
  double x = 2;
  double laguerre = pow(-1, n) / lgamma(n + 1) * pow(x / 2, n) * exp(x / 2) * diff(gamma, n)
```
