MATLAB: INTEGRAL AT THE AREA

qwe

Hello all,
Does anyone know how to integrate (x2*y3-x3*y2)+(y2-y3)*x+(x3-x2)*y; in MATLAB from domain x2 to x3 in X range and y2 to y3 in Y range?
Thanks!

Best Answer

First define a function. This function must be able to accept an array and return an array. That is to say, if y1 = f(x1) and y2 = f(x2), where x1 and x2 are scalars, the function must also return [y1,y2] for f([x1,x2]). Actually the inputs will tend to be dozens or hundreds of elements long. There is more than one way to define a function in MATLAB, but the quickest is with the @ symbol. When you write @(x,y) it means that what follows that will be a function of x and y. That is to say, x and y will be treated as names of the variables of the function, and MATLAB will not try to evaluate the expression right then and there. So, it looks to me like you want to
1. First define x2, x3, y2, and y3. These will be scalar values. For example,
x2 = 0;
x3 = 1;
y2 = 0;
y3 = pi;
2. Define
f = @(x,y) (x2*y3-x3*y2) + (y2-y3)*x + (x3-x2)*y
Normally, I would have told you to be sure to use .* instead of * because .* is element-by-element multiplication and * is matrix multiplication, but in this case you basically have an expression of the form a + b*x + c*y, where a, b, and c are scalars. When one argument is a scalar * and .* are the same operation. Note that if you want to change x2, x3, y2, or y3, you must define f again because when you create the function, it takes a snapshot of all the variables other than the arguments.
3. Perform the integral
integral2(f,x2,x3,y2,y3)