Pascal/Turbo Pascal - Problema codigo ' suma de riemman simple '

 
Vista:

Problema codigo ' suma de riemman simple '

Publicado por Nicolas (1 intervención) el 03/01/2017 21:11:28
A continuación les dejo el código, es un trabajo que me pidieron hace días y no he podido terminar, consiste en realizar una suma de riemann simple, con la cual adquirir el área entre la curva y el eje de las abscisas en un intervalo previamente determinado, el problema es que no me da los resultados y segun yo el procedimiento esta bien, claramente tengo algún error y les agradecería su ayuda :(
pd: por temas de facilidad de calculo se permite que el lado que corresponde al eje x de cada rectangulo sea de lado 1 .
de antemano muchas gracias


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Program Riemann;
uses crt;       {usar limpiar pantalla}
 var    a, b, c, c1, x1, x2, p1, x3, x0 ,c2  {declaracion de variables}
         , suma, i, x4, abs1,r : integer ;
         resp :char;
 
Begin
clrscr;
repeat         {inicio bucle repeat}
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º        Este programa realiza la suma del area de    º');
 writeln('º            una funcion con respecto al eje x.       º');
 writeln('º                    de la forma                      º');
 writeln('º                  f(x):ax^2+bx+c                     º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
   {interaccion con el usuario}
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º   ingrese a.-  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 readln(a);
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º   ingrese b.-  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 readln(b);
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º   ingrese c.-  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 readln(c);
 {ingreso de intervalo}
 writeln('ingrese intervalo de evaluacion [A,B]');
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º   ingrese A.-  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 readln(x1);
x1:=p1;
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º   ingrese B.-  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 readln(x2);
x3:= x2-x1; {dimension del intervalo}
 suma:=0;
 for i :=0 to x3  do { inicio bluce for con condicion de termino}
  begin
  x0:=sqr(x1) ;        {desglose de operatoria en la funcion}
   c1:= a*x0+b*x1+c ;
   abs1:= abs(c1);
   suma:=suma+abs1;      {acumulador}
  x1:= x1+1;       {contador}
  end;
  clrscr;
  {se presenta el intervalo y el resultado de la operacion}
 writeln('Intervalo [',p1,',',x2,']');
 writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
 writeln('º  El area total bajo la curva es : ',suma,'u^2  º');
 writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
 writeln('¨ Deseas Volver a calcular ? [ s / n ]');
   readln(resp);
     {consulta del ciclo repeat}
   until (resp='N') or (resp='n') ;
{fin del programa}
end.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de alex
Val: 4
Ha aumentado su posición en 9 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

<a href="#">Problema codigo " suma de riemman simple "</a>

Publicado por alex (2 intervenciones) el 05/01/2017 03:56:32
Espero ayudar con esta modificación aunque se puede mejorar, puesto que los resultados reales se pueden mostrar sin notación científica con solo dos decimales
pd. entre "n" sea mas grande la aproximación del área debajo la curva sera mejor. yo utilice 1000 en adelante en mis pruebas


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Program Riemann;
uses crt;       {usar limpiar pantalla}
 var    a, b, c, p1 ,c2  {declaracion de variables}
         , i, x4,r : integer ;
         resp :char;
        x1,x3,c1,suma,abs1,x0,x2:real;
Begin
clrscr;
repeat         {inicio bucle repeat}
 writeln('ÉIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII»');
 writeln('º        Este programa realiza la suma del area de    º');
 writeln('º            una funcion con respecto al eje x.       º');
 writeln('º                    de la forma                      º');
 writeln('º                  f(x):ax^2+bx+c                     º');
 writeln('EIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII¼');
   {interaccion con el usuario}
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese a.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(a);
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese b.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(b);
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese c.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(c);
 {ingreso de intervalo}
 writeln('ingrese intervalo de evaluacion [A,B]');
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese A.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(x1);
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese B.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(x2);
 writeln('ÉIIIIIIIIIIIIIIII»');
 writeln('º   ingrese n.-  º');
 writeln('EIIIIIIIIIIIIIIII¼');
 readln(p1);
x3:= (x2-x1)/ p1; {dimension del intervalo}
x0:=x1;
 suma:=0;
 for i :=0 to p1  do { inicio bluce for con condicion de termino}
  begin
  x0:=x0+x3;        {desglose de operatoria en la funcion}
   c1:= (a*sqr(x0)+b*x0+c)*x3;
   abs1:= abs(c1);
   suma:=suma+abs1;      {acumulador}
  end;
  clrscr;
  {se presenta el intervalo y el resultado de la operacion}
 writeln('Intervalo [',x1,',',x2,']');
 writeln('ÉIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII»');
 writeln('º  El area total bajo la curva es : ',suma,'u^2  º');
 writeln('EIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII¼');
 writeln('" Deseas Volver a calcular ? [ s / n ]');
   readln(resp);
     {consulta del ciclo repeat}
   until (resp='N') or (resp='n') ;
{fin del programa}
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar