0% found this document useful (0 votes)
40 views

Raport: Lucrare de Laborator nr.1

The document is a laboratory report that aims to: 1) Separate all real roots of the equation f(x)=0 where y=f(x) is a real function of the real variable. 2) Determine a real root of the given equation with the bisection method within an error of ε=10^-2. 3) Specify the obtained root with accuracy ε=10^-6 using successive approximations and the tangent method. 4) Compare the results considering the number of iterations and function/derivative evaluations. The report implements the methods in C++ to find the roots of two equations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Raport: Lucrare de Laborator nr.1

The document is a laboratory report that aims to: 1) Separate all real roots of the equation f(x)=0 where y=f(x) is a real function of the real variable. 2) Determine a real root of the given equation with the bisection method within an error of ε=10^-2. 3) Specify the obtained root with accuracy ε=10^-6 using successive approximations and the tangent method. 4) Compare the results considering the number of iterations and function/derivative evaluations. The report implements the methods in C++ to find the roots of two equations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Ministerul Educaiei Republicii Moldovei

Universitatea Tehnic a Moldovei

Raport
Lucrare de laborator nr.1
Varianta 6

A realizat: st. gr. C-162 Gangan Eugeniu


A verificat: Conf.Univ. Istrati Daniela

2017
Scopul lucrrii:
1)Sa se separe toate radacinile reale ale ecuatiei f(x) = 0 unde y=f(x) este o functie reala de variabila
reala.
2)Sa se determine o radacina reala a ecuatiei date cu ajutorul metodei injumatatirii intervalului cu o
eroare mai mica decit = 10-2
3)Sa se precizeze radacina obtinuta cu exactitatea = 10-6 , utilizind:
-metoda aproximatiilor succesive
-metoda tangentelor (Newton)
4) Sa se compare rezultatele luind in consideratie numarul de iteratii evaluarile pentru functii si
derivata.

Varianta 1
3
1) x -26x+43=0
2) lg(1+x)+x-15=0

Metoda grafica
3
1)x -26x+43=0

2)lg(1+x)+x-15=0
Programul
1)x3-26x+43=0
#include <iostream>
#include <cmath>

using namespace std;

void met_injumatatirii(){
float a,b,c,result,fa,fb,fc,eps;
int iter=0;
eps = 0.01;
cout<<"Introduceti intervalu [a,b]"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
while(iter!=100){
c = (a+b)/2;
iter++;
fa=a*a*a-26*a+43;
fb=b*b*b-26*b+43;
fc=c*c*c-26*c+43;

if(fc==0||(abs(b-a)<2*eps)){
result = c;
cout<<"Rezultatul obtinut este "<<result<<endl;
cout<<"S-au facut "<<iter<<"iteratii"<<endl;
break;
}
else{
if((fa>=0&&fc>=0)||(fa<=0&&fc<=0)) a=c;
if((fa>0&&fc<0)||(fa<0&&fc>0)) a=a;
if((fb>=0&&fc>=0)||(fb<=0&&fc<=0)) b=c;
if((fb>0&&fc<0)||(fa<0&&fc>0)) b=b;
}
}
}
void met_aproxsucces(){
float x[100];
float eps = 0.000001;
int iter;
cout<<"Introduceti x0= ";
cin>>x[0];
for(int i=1;i<100;i++){
x[i] =(x[i-1]*x[i-1]*x[i-1]-43)/26;

if((x[i]-x[i-1])<=eps){
iter = i;
cout<<"S-au facut "<<iter<<" iteratii"<<endl;
cout<<"x[i] = "<<x[i]<<endl;
break;
}
}
}
void met_newton(){
float x[100],fx,dfx;
float eps = 0.000001;
int iter;
cout<<"Introdu x0";
cin>>x[0];
for(int i=1; i<100; i++){

x[i] = x[i-1] - ((x[i-1]*x[i-1]*x[i-1]-26*x[i-1]-43)/(3*x[i-1]*x[i-1]-26));


if(abs(x[i]-x[i-1])<eps){
iter=i;
cout<<"S-au facut "<<iter<<" iteratii"<<endl;
cout<<"x"<<iter<<" = "<<x[i]<<endl;
break;
}}}
int main() {
int user_option;
while(1){
system("clear");
cout<<"1. Metoda injumatatirii intervalelor "<<endl;
cout<<"2.Metoda aproximatiilor succesive "<<endl;
cout<<"3.Metoda Newton "<<endl;
cin>>user_option;
switch(user_option){
case 1:
met_injumatatirii();
break;
case 2:
met_aproxsucces();
break;
case 3:
met_newton();
break;
}
}
return 0;
}
2)lg(1+x)+x-15=0
#include <iostream>
#include <cmath>

using namespace std;

void met_injumatatirii(){
float a,b,c,result,fa,fb,fc,eps;
int iter=0;
eps = 0.01;
cout<<"Introduceti intervalu [a,b]"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
while(iter!=100){
c = (a+b)/2;
iter++;

fa=log(10)*(1+a)+a-15;
fb=log(10)*(1+b)+b-15;
fc=log(10)*(1+c)+c-15;
if(fc==0||(abs(b-a)<2*eps)){
result = c;
cout<<"Rezultatul obtinut este "<<result<<endl;
cout<<"S-au facut "<<iter<<"iteratii"<<endl;
break;
}
else{
if((fa>=0&&fc>=0)||(fa<=0&&fc<=0)) a=c;
if((fa>0&&fc<0)||(fa<0&&fc>0)) a=a;
if((fb>=0&&fc>=0)||(fb<=0&&fc<=0)) b=c;
if((fb>0&&fc<0)||(fa<0&&fc>0)) b=b;
}
}
}
void met_aproxsucces(){
float x[100];
float eps = 0.000001;
int iter;
cout<<"Introduceti x0= ";
cin>>x[0];
for(int i=1;i<100;i++){
x[i] = (log(10)*(x[i-1]+1)+15);
if((x[i]-x[i-1])<=eps){
iter = i;
cout<<"S-au facut "<<iter<<" iteratii"<<endl;
cout<<"x[i] = "<<x[i]<<endl;
break;
}
}
}
void met_newton(){
float x[100],fx,dfx;
float eps = 0.000001;
int iter;
cout<<"Introdu x0";
cin>>x[0];
for(int i=1; i<100; i++){
fx=log(10)*(x[i-1]+1)+x[i-1]+1;
dfx=(1/log(10)*(x[i-1])+1);
x[i] = x[i-1] - fx/dfx;

if(abs(x[i]-x[i-1])<eps){
iter=i;
cout<<"S-au facut "<<iter<<" iteratii"<<endl;
cout<<"x"<<iter<<" = "<<x[i]<<endl;
break;
}}}
int main() {
int user_option;
while(1){
system("clear");
cout<<"1. Metoda injumatatirii intervalelor "<<endl;
cout<<"2.Metoda aproximatiilor succesive "<<endl;
cout<<"3.Metoda Newton "<<endl;
cin>>user_option;
switch(user_option){
case 1:
met_injumatatirii();
break;
case 2:
met_aproxsucces();
break;
case 3:
met_newton();
break;
}
}
return 0;
}
Concluzie:

n urma efecturii acestei lucrri de laborator, am acumulat experien n aflarea


rdcinilor unei ecuaii. Apoi din acest interval, am gasit soluia necesar. Am implementat toate
metodele n programul C++, i am aflat numrul de iteraii pentru fiecare metod, i ecuaie.

You might also like