Você está na página 1de 10

INSTITUTO POLITÉCNICO NACIONAL

ESCUELA SUPERIOR DE INGENIERÍA MECÁNICA Y ELÉCTRICA

METODOS NUMERICOS

Examen de tercer parcial

ALUMNO:

GRUPO: 3EV6

1
1.- Calcule el valor de la integral definida de 0 a pi de la raiz de sen(x),utilizando el método de
Π
Simpson. ∫0 √𝑠𝑒𝑛𝑥

A≈ 2.094 ±0.053
Código fuente utilizado para método Simpson

#include <stdio.h> {
#include <conio.h> return sqrt(sin(X)); //AQUI SE PONE LA
FUNCION
#include <math.h>
}

void Lee_Datos()
double F(double X);
{
void Simpson_13();
//solo es necesario introducir el metodo
void Lee_Datos();
inferior ya que el superior ya esta definido
printf("METODO DE SIMPSON PARA
DETERMINAR EL AREA BAJO LA
double Av,A,B,Eror,Area; FUNCION\n");
int N,ND; printf(" Limite inferior de la integral A: ");
double Respuesta; scanf("%lf",&A);
double B=3.14159265; //B se define como printf(" Limite superior de la integral B:
constante global con el valor de PI PI \n");
int main() // scanf("%lf",&B);
{ printf(" Numero de Divisiones ND:
Av=180; ");

Lee_Datos(); scanf("%li",&ND);

N=2; }

Simpson_13(); void Simpson_13()

//SE CALCULA EL ERROR EN % Y SE {


IMPRIMEN RESULTADOS. double X,S1,S2,H;
Eror=fabs((pow((B-A),5)/2)/(pow(N,4)*Av)); int I;
printf("%10d\nel area es=%11.8f \nel error X=A; S1=0; S2=0; H=(B-A)/N;
es=+-%11.8f",N,Area,Eror);
X=X+H; S1=S1+F(X);
getch();
Area=H/3*(F(A)+4*S1+2*S2+F(B));
}
}
double F(double X)

2
3
2.- Utilice los siguientes datos para encontrar el polinomio de interpolación polinomial de Newton
y también encuentre el valor de
y en x = 19.

x y
------------
0 1 R=+0.000011
14 16
28 35
42 58
56 95

Código fuente utilizado


#include <stdio.h>

#include <malloc.h>

#include <stdlib.h>

struct punto{
double x;

double y;

};

int main()
{
struct punto * P; // El conjunto de puntos
int i, j, n, order;
double fdd[5][5];

double x, xterm, yint2, yint[5], Ea[5];

n = 5;

P = (struct punto *)malloc(n * sizeof(struct punto) );

if (P == NULL) {
printf("Error en asignación de memoria\n");

exit(1);

4
//Puntos en orden ascendente for(i = 0; i < n; i++)

(P+0)->x = 0.0; (P+0)->y = 1.0; printf("fdd[%i][0] = %+lf\n", i, fdd[i][0]);

(P+1)->x = 14.0; (P+1)->y = 16.0; for(j = 1; j < n; j++)


(P+2)->x = 28.0; (P+2)->y = 35.0; for(i = 0; i < n - j; i++)

(P+3)->x = 42.0; (P+3)->y = 58.0; printf("fdd[%i][%i] = %+lf\n", i, j, fdd[i][j]);

(P+4)->x = 56.0; (P+4)->y = 95.0; printf("\n");

printf("Tabla de puntos (x, y):\n");

printf("Interpolacion de printf(" x %c [i][0] %c [i][1] %c [i][2] %c


Newton\n\n"); [i][3] %c [i][4] \n", 179, 179, 179, 179, 179);
printf("Tabla de puntos (x, y):\n"); printf("---%c---------%c---------%c---------%c--
-------%c---------\n", 179, 179, 179, 179, 179);
printf(" x | y\n");
for(i = 0; i < n; i++) {
printf("----------|----------\n");
for(i = 0; i < n; i++)
printf("%3.1lf", (P+i)->x);
printf("%10.8lf|%10.8lf\n", (P+i)->x,
(P+i)->y); for(j = 0; j < n - i; j++)
printf("\n\n"); printf("%c%+8.6lf", 179, fdd[i][j]);

printf("%c\n", 179);
// Interpolación de Newton }

for(i = 0; i < n; i++) printf("\n\n");

fdd[i][0] = (P+i)->y;
for(j = 1; j < n; j++) free(P);

for(i = 0; i < n - j; i++) { return 0;

fdd[i][j] = (fdd[i+1][j-1] - fdd[i][j-1]) / ((P+i+j)- }


>x - (P+i)->x);
}

5
Para hallar y=19

6
3.- Calcule ln x = 2.5 usando

x y
----------------
1 0
1.5 0.405465 R ≈ 1.173597 con error de 28.08%
4.0 1.306294
5.5 1.704748

Código fuente utilizado.


#include <stdio.h>

b0 = y0;

int main() b1 = (y1 - y0)/(x1 - x0);


{ b2 = ((y2-y1)/(x2-x1) - (y1-y0)/(x1-x0))/(x2-
x0);
double x0, y0, x1, y1, x2, y2,x3,y3;
b3= ((y3-y2)/(x3-x2) - (y2-y1)/(x2-x1)-(y1-
double b0, b1, b2,b3, x, y;
y0)/(x1-x0)/(x2-x0))/(x3-x0);
y = b0 + b1*(x - x0) + b2*(x - x0)*(x -
printf("Interpolacion polinominal\n\n"); x1)+b3*(x-x0)*(x-x1)*(x-x2);

printf("Ingresa las coordenadas de x0: "); printf("Tabla de valores:\n");

scanf("%lf %lf", &x0, &y0); printf(" x | y\n");

printf("--------------\n");

printf("Ingresa las coordenadas de x1: "); printf("%5.3lf |%8.6lf\n", x0, y0);

scanf("%lf %lf", &x1, &y1); printf("%5.3lf |%8.6lf\n", x1, y1);

printf("%5.3lf |%8.6lf\n", x2, y2);

printf("Ingresa las coordenadas de x2: "); printf("%5.3lf |%8.6lf\n", x3, y3);

scanf("%lf %lf", &x2, &y2); printf("--------------\n\n");

printf("Ingresa las coordenadas de x3: ");

scanf("%lf %lf", &x3, &y3); printf("Tabla con punto calculado:\n");

printf(" x | y\n");

printf("Ingresa un valor de x: "); printf("--------------\n");

scanf("%lf", &x); printf("%5.3lf |%8.6lf\n", x0, y0);

7
printf("%5.3lf |%8.6lf\n", x, y); ErrRel = fabs(ValorExacto - y)/ValorExacto;

printf("%5.3lf |%8.6lf\n", x1, y1); printf("Error Relativo = %lf%%\n\n", ErrRel


* 100.0);
printf("%5.3lf |%8.6lf\n", x2, y2);

printf("%5.3lf |%8.6lf\n", x3, y3);


printf("Presiona Enter...");
printf("--------------\n");
getchar();
}
double ErrRel, ValorExacto = 0.916290;

8
4.- Usando interpolación cuadrática de Lagrange, encuentre el
polinomio P_2(x) y el valor de y en x=5,
dados y(0) = 13, y(1) = 59 y y(5) = 89 R=-1.800000

Código fuente utilizado


#include <stdio.h>

#include <malloc.h> // Ingresamos los puntos


#include <stdlib.h> for(i = 0; i < n; i++) {

printf("Ingresa (x, y) para el punto %i : ",


i+1);
struct punto{
scanf("%lf %lf", &((P+i)->x), &((P+i)->y));
double x;
}
double y;
};
printf("\nTabla de puntos (x, y):\n");
printf(" x | y\n");
int main()
printf("----------|----------\n");
{
for(i = 0; i < n; i++)
int i, j, n;
printf("%10.8lf|%10.8lf\n", (P+i)->x,
double x;
(P+i)->y);
struct punto * P; // El conjunto de puntos

double * L; // Funciones base de


printf("\n\n");
Interpolacion de Lagrange

// Funciones base de interpolación de


printf("Ingrese el numero de puntos : ");
Lagrange
scanf("%i", &n);
printf("Ingresa el valor de i : ");

scanf("%i", &i);
P = (struct punto *)malloc(n * sizeof(struct
printf("Calcularemos L_%i\n", i);
punto) );

if (P == NULL) {
L = (double *)malloc(n * sizeof(double));
printf("Error en asignación de
memoria\n"); if(L == NULL) {

exit(1); printf("Error en asignación de


memoria\n");
}

9
exit(1); }

} printf("\n\n");
// Código fuente para el producto double z = 0.0;

printf("L%i = ", i); for(i = 0; i < n; i++) {

for(j = 0; j < n; j++) { printf("L%i = ", i);

if(j == i) for(j = 0; j < n; j++) {


continue; if(j == i)

printf("(x - x[%i])/(x[%i] - x[%i]) * ", j, i, j); continue;

} z = (x -(P+j)->x)/((P+i)->x - (P+j)->x);
printf("\n\n"); }

printf("Ingresa el punto x a calcular : "); printf("%lf\n", z);


scanf("%lf", &x); }
printf("L%i = ", i); printf("\n\n");
for(j = 0; j < n; j++) { free(L);

if(j == i) free(P);

continue; printf("Presione Enter...");

printf("(%lf - %lf)/(%lf - %lf) * ", getchar();

x, (P+j)->x, (P+i)->x, (P+j)->x); }

10

Você também pode gostar