0% found this document useful (0 votes)
29 views4 pages

LABORATOARE 1,2 Rezolvarea Numerică A Ecuaţiilor Algebrice

This document describes three numerical methods - bisection, chord, and tangent (Newton's method) - to solve the equation cos(2x) - x^2 - 1/2 = 0. It provides the Matlab code for each method and steps to call the functions to find the solutions within an absolute error of 10^-5. Examples are given to find the solutions over different intervals. Exercises are provided to modify the code to stop after a maximum number of iterations set by the user and to apply the three methods to solve the equation x + 0.5*arctan(x) - 1 = 0.

Uploaded by

Stefan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

LABORATOARE 1,2 Rezolvarea Numerică A Ecuaţiilor Algebrice

This document describes three numerical methods - bisection, chord, and tangent (Newton's method) - to solve the equation cos(2x) - x^2 - 1/2 = 0. It provides the Matlab code for each method and steps to call the functions to find the solutions within an absolute error of 10^-5. Examples are given to find the solutions over different intervals. Exercises are provided to modify the code to stop after a maximum number of iterations set by the user and to apply the three methods to solve the equation x + 0.5*arctan(x) - 1 = 0.

Uploaded by

Stefan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LABORATOARE 1,2 Rezolvarea numerică a ecuaţiilor algebrice

1
Aplicaţie: Să se determine numeric soluţiile ecuaţiei cos(2 x)  x 2   0 cu eroarea absoluta eps  105 .
2
1. METODA BISECTIEI

Functiile Matlab:
function f=f(x)
f=cos(2*x)-x^2-1/2;
end

function rad=bisectie(a,b,eps)
rad=(a+b)/2;
i=1;
fid=fopen('bisectie.txt','w');
fprintf(fid,' i radacina |f(radacina)| \n');
fprintf(fid,'%3d %15.12f % 15.12f \n ',i,rad,abs(f(rad)));
while (b-a)>eps
if f(a)*f(rad)<0
b=rad;
else
a=rad;
end
rad=(a+b)/2;
i=i+1;
fprintf(fid,'%3d %15.12f % 15.12f \n ',i,rad,abs(f(rad)));
end
fclose(fid);
end

Pasi de rezolvare:
1. Se reprezinta grafic functia f(x) si se gasesc intervalele in
care se afla solutiile.
2. Se apeleaza functia bisectie.m in linia de comanda a Matlab-ului
dupa cum urmeaza:
>> rad=bisectie(-2,0,10^(-5))
>> rad=bisectie(0,2,10^(-5))

OBSERVATIE: Solutia numerica se va gasi in fisierul bisectie.txt


2. METODA COARDEI

Functiile Matlab:

function rad=coarda(a,b,eps)
x0=(a*f(b)-b*f(a))/(f(b)-f(a));
i=1;
fid=fopen('coarda.txt','w');
fprintf(fid,' i radacina |f(radacina)| \n');
fprintf(fid,' %3d %15.12f % 15.12f \n ',i,x0,abs(f(x0)));
if f(a)*f(x0)<0
b=x0;
else
a=x0;
end
i=i+1;
x1=(a*f(b)-b*f(a))/(f(b)-f(a));
if f(a)*f(x1)<0
b=x1;
else
a=x1;
end
fprintf(fid,' %3d %15.12f % 15.12f \n ',i,x1,abs(f(x1)));
while abs(x1-x0)>eps
x0=x1;
x1=(a*f(b)-b*f(a))/(f(b)-f(a));
if f(a)*f(x1)<0
b=x1;
else
a=x1;
end

i=i+1;
fprintf(fid,' %3d %15.12f % 15.12f \n ',i,x1,abs(f(x1)));
end
fclose(fid);
rad=x1;
end

Pasi de rezolvare:
1. Se reprezinta grafic functia f(x) si se gasesc intervalele in
care se afla solutiile.
2. Se apeleaza functia coarda.m in linia de comanda a Matlab-ului
dupa cum urmeaza:

>> rad=coarda(0,2,10^(-5))

OBSERVATIE: Solutia numerica se va gasi in fisierul coarda.txt


3. METODA TANGENTEI (Newton)

Functia Matlab:

function rad=tangenta(x0,eps)
syms x
f(x)=cos(2*x)-x^2-1/2;
df(x)=diff(f(x),x);
i=1;
x1=x0-double(f(x0)/df(x0));
fid=fopen('tangenta.txt','w');
fprintf(fid,' i radacina |f(radacina)| \n');
fprintf(fid,' %3d %15.12f % 15.12f \n ',i,x1,abs(double(f(x1))));
while abs(x0-x1)>eps
x0=x1;
x1=x0-double(f(x0)/df(x0));
i=i+1;
fprintf(fid,' %3d %15.12g\f %15.12f \n ',i,x1,abs(double(f(x1))));
end
rad=x1;
fclose(fid);
end

Pasi de rezolvare:
1. Se reprezinta grafic functia f(x) si se gasesc intervalele in
care se afla solutiile.
2. Se apeleaza functia tangenta.m in linia de comanda a Matlab-ului
dupa cum urmeaza:

>> rad=tangenta(1,10^(-5))

OBSERVATIE: Solutia numerica se va gasi in fisierul tangenta.txt

Exercitii: 1. Să se modifice functiile anterioare in asa fel incat procesele iterative sa se opreasca dupa un
numar maxim de iteratii definit de utilizator.
2. Sa se determine numeric solutiile ecuatiei x+0.5*arctg(x)-1=0 folosind metoda bisectiei, coardei
si tangentei.

You might also like