• Toshkent-2024
  • $sum = 5 ($func($a) + $func($b))




    Download 5,05 Mb.
    bet1/3
    Sana05.07.2024
    Hajmi5,05 Mb.
    #266715
      1   2   3
    Bog'liq
    2-ishamaliy



    O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI



    Muhammad Al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari Universiteti
    Algoritmlarni loyihalash
    Topshirdi: Baxtiyorov Asilbek
    Tekshirdi:Ravshanov Anvar


    Toshkent-2024



    1. MISOL

    Mavzu:Funksiyalarni Furye qatoriga yoyish





    DASTURI:
    const pi =3.14;


    // Function f(x) = x + 5π
    function f($x) {
    return $x + 5 * pi;
    }

    // Numerical integration using the trapezoidal rule


    function integrate($func, $a, $b, $n = 1000) {
    $h = ($b - $a) / $n;
    $sum = 0.5 * ($func($a) + $func($b));
    for ($i = 1; $i < $n; $i++) {
    $sum += $func($a + $i * $h);
    }
    return $sum * $h;
    }

    // Function to calculate an and bn coefficients


    function fourierCoefficients($n, $a = -pi, $b = pi, $numIntervals = 1000) {
    // an coefficient
    $an_func = function($x) use ($n) {
    return f($x) * cos($n * $x);
    };

    // bn coefficient


    $bn_func = function($x) use ($n) {
    return f($x) * sin($n * $x);
    };

    $a_n = integrate($an_func, $a, $b, $numIntervals) / pi;


    $b_n = integrate($bn_func, $a, $b, $numIntervals) / pi;

    return [$a_n, $b_n];


    }

    // Function to compute Fourier series


    function fourierSeries($x, $terms = 10) {
    $pi = pi;
    // Compute a0
    $a0_func = function($x) {
    return f($x);
    };
    $a0 = integrate($a0_func, -$pi, $pi) / (2 * $pi);

    // Fourier Series Initialization


    $sum = $a0;

    // Calculate Fourier Series up to the specified number of terms


    for ($n = 1; $n <= $terms; $n++) {
    list($a_n, $b_n) = fourierCoefficients($n);
    $sum += $a_n * cos($n * $x) + $b_n * sin($n * $x);
    }

    return $sum;


    }

    // Example usage:


    $x = 1.0; // You can set this to any value within the interval [-pi, pi]
    $a_values = [];

    for ($n = 0; $n <= 10; $n++) {


    $a_values[$n] = fourierCoefficients($n)[0];
    }

    print_r($a_values);



    ?>

    Download 5,05 Mb.
      1   2   3




    Download 5,05 Mb.