x3 + x2 x – 3 = 0
Tenglamaning yechim joylashgan oralig’ini toping. Vatarlar usuli yordamida ildizlarni e=10-5 aniqlik bilan hisoblash algoritmini tuzing. Bunday aniqllika erishish uchun zarur qadamlar sonini aniqlang.
#include #include using namespace std;
float f(float x){
return pow(x,3)+(x*x)-x-3; // vatarlar usuli
}
float f1(float x){
return 3*x*x+2*x-1;
}
float f2(float x){
return 6*x+2;
}
int main() {
float a,b,eps;
cin>>a>>b>>eps;
float x[100];
if(f1(a)*f2(a)>0)
x[0]=a;
else x[0]=b;
b=a;
x[1]=x[0]-(f(x[0])*(b-x[0]))/(f(b)-f(x[0]));
int i=0;
while(fabs(x[i+1]-x[i])>eps){
i++;
x[i+1]=x[i]-(f(x[i])*(b-x[i]))/(f(b)-f(x[i]));
}
cout<<"x="< Ushbu masalani Nyuton usuli orqali yechish algoritmini tuzing. Ikkala usulda ham yechimlarni oling. Ko’rib chiqilgan usullar samaradorligini taqqoslang.
Dastur kodi : #include #include using namespace std;
float f(float x){
return pow(x,3)+(x*x)-(x)-; // urinmalar usuli
}
float f1(float x){
return 3*x*x+2*x-1;
}
float f2(float x){
return 6*x+2;
}
int main() {
float a,b,eps;
cin>>a>>b>>eps;
float x[100];
if(f(a)*f2(a)>0)
x[0]=a;
else x[0]=b;
x[1]=x[0]-f(x[0])/f1(x[0]);
int i=0;
while(fabs(x[i+1]-x[i])>eps){
i++;
x[i+1]=x[i]-f(x[i])/f1(x[i]);
}
cout<<"x="< Chiziqli dasturlash masalasini hosil qiling: