Permalink
Browse files

Added charts

  • Loading branch information...
1 parent 17b66eb commit 6d787494bed0c9f60d4475508ffe651b6a00a0a5 @gnuvince committed Mar 30, 2011
View
@@ -0,0 +1,22 @@
+p5
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p4, from=0, to=3*pi, add=TRUE, col="green")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p5, from=0, to=3*pi, add=TRUE, col="green")
+?pdf
+pdf("p1.pdf")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p1, from=0, to=3*pi, add=TRUE, col="green")
+pdf("p2.pdf")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p2, from=0, to=3*pi, add=TRUE, col="green")
+pdf("p3.pdf")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p3, from=0, to=3*pi, add=TRUE, col="green")
+pdf("p4.pdf")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p4, from=0, to=3*pi, add=TRUE, col="green")
+pdf("p5.pdf")
+plot(sin, from=0, to=3*pi, ylim=c(-5, 5))
+curve(p5, from=0, to=3*pi, add=TRUE, col="green")
+n
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,36 @@
+p1 <- function(x) {
+ +3.89817e-17*(x - 0)+0
+}
+p2 <- function(x) {
+ +0.0450316*(x - 0)*(x - 4.71239)-0.212207*(x - 0)+0
+}
+p3 <- function(x) {
+ +7.89935e-18*(x - 0)*(x - 3.14159)*(x - 6.28319)-2.48165e-17*(x - 0)*(x - 3.14159)+3.89817e-17*(x - 0)+0
+}
+p4 <- function(x) {
+ -0.0157589*(x - 0)*(x - 2.35619)*(x - 4.71239)*(x - 7.06858)+0.074262*(x - 0)*(x - 2.35619)*(x - 4.71239)-0.217432*(x - 0)*(x - 2.35619)+0.300105*(x - 0)+0
+}
+p5 <- function(x) {
+ -1.86623e-18*(x - 0)*(x - 1.88496)*(x - 3.76991)*(x - 5.65487)*(x - 7.53982)-0.013297*(x - 0)*(x - 1.88496)*(x - 3.76991)*(x - 5.65487)+0.100257*(x - 0)*(x - 1.88496)*(x - 3.76991)-0.350388*(x - 0)*(x - 1.88496)+0.504551*(x - 0)+0
+}
+
+
+pdf("p1.pdf")
+plot(function(x) { abs(sin(x) - p1(x)) }, from=0, to=3*pi, ylim=c(-3, 3), main="Erreur avec polynôme ordre 1")
+dev.off()
+
+pdf("p2.pdf")
+plot(function(x) { abs(sin(x) - p2(x)) }, from=0, to=3*pi, ylim=c(-3, 3), main="Erreur avec polynôme ordre 2")
+dev.off()
+
+pdf("p3.pdf")
+plot(function(x) { abs(sin(x) - p3(x)) }, from=0, to=3*pi, ylim=c(-3, 3), main="Erreur avec polynôme ordre 3")
+dev.off()
+
+pdf("p4.pdf")
+plot(function(x) { abs(sin(x) - p4(x)) }, from=0, to=3*pi, ylim=c(-3, 3), main="Erreur avec polynôme ordre 4")
+dev.off()
+
+pdf("p5.pdf")
+plot(function(x) { abs(sin(x) - p5(x)) }, from=0, to=3*pi, ylim=c(-3, 3), main="Erreur avec polynôme ordre 5")
+dev.off()
View
@@ -18,6 +18,17 @@
\maketitle
+\section{Interpolation}
+
+\subsection{Graphes de l'erreur des polynômes d'interpolation}
+
+\includegraphics[scale=0.4]{data/p1}
+\includegraphics[scale=0.4]{data/p2}
+\includegraphics[scale=0.4]{data/p3}
+\includegraphics[scale=0.4]{data/p4}
+\includegraphics[scale=0.4]{data/p5}
+
+
\section{Intégration numérique}
\subsection{Description du problème et méthodes utilisées}
View
@@ -3,6 +3,8 @@
#include <math.h>
#define PI 3.14159265358979323846
+#define START 0
+#define END 3*PI
double fact(int);
double CalculateS(double, double, double, size_t);
@@ -83,7 +85,7 @@ Polynomial* InterpolationPolynomialNew(double (*f)(double), size_t degree,
/* Initialize table */
for (size_t i = 0; i <= degree; ++i) {
table[0][i] = (*f)(start + i*h);
- printf(" >> f(%.6lf) = %.6lf\n", (start + i*h), table[0][i]);
+ //printf(" >> f(%.6lf) = %.6lf\n", (start + i*h), table[0][i]);
}
/* Fill up the table */
@@ -93,12 +95,14 @@ Polynomial* InterpolationPolynomialNew(double (*f)(double), size_t degree,
}
}
+ /*
for (size_t i = 0; i <= degree; ++i) {
for (size_t j = 0; j <= degree - i; ++j) {
printf("%+.5lf\t", table[i][j]);
}
putchar('\n');
}
+ */
@@ -156,13 +160,9 @@ double f(double x) {
}
int main(void) {
- double start = 0.1;
- double end = 1.7;
-
for (size_t i = 1; i <= 5; ++i) {
- Polynomial *p = InterpolationPolynomialNew(&f, i, start, end);
- InterpolationPolynomialPrint(p, start, end);
- printf("%g %g\n", f(0.8), InterpolationPolynomialEval(p, 0.8, start, end));
+ Polynomial *p = InterpolationPolynomialNew(&f, i, START, END);
+ InterpolationPolynomialPrint(p, START, END);
PolynomialFree(p);
}

0 comments on commit 6d78749

Please sign in to comment.