-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLagrange.cpp
More file actions
executable file
·41 lines (38 loc) · 839 Bytes
/
Lagrange.cpp
File metadata and controls
executable file
·41 lines (38 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Lagrange.cpp
* TrabMetodos
*/
#include "Lagrange.h"
#include <iostream>
Lagrange::Lagrange () : Interpolacao ()
{
}
Lagrange::~Lagrange ()
{
// Apaga da memória todos os objetos FuncaoLagrange do vetor
for (vector<FuncaoLagrange*>::iterator i = L.begin (); i != L.end (); ++i)
{
delete *i;
}
L.clear ();
}
string Lagrange::calcular ()
{
cout << "Funções parciais:" << endl;
// Gera as funções parciais de Lagrange L(x)
for (int i = 0; i < qtd; i++)
{
L.push_back ( new FuncaoLagrange (i, x, f) );
}
// Aplica a distributiva com os f(x)s para gerar o polinomio de aproxinação
polinomio = *L[0];
for (vector<FuncaoLagrange>::size_type i = 1; i < L.size (); i++)
{
polinomio = polinomio + *L[i];
}
return polinomio.toString ();
}
double Lagrange::plotar (double x)
{
return polinomio.plotar (x);
}