# I am not able to integrate heaviside(y-f) for x= 0 to pi/2 and y = 0 to pi/2 (only syms integration "int"). After running the code, output is shown in below and i am not able to get the numerical answer. Can you give some ideas on how to proceed?

8 visualizaciones (últimos 30 días)
Comentada: hosein Javan el 14 de Ag. de 2020
syms x y
f = sin(x);
integ = int( int(heaviside(y-f), x, 0, pi/2),y, 0, pi/2)
Result:
integ =
int(int(heaviside(y - sin(x)), x, 0, pi/2), y, 0, pi/2)
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Walter Roberson el 14 de Ag. de 2020
For your purposes, is heaviside(0) equal to 0, or is it equal to 1, or is it equal to 1/2, or is it undefined ?
Editada: CHINTALAPUDI GNANA SURYA NARAYANA SAI el 14 de Ag. de 2020
yes, it is heaviside(=0 or >0) equal to 1 and heaviside(<0) equal to 0.

Iniciar sesión para comentar.

### Respuesta aceptada

Walter Roberson el 13 de Ag. de 2020
Reverse the order of integration.
>> integ = int( int(heaviside(y-f), y, 0, pi/2),x, 0, pi/2)
integ =
pi^2/4 - 1
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (1)

hosein Javan el 13 de Ag. de 2020
if you need numerical integration, some functions cannot be easily evaluated by symbolic. instead use "integral". in here we have a double integral. the integral calculation method is 'iterated' which means on each iteration it is integrating on one dimension and then the next. it takes a few seconds to accomplish though.
fun = @(x,y) double( y > sin(x) )
q = integral2(fun, 0, pi/2, 0, pi/2, 'Method', 'iterated', 'Reltol', 1e-8)
% answer in command window:
q =
1.4674
here's your function plot. blue part is zero. yellow part equals one.
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
actually i need to do syms int type of integration, but as you suggested i will also look into integral2 command. Thank you very much.
hosein Javan el 14 de Ag. de 2020
you're welcome.

Iniciar sesión para comentar.

### Categorías

Más información sobre Calculus en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by