Программа на языке CИ
#include “stdafx.h” #include <iostream> #include <math.h> using namespace std; double f (double x)
{double Y; Y=pow(x,2)-5*x+6; return Y;}
double f1 (double x)
{double Y;
Y=2*x-5; return Y;} void main()
{ double x0,x1,e=0.0001; cout<<”Vvedite x0”<<endl; cin>>x0;
cout<<”\t”<<”x”<<”\t”<<”f(x)”<<”\t”<<”f1(x)\n”; cout<<”\t”<<x0<<”\t”<<f(x0)<<”\t”<<f1(x0)<<”\n”; while(fabs(f(x0))>e)
{
x1=x0-f(x0)/f1(x0); cout<<”\t”<<x1<<”\t”<<f(x1)<<”\t”<<f1(x1)<<endl; x0=x1;
}}
Метод простой итерации
Программа на языке CИ
#include “stdafx.h” #include <iostream> #include <math.h> using namespace std; double f (double x)
{double Y; Y=pow(x,2)-5*x+6; return Y;}
double fi (double x)
{double Y; Y=sqrt(5*x-6); return Y;} void main()
{double x0,x1,eps=0.01; cout<<”Vvedite x0”<<endl; cin>>x0;
cout<<”\t”<<”x”<<”\t”<<”f(x)”<<”\n”; cout<<”\t”<<x0<<”\t”<<f(x0)<<”\n”; while(fabs(f(x0))>eps)
x1=fi(x0); cout<<”\t”<<x1<<”\t”<<f(x1)<<endl; x0=x1;
}
}