I have a problem with my algorithm. The purpose of the program is to calculate the area under the curve of a function by means of the Riemann method. The error is in the lower sum. since at the moment of being taking out the areas of the triangles, what I did is to multiply by and, but the monent to give the calculation is inaccurate. They could help me, and look for everything goolge and I can not find an example. I have suspicions that it has to be with an if you compare y. But I can not think of how. I'm a noob. Thanks.
pd: An example is: Lower limit: 4. Upper limit: 10. Number of rectangles: 3.
Correct answer: 76. Program response: 112
Analysis: It is giving me 36 more, since x = 6 is 36, but when x = 7 is 36. then it should not add that y. Greetings
#include <stdlib.h>
#include <stdio.h>
int main(){
float limiteMinimo,limiteMaximo;
int rectangulos;
float ancho;
float x,y;
float area;
printf("\nEste programa calculara el %crea de la funci%cn: y = -(x-7)^2 +19 \n",160,162);
printf("en los intervalos de 2.68 a 11.32 \n\n");
printf("Ingrese el l%cmite m%cnimo: ",161,161);
scanf("%f",&limiteMinimo);
printf("Ingrese el l%cmite m%cximo: ",161,160);
scanf("%f",&limiteMaximo);
printf("\nIngrese el n%cmero de segmentos (rect%cngulos) enteros: ",163,160);
scanf("%d",&rectangulos);
system("cls");
printf("\n**Suma inferior**\n\n");
printf("Datos: L%cmite m%cnimo: %.2f \n ",161,161,limiteMinimo);
printf(" L%cmite m%cximo: %.2f \n ",161,160,limiteMaximo);
printf(" N%cmero de segmentos: %d \n ",163,rectangulos);
ancho = (limiteMaximo - limiteMinimo)/rectangulos;
printf("\n Ancho: %.2f\n\n",ancho);
for( x=limiteMinimo ; x<=limiteMaximo ; x=x+ancho ){
y= -((x-7)*(x-7))+19;
area = area + (ancho*y);
}
printf("\nEl area es: %.2f \n\n",area);
system("pause");
return 0;
}