RAPORT
Tema: REZOLVAREA NUMERICĂ A ECUAŢIILOR
ALGEBRICE ŞI TRANSCENDENTE
Var. 17
Chișinău 2022
Лабораторная работа №1
ч.1 Графический и алгебраический методы отделения корней
Тема: «Численное решение алгебраических и трансцендентных уравнений»
I. Цель работы
1. Разделим все действительные корни уравнения f (x) = 0, где y = f (x) – функция
вещественное или действительное.
2. Определите действительный корень данного уравнения, используя метод
деления пополам интервал с погрешностью менее ε = 10-2.
3. Задайте корень, полученный с точностью ε = 10-6, используя
метод последовательных приближений
метод касательной (Ньютон)
II. Задачи, предоставленные для решения (в-1)
1. a) 2
y 1=x , y 2 =4 sin ( x)
1. b) x + 18∗x + 43
3
2 x=4∗cos ( x )
y1 = 2x;
y2 = 4cos(x)
f′(x)= 0
f ' ( x )=x=± √ 6
Разделим уравнение на 2 части и найдем корни графическим методом:
3
x =18 x+ 43
3
y 1=x ; y 2=18 x+ 43
x -∞ −√ 6 +√ 6 +∞
f(x) - + - +
√ 6 = 2.45
Получили 3 интервала, в которых находятся корни уравнения:
r1∈(−∞;-√6) r2∈(-√6;√6) r3∈(√6;+∞)
II. Определите действительный корень данного уравнения, используя
метод деления пополам интервал с погрешностью менее ε = 10-2.
#include <stdio.h>
#include <locale>
#include <conio.h>
#include <math.h>
#include <iostream>
if ((f(a) > 0 && f((a + b) / 2) < 0) || (f(a) < 0 && f((a + b) / 2) > 0))
{
b = (a + b) / 2;
cout << count_iter << ") [" << a << ";" << b << "]\n";
}
else
if ((f((a + b) / 2) > 0 && f(b) < 0) || (f((a + b) / 2) < 0 && f(b) > 0))
{
a = (a + b) / 2;
cout << count_iter + 1 << ") [" << a << ";" << b << "]\n";
}
else
{
printf("Корней нет !");
return 0;
getch();
}
count_iter++;
}
x = (a + b) / 2;// вычисление х после завершения цикла
printf("x^3-18*x+43\n\nx=%f \nF(x)=%f \n|a-b|=%f \nКол-во итераций=%d", x, f(x), fabs(a - b), count_iter); //
вывод результатов
getch();
return 0;
}
b)
3. Calculul rădăcinii reale prin metoda aproximațiilor successive.
a) x^2+4*sin(x) //oricare valoare
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
double function(double x)
{
return x*x+4+sin(x);
}
int main()
{
int k = 0;
double x0, x1 = 0, eps;
cout << "Valoarea initiala x0= ";
cin >> x0;
while (1)
{
x1 = function(x0);
k++;
if (abs(x1 - x0)>=eps)
{ cout << "Rezultatul: " << x0 << endl << "Numarul de iteratii " << k <<
endl; break; }
x0 = x1;
}
}
b) x^3-18x+43
#include<iostream>
#include<cmath>
#include<cstdlib>
double function(double x)
return x*x*x-18*x+43;
int main()
{
int k = 0;
while (1)
x1 = function(x0);
k++;
if (abs(x1 - x0)<eps)
{ cout << "Rezultatul: " << x0 << endl << "Numarul de iteratii " << k <<
endl; break; }
x0 = x1;
}
4. Calculul rădăcinii reale prin metoda tangentelor(Newton).
a) x^2+4*sin(x)
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
double function(double x)
{
return x*x+4+sin(x);
}
double fderivat(double x)
{
return 2*x+4*cos(x);
}
int main()
{
int k = 0;
double x0, x1, eps;
cout << "Valoare initiala x0: ";
cin >> x0;
cout << "Valoarea lui Epsilon: ";
cin >> eps;
while (1)
{
x1 = x0 - function(x0) / fderivat(x0);
k++;
if (abs(x1 - x0)>eps)
{ cout << "Rezultatul: " << x0 << endl << "Numarul de iteratii " << k <<
endl; break; }
x0 = x1;
}
}
b) x^3-18x+43
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
double function(double x)
{
return x*x*x-18*x+43;
}
double fderivat(double x)
{
return 3+x+x-18;
}
int main()
{
int k = 0;
while (1)
{
x1 = x0 - function(x0) / fderivat(x0);
k++;
if (abs(x1 - x0)<eps)
{ cout << "Rezultatul: " << x0 << endl << "Numarul de iteratii " << k <<
endl; break; }
x0 = x1;
}
Deoarece nu avem radacina pentru ecuatia data nu se poate efectua calculul!
Metoda secantei
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
double f(double x)
{
return x*x+4+sin(x);;
}
int main() {
double x2, x1, x3 = 0, y, eps = 0.000001;
int k = 0;
cout << " Introduceti intervalul " << endl;
cout << " a = ";
cin >> x1;
cout << " b = ";
cin >> x2;
do {
k++;
y = x3;
x3 = x2 - (f(x2) * (x2 - x1) / (f(x2) - f(x1)));
x1 = x2;
x2 = x3;
} while (fabs(y - x3) >= eps);
cout << " Radacina este: " << x3 << endl;
cout << " Numarul de iteratii : " << k << endl;
}
f(x) = x^2+4sin(x)
Metoda Metoda Metoda Metoda
Înjumătățirii Aproxi- Tangentelor Secantei
Intervalului mațiilor (Newton)
Succesive
Numărul de
iterații 7 1 1 4688544
Soluția finală -1.507 -1.5 -1.5 -0.227914
Написано на C++
#include<iostream>
using namespace std;
int main() {
int year, currentyear, differenceyear, differencemonth, differenceday;
short month, day, currentmonth, currentday;
cout << "Enter date of your birthday: ";
cin >> day >> month >> year;
cout << "Enter current year, month and day: ";
cin >> currentday >> currentmonth >> currentyear;
differenceyear = currentyear - year;
differenceday = currentday - day;
differencemonth = currentmonth - month;
if (differencemonth < 0 || differenceday < 0) differenceyear = differenceyear -
1;
if (differencemonth < 0 && differenceday < 0) differencemonth = 12 +
differencemonth - 1;
if (differencemonth < 0 && differenceday > 0) differencemonth = 12 +
differencemonth;
if (differencemonth > 0 && differenceday < 0) differenceday = day +
differenceday;
short daysAll = (differenceyear * 365.25)+(differencemonth*30)+differenceday;
cout << daysAll << "days\n";
system("pause");
return 0;
}