Borrar filtros
Borrar filtros

How to vectorize integral2?

4 visualizaciones (últimos 30 días)
祥宇 崔
祥宇 崔 el 10 de Abr. de 2023
Comentada: 祥宇 崔 el 10 de Abr. de 2023
We can use 'integral' for twice only when these two variables are independent to each other. And then the option 'Arrayvalued' could be used then. But what if we can't seperate them? For instance:
fun = @(n,x,y) sin(n*x-y).*sqrt(x-n*y);
for i=1:1e3
integral2(@(x,y) fun(i,x,y),0,2*pi,0,2*pi);
end
Is there anaway to speed it up by vectorizing it?

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Abr. de 2023
No, there is no way to speed that up by vectorizing.
In general, if you have multiple functions to calculate at the same time, then they might well have different convergence properties. integral2() would have no way of splitting up a vector-valued function into its different components, so if it did support vector-valued functions, it would end up having to evaluate every segment according to the worst convergence over that segment.
  2 comentarios
Walter Roberson
Walter Roberson el 10 de Abr. de 2023
By the way, under the assumption that n is a positive integer, there does turn out to be a closed form solution
-pi^(1/2)*(-n^3*(fresnels(2/n^(1/2))-fresnels((-2*n+2)^(1/2)/n^(1/2)*2^(1/2)))* ...
cos((2*n^2-2)*pi/n)-n^3*(fresnelc(2/n^(1/2))-fresnelc((-2*n+2)^(1/2)/n^(1/2)* ...
2^(1/2)))*sin((2*n^2-2)*pi/n)+1i*n^3*fresnels(2)+fresnels(2*1i*n)+...
fresnels(2*n^(1/2))-fresnels((-2*n+2)^(1/2)*2^(1/2)*n^(1/2)))/n^(3/2)*2^(1/2)/(2*n^2-2)
祥宇 崔
祥宇 崔 el 10 de Abr. de 2023
Thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by