4. Berilgan integralni Trapetsiya hamda Simpson usulida hisoblang. N oraliqni bo’linish soni.
Dastur kodi:
#include
#include
using namespace std;
double F(double x)
{
return cos(x*x+1) * exp(-x*x);
}
int main()
{
double a = 0, b = 1, n = 10;
double S = 0, h = (b-a)/n;
for(int i = 1; i <= n-1; i ++)
{
S += F(a + i * h);
}
S = h*((F(a) + F(b))/2) + h * S;
cout << S;
}
Dastur natijasi:
Dastur kodi:
#include
#include
using namespace std;
double F(double x)
{
return cos(x*x+1) * exp(-x*x);;
}
int main()
{
double a = 0, b = 1, n = 10;
double h = (b-a)/n, S = 0, m = n / 2;
for(int i = 1; i <= m; i ++)
{
S += 4 * F(a + (2 * i - 1) * h);
if (i < m) {
S += 2 * F(a + 2 * i * h);
}
}
S = (S + F(a) + F(b)) * h / 3;
cout << S;
}
Dastur natijasi:
Algebraik va transtsendent tenglamalar yechimlarini taqribiy usullar bilan topish.
1-Vazifa. Tenglamalar yechimlari joylashgan [a; b] oraliqni analitik usul bilan ajrating.
2-Vazifa. Tenglamalar yechimlari joylashgan oraliqlar aniqlangandan so’ng taqribiy yechimlarini oraliqni teng ikkiga bo’lish usulida E=0.001 aniqlikda hisoblang. Algoritmini tuzib, dasturlash tilida dastur kodini yozib natija oling.
Dastur kodi:
#include
#include
using namespace std;
float F(float x)
{
return pow(x,3) - 2*x -5;
}
int main()
{
const int k = 4;
float a,b,x[2*k+1], y[2*k+1], E = 0.001, c;
for(int i = 0; i <= 2*k+1; i ++)
{
x[i] = -k + i;
y[i] = F(x[i]);
}
for(int i = 0; i <= 2*k; i ++)
{
if(y[i]*y[i+1] < 0)
{
a = x[i];
b = x[i+1];
}
}
cout << "a = " << a << ", b = " << b << endl;
while (fabs(b - a) >= E) {
c = (a + b) / 2;
if (F(a) * F(c) < 0) {
b = c;
} else {
a = c;
}
}
c = (a + b) / 2;
cout << "c = " << c;
}
Dastur natijasi:
Dastur kodi:
#include
#include
using namespace std;
float F(float x)
{
return 2*x -pow(2,x);
}
int main()
{
const int k = 4;
float a,b,x[2*k+1], y[2*k+1], E = 0.001, c;
for(int i = 0; i <= 2*k+1; i ++)
{
x[i] = -k + i;
y[i] = F(x[i]);
}
for(int i = 0; i <= 2*k; i ++)
{
if(y[i]*y[i+1] < 0)
{
a = x[i];
b = x[i+1];
}
}
cout << "a = " << a << ", b = " << b << endl;
while (fabs(b - a) >= E) {
c = (a + b) / 2;
if (F(a) * F(c) < 0) {
b = c;
} else {
a = c;
}
}
c = (a + b) / 2;
cout << "c = " << c;
}
Dastur natijasi:
Iteratsion usullar: Nyuton(Urinmalar) va vatarlar usuli. Ularning yaqinlashish tezligini baholash.
1-Vazifa. Vatarlar va urinmalar usullari yordamida tenglama taqribiy ildizlarini 0,001 aniqlikda hisoblash.
2-Vazifa. Tenglamaning taqribiy oraliqlari topib, ularning yaqinlashish tezligini baholang.
Dastur kodi:
#include
#include
using namespace std;
float F(float x)
{
return x-sqrt(log(x+2));
}
float F1(float x)
{
return 1-0.5 / sqrt(log(x+2)) * (1/(x+2));
}
float F2(float x)
{
return -0.25*pow(log(x+2),-1.5)*pow((x+2),-2)+ 1/2 *pow((x+2),-2)*pow(log(x+2),-0.5) ;
}
int main()
{
int i = 0;
float a, b, x1, x2, E = 0.001;
do {
cout<< "a = "; cin >> a;
cout<< "b = "; cin >> b;
cout<
} while (F(a) * F(b) > 0);
if (F(a) * F2(a) > 0) {
x1 = a;
} else {
x1 = b;
}
x2 = x1 - (F(x1) / F1(x1));
while (fabs(x2 - x1) >= E) {
x1 = x2;
i++;
x2 = x1 - (F(x1) / F1(x1));
}
cout << "x2 = " << x2 << " i = " << i;
}Dastur natijasi:
Dastur kodi:
#include
#include
using namespace std;
float F(float x)
{
return pow(x, 3) +3 * pow(x, 2) + 6 * x - 1;
}
float F1(float x)
{
return 3*x*x+6*x+6;
}
float F2(float x)
{
return 6*x+6;
}
int main()
{
int i = 0;
float a, b, x1, x2, E = 0.001;
do {
cout<< "a = "; cin >> a;
cout<< "b = "; cin >> b;
cout<
} while (F(a) * F(b) > 0);
if ( F(a) * F2 (a) > 0) {
x1 = a;
x2 = x1 - ((F(x1) * (b - x1)) / (F(b) - F(x1)));
while (fabs(x2 - x1) >= E) {
x1 = x2;
i++;
x2 = x1 - ((F(x1) * (b - x1)) / (F(b) - F(x1)));
}
} else {
x1 = b;
x2 = x1 - ((F(x1) * (x1 - a)) / (F(x1) - F(a)));
while (fabs(x2 - x1) >= E) {
x1 = x2;
i++;
x2 = x1 - ((F(x1) * (x1 - a)) / (F(x1) - F(a)));
}
}
cout << "x2 = " << x2 << "; i = " << i;
}
5. Algebraik va trantsendent tenglamalarni taqribiy yechish usullari,
algoritmlari va dasturlari, urinmalar usuli
Reja:
Algebraik va trantsendent tenglamalarni taqribiy yechish usullari, kesmani ikkiga bulish usuli
Vatarlar usuli va iteratsiya usuli
Urinmalar usuli
Tayanch iboralar: Tenglama, tenglamaning ildizlari, bir no‘malumli tenglamalar, algebraik tenglama, trantsendent tenglama, tenglamalarni taqribiy yechish usullari, kesmani ikkiga bulish, vatarlar, iteratsiya usullari, urinmalar usuli.
Algebraik va trantsendent tenglamalarni taqribiy yechish usullari, kesmani ikkiga bulish usuli
Algebraik va trantsendent tenglamalar ildizlari yotadigan oraliklar ajratib olingandan sung tenglamaning ildizini taqribiy hisoblash uchun, taqribiy hisoblash usullaridan biri kullaniladi.
Demak tenglama berilgandan sung, tenglamaning ildizlari yotgan oraliklar ajratib olinadi, taqribiy ildizni topish usuli tanlanadi, tanlangan usulga mos ravishda algorimning blok–sxemasi va biror bir dasturlashtirish tilida blok–sxemaga mos ravishda dastur tuziladi. Dastur kompyuterga terilib, natijalar olinadi va taxlil kilinadi.
Tenglamalarning ildizlarini taqribiy yechish usullaridan biri bu kesmani teng ikkiga bulish usulidir. Bunda berilgan [a;b] kesma teng ikkiga bulinib [a;с] yoki [с;b] kesmalarda f(a)∙f(c)<0 yoki f(c)∙f(b)<0 shart tekshiriladi va с=(a+b)/2 qilib olinadi va ildiz b-a≤ε shart bajarulgunga kadar davom etirilib topiladi.
0>0>
Do'stlaringiz bilan baham: |