1) Separarea Rădăcinilor A) X +0.4x +0.6x-1.6 0: X X) 3 X X
1) Separarea Rădăcinilor A) X +0.4x +0.6x-1.6 0: X X) 3 X X
x 2 x +3 x=0
=b2-4ac= (0.8)2-4*3*0.6=0.64-7.2=-6.56
[-k;k] k=(1+a)/|a0|
a=max{a1,,an}=1.6
k=(1+1.6)/1=2.6=3
a0=1
X
sgn f(x)
-3
-
0
-
3
+
x3-albastru
x-5-rou
Listingul Programului:
#include <string>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
float x,a,b,Eps;
void Meniu();
float f(float x);
void Newton (float a,float b,float Eps);
void Secante(float a, float b, float Eps);
void eps();
bool Intervalf();
float f0(float x) {
return pow(x,3)+0.4*pow(x,2)+0.6*x-1.6; // ecuatia
}
float f1(float x) {
return 3*pow(x,2)+0.8*x+0.6; // derivata de ord I
}
float f2(float x) {
return 6*x+0.8;
// ord II
}
int main()
{char var;
while(true)
{
Meniu();
cin>>var;
switch(var)
{
case '1': Intervalf(); break;
case '2': eps(); break;
case '3': Newton(a,b,Eps); break;
case '4': Secante(a,b,Eps); break;
case '0': exit(0);break;
}
}
cout<<endl;
return 0;
}
// functia meniu
void Meniu()
{ cout<<
"--------------------MENIUL--------------";
cout<<endl<< "| 1 |
Introduceti intervalu
|";
cout<<endl<< "----------------------------------------";
cout<<endl<< "| 2 |
Introduceti Epsilon
|";
cout<<endl<< "----------------------------------------";
cout<<endl<< "| 3 |
Metoda Tangentelor(Newton) |";
cout<<endl<< "----------------------------------------";
cout<<endl<< "| 4 |
Metoda Secantelor
|";
cout<<endl<< "----------------------------------------";
cout<<endl<< "| 0 |
Iesire
|";
cout<<endl<< "----------------------------------------";
cout<<endl<<"==";
}
bool Intervalf()
{
cout << "Intervalul este: ";
cin>>a>>b;
if ((f(a) * f(b))<=0)
{
cout<<"Intervalul scris este corect"<<endl;
return true;
}
else
if ( (f(a) * f(b)>0) ){
cout<<"Intervalul nu este corect "<<endl;
return false;
}
}
void eps()
{
cout<<endl<<"Precizia=10^";
cin>>Eps;
Eps=pow(10,Eps);
cout<<"Epsilon="<<Eps<<endl;
}
void Newton(float a,float b,float Eps)
{
int n=0; // iteratii
float c;
if(f0(a)*f2(a)>0) c=a;
else c=b;
do {
c=c-f0(c)/f1(c); // formula Newton
n+=1;
}
Rexultat: