How to make improper integrals in matlab and paint the area under the curve?

0

we must do a project in matlab we must enter a function and the limits so that the integral is improper and returns the graph with the value of the area under the curve, the problem is that we can not generate the graph correctly, walking online I found this fraction of code that generates a very good graphic but we do not understand how it works, could someone explain the operation? I know that the fill function is the one that graphs but I do not understand how the parameters pass.

clear all x1 = -5: 0.1: 10; y1 = x1. ^ 2;

x2 = x1; y2 = y1 * 0;

x3 = ones (1, length (x1)) * x1 (end); y3 = y1;

x = [x2 x3 x1 (end: -1: 1)]; y = [y2 y3 y1 (end: -1: 1)]; fill (x, y, 'r')

    
asked by Alex Albuja Andino 22.05.2018 в 06:34
source

1 answer

0

If you notice if you execute,

clear all; x1=-5:0.1:10; y1=x1.^2;
figure; fill(x1,y1,'r')

The area that is drawn is the opposite of the one you are looking for, then it is evident that the rest of the code is used to redefine the area that you want to color, that is, the area of the integral.

To do this with x2 and y2 you are turning MATLAB to consider the axis of the x as one of the boundaries of the area since x2 is equal to x1 and y2 is a row vector of zeros of as many elements as points a represent.

In the same way with x3 and y3, the x = 10 axis is redefined.

    
answered by 09.09.2018 в 17:10