- •Кафедра електроніки
- •Лабораторна робота № 1 розв’язування нелінійних рівнянь
- •Початкове наближення слід вибрати з умови
- •Похибка методу оцінюється як
- •Звіт повинен містити
- •Контрольні питання
- •Метод половинного ділення:
- •Метод хорд:
- •Метод дотичних:
- •Метод січних:
- •Лістинг програм: Метод половинного ділення:
- •Метод хорд:
- •Метод дотичних:
- •Метод січних:
- •Висновок
Метод хорд:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double x,fa,fb,b,e,r;
e=0.001;
b=-2;
fb=4*b*b*b-3,5*b*b-3,5*b-0,5;
//cout <<"fb="<<fb<<\n;
x=2;
ssulka1:
fa=4*x*x*x-3,5*x*x-3,5*x-0,5;
//cout <<"fa="<<fa<<\n;
r=(x-(fa*(b-x)/(fb-fa)));
//cout <<"r="<<r<<\n;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka1;
}
else
{
//fa=4*r*r*r-3,5*r*r-3,5*r-0,5;
//cout <<"fa="<<fa<<\n;
cout <<"x="<<r<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Метод дотичних:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double f,fcx,x,e,r ;
e=0.001;
x=-2;
ssulka:
fcx=12*x*x-7*x-3.5;
// cout<<"fcx="<<fcx<<endl;
f= 4*x*x*x-3.5*x*x-3.5*x-0.5;
// cout<<"f="<<f<<endl;
r=x-(f/fcx);
// cout<<"r="<<r<<endl;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka;
}
else
cout<<"x="<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Метод січних:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double f,fc,fx,x,e,r,c ;
e=0.001;
x=-2;
ssulka:
c=x-0.1;
fc= 4*c*c*c-3.5*c*c-3.5*c-0.5;
//cout<<"fd="<<fd<<\n;
f= 4*x*x*x-3.5*x*x-3.5*x-0.5;
//cout<<"f="<<f<<\n;
fx=(f-fc)/0.1;
//cout<<"fx="<<fx<<\n;
r=x-(f/fx);
//cout<<"r="<<r<<\n;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka;
}
else
cout<<"x="<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Висновок
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Люда:
Половинне ділення
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
double a,b,c,p,fa,fb,fc,e;
a=-2;
b=2;
e=0.001;
ssulka1:
c=(a+b)/2;
fa=4*a*a*a-3,5*a*a-3,5*a-0,5;
fb=4*b*b*b-3,5*b*b-3,5*b-0,5;
fc=4*c*c*c-3,5*c*c-3,5*c-0,5;
cout<<"pohidni v tochkah nakinciah vidrizkiv"<<endl;
cout <<"fa="<<fa<< endl;
cout <<"fb="<<fb<< endl<<endl;
cout<<"pohidni v novi tochci dlia toho shob provirutu ii znak toist f(x)<0 to - chu f(x)>0 to +"<<endl;
cout <<"fc="<<fc<< endl<<endl;
if (fa<0&&fc>0)
b=c;
else
a=c;
p=b-a;
cout<<"novi vidrizku vuburaish toi de e zmina znakiv [p;a] chu [b;c]"<<endl;
cout <<"p ="<<p<<endl;
cout <<"a="<<a<<endl;
cout <<"b="<<b<<endl;
cout <<"c="<<c<<endl<<endl<<endl<<endl;
if (p>e)
goto ssulka1;
c=(a+b)/2;
cout <<"x="<<c<< endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Метод хорд
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double x,fa,fb,b,e,r;
e=0.001;
b=-2;
fb=4*b*b*b-3,5*b*b-3,5*b-0,5;
cout <<"fb="<<fb<<endl;
x=2;
ssulka1:
fa=4*x*x*x-3,5*x*x-3,5*x-0,5;
cout <<"fa="<<fa<<endl;
r=(x-(fa*(b-x)/(fb-fa)));
cout <<"r="<<r<<endl<<endl<<endl;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka1;
}
else
{
fa=4*r*r*r-3,5*r*r-3,5*r-0,5;
cout <<"fa="<<fa<<endl;
cout <<"x="<<r<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Січних
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double f,fc,fx,x,e,r,c ;
e=0.001;
x=-2;
ssulka:
c=x-0.1;
fc= 4*c*c*c-3.5*c*c-3.5*c-0.5;
cout<<"fd="<<fd<<endl;
f= 4*x*x*x-3.5*x*x-3.5*x-0.5;
cout<<"f="<<f<<endl;
fx=(f-fc)/0.1;
cout<<"fx="<<fx<<endl;
r=x-(f/fx);
cout<<"r="<<r<<endl<<endl<<endl;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka;
}
else
cout<<"x="<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Дотичних
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double f,fcx,x,e,r ;
e=0.001;
x=-2;
ssulka:
fcx=12*x*x-7*x-3.5;
cout<<"fcx="<<fcx<<endl;
f= 4*x*x*x-3.5*x*x-3.5*x-0.5;
cout<<"f="<<f<<endl;
r=x-(f/fcx);
cout<<"r="<<r<<endl<<endl<<endl;
if(((x-r)>0&&(x-r)>e)||((x-r)<0&&-1*(x-r)>e))
{
x=r;
goto ssulka;
}
else
cout<<"x="<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}