Friday, October 21, 2022

Digital Integration

 // DigitalIntegration.cpp : This file contains the 'main' function. Program execution begins and ends there.

// Digital integration of the function sin(x) from a to b

#include <iostream>

#include <math.h>

int main()

{

    int N = 10;

    double a, b, dx,s;

    a = 0;

    b = 3.14 / 4;

    dx = (b - a) / N;

    double sol = -cos(b) + cos(a);

    std::cout << "Solution analitical="<< sol<< "\n";

    s = sin(a)/2;

    for (int i = 1; i < N; i++) s = s + sin(a + i * dx);

    s = s + sin(b) / 2;

    s = s * dx;

    std::cout << "Solution numerical=" << s << "\n";

}


No comments:

Post a Comment

NaCl.xyz Generator with Interactive 3D Visualization

NaCl.xyz Generator with Interactive 3D Visualization NaCl.xyz Generator with Interactive 3D Visualization ...