• Bajardi: Xamzayev Durbek Tekshirdi : Nosirova Namunabonu 1-laboratoriya ishi topshirig‘i
  • 1 – amaliy ishi Bajardi: Xamzayev Durbek Tekshirdi : Nosirova Namunabonu




    Download 1,46 Mb.
    Sana15.05.2024
    Hajmi1,46 Mb.
    #234006

    MUHAMMAD AL-XORAZMIY NOMIDAGI
    TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
    Televezion Texnalogiyalar fakultite
    Elektr Energetika yo’nalishi 520-22 guruh talabasi
    Xamzayev Durbekning Algorithmlarni loyihalash fanidan
    1 – amaliy ishi



    Bajardi: Xamzayev Durbek
    Tekshirdi : Nosirova Namunabonu

    1-laboratoriya ishi topshirig‘i
    Berilgan integral qiymatini to‘g‘ri to‘rtburchaklar, trapetsiyalar, Simpson usullarida ε>0 aniqlikda hisoblang. Aniqlikka erishganlik sharti sifatida |S2n-Sn| < ε tengsizlikdan foydalaning (boshlang’ich n = 10 deb olish mumkin). Natijaga erishish uchun zarur bo’lgan qadamlar soni va integral taqribiy qiymatini chiqariladi. C++ dasturlash tilida natijani oling.

    To’g’ri to’rburchaklar usuli
    #include
    #include

    using namespace std;


    int main(){
    float s,a,b,h,x;
    int n,i;
    cout<<"a=";cin>>a;
    cout<<"b=";cin>>b;
    cout<<"n=";cin>>n;
    h =(b-a)/n;
    s=0;
    for(i=0;ix =a+i*h;
    s+=pow(sin(x+1),2)*log(pow(x,2)+3);
    }
    s=s*h;
    cout< return 0;
    }

    Trapetsiya usuli


    #include
    #include

    using namespace std;

    double function(double x ) {
    return pow(sin(x+1),2)*log(pow(x,2)+3);
    }

    double trapezoidMethod(double a, double b, int n) {


    double h = (b - a) / n;
    double sum = function(a) + function(b);

    for (int i = 1; i < n; ++i) {


    sum += 2*(function(a + i*h));
    }

    return sum*h/2;


    }

    int main()


    {
    double a = 0, b = 1, epsilon = 0.001;
    int n = 10;

    double ans, result;


    int steps = 0;
    do
    {
    ans = trapezoidMethod(a, b, n);
    n *= 2;
    result = trapezoidMethod(a, b, n);
    steps++;
    } while (fabs(result - ans) >= epsilon);

    cout << "Trapetsiyalar usuli bilan hisoblangan integral qiymati: " << result << endl;


    cout << "Zarur bo'lgan qadamlar soni: " << steps << endl;
    return 0;
    }

    Simpson usuli

    #include


    #include
    using namespace std;
    float f(float x)
    {
    return pow(sin(x+1),2)*log(pow(x,2)+3);
    }
    int main ()
    {
    float S,a,b,h,x; int n,i;
    cin>>a>>b>>n;
    h=(b-a)/(2*n);
    S=f(a)+f(b);
    for (i=1;i<2*n;i++)
    {
    x=a+i*h;
    if (i%2==0) S=S+2*f(x); else S=S+4*f(x);
    }
    S=S*h/3;
    cout< return 0;
    }


    1.2 Berilgan tenglamaning taqribiy yechimini ε>0 aniqlikda urinmalar (Nyuton) va vatarlar usullarida hisoblang. Aniqlikka erishganlik sharti sifatida |xn+1-xn|<ε tengsizlikdan foydalaning. Boshlang‘ich x0ϵ(a;b) olinadi.
    Natijada ildiz taqribiy qiymati va zarur bo‘lgan qadamlar soni chiqarilsin.
    С++ dasturida natijani oling.

    #include


    #include

    using namespace std;

    // Tenglama x-cos(x)
    // Birinchi tartibli hosila 1+sin(x)
    // Ikkinchi tartibli hosila cos(x)

    //2-Tenglama pow(x, 3) - 3 * x -1 (0, 1)


    //Birinchi tartibli hosila 3 * pow(x, 2) - 3
    //Ikkinchi tartibli hosila 6 * x

    double function(double x) {


    // return x-cos(x);
    return pow(x, 3) - 3 * x -1;
    }

    double first_derivative (double x) {


    // return 1+sin(x)
    return 3 * pow(x, 2) - 3;
    }

    double second_derivative (double x) {


    // return cos(x)
    return 6 * x ;
    }

    double vatarlarMethod(double a, double b, double epsilon) {


    double c;
    int steps = 0;
    do
    {
    c = a - function(a) * (b - a) / (function(b) - function(a));

    (function(a) * function(c) > 0) ? a = c : b = c;


    steps++;
    } while (fabs(function(c)) >= epsilon);

    cout << "Yechim topish uchun zarur bo'lgan qadamlar soni: " << steps << endl;

    return c;
    }

    int main()


    {
    // double a = 0, b = 1, epsilon = 0.001;
    double a = 0, b = 1, epsilon = 0.001;

    if (function(a) * function(b) >= 0 || first_derivative(a) * first_derivative(b) <= 0) {


    cout << "Tenglama bu oraliqda yechimga ega emas!" << endl;
    }

    double result = vatarlarMethod(a, b, epsilon);

    cout << "Tenglamaning vatarlar usulida hisoblangan ildizi: " << result << endl;
    return 0;
    }
    Urinmalar (Nyuton) usuli
    #include
    #include

    using namespace std;

    // Tenglama x -cos(x)=0
    // Birinchi tartibli hosila 1+sin(x)
    // Ikkinchi tartibli hosila cos(x)

    //2-Tenglama pow(x, 3) + 3 * x -1 = 0 (0, 1)


    //Birinchi tartibli hosila 3 * pow(x, 2) +3
    //Ikkinchi tartibli hosila 6 * x

    double function(double x) {


    // return x-cos(x);
    return pow(x, 3) + 3 * x -1;
    }

    double first_derivative (double x) {


    // return 1+sin(x);
    return 3 * pow(x, 2) +3;
    }

    double second_derivative (double x) {


    // return cos(x);
    return 6 * x ;
    }

    double NyutonMethod(double a, double b, double epsilon) {


    double c;
    int steps = 0;
    if (function(a) * second_derivative(a) > 0)
    c = a;
    else
    c = b;

    do
    {

    c = c - function(c) / first_derivative(c);
    steps++;

    } while (fabs(function(c)) >= epsilon);


    cout << "Yechim topish uchun zarur bo'lagan qadamlar soni: " << steps << endl;
    return c;
    }

    int main()


    {
    // double a = 0, b = 1, epsilon = 0.001;
    double a = 0, b = 1, epsilon = 0.001;

    if (function(a) * function(b) >= 0 || first_derivative(a) * first_derivative(b) <= 0) {


    cout << "Tenglama bu oraliqda yechimga ega emas!" << endl;
    }

    double result = NyutonMethod(a, b, epsilon);



    cout << "Tenglamaning Nuyuton usulida hisoblangan ildizi: " << result << endl;
    return 0;
    }

    Download 1,46 Mb.




    Download 1,46 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    1 – amaliy ishi Bajardi: Xamzayev Durbek Tekshirdi : Nosirova Namunabonu

    Download 1,46 Mb.