I'd like to accumulate the total area between a curve and x-axis in one go if possible using a for loop. I find points of intersection first, then based on it and x1, x2 find total area, then graph at the end. This is my code:
dy2=-x^2-2*x; x1=-3; x2=2;
Based on the points of intersection, I'd like to calculate area with bounds of integration starting with x1, go through the points of intersections, end at x2. Can I do the code below using a loop?
A1=abs(int(dy2,x1,poi(1)));
A2=abs(int(dy2,poi(1),poi(2)));
A3=abs(int(dy2,poi(2),x2));
Below is a graph of the shaded area.
fp1 = fplot(dy1, [x1 x2]); hold on
fp2 = fplot(dy2, [x1 x2]); hold off
patch([x1 fliplr(x2)], [y1 fliplr(y2)], 'g');
j=xline(0); set(j,'color','black','Linewidth', 1.5);
k=yline(0); set(k,'color','black','Linewidth', 1.5);
Thanks.