Azzera filtri
Azzera filtri

How to vectorize integral2?

4 visualizzazioni (ultimi 30 giorni)
祥宇 崔
祥宇 崔 il 10 Apr 2023
Commentato: 祥宇 崔 il 10 Apr 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?

Risposta accettata

Walter Roberson
Walter Roberson il 10 Apr 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 Commenti
Walter Roberson
Walter Roberson il 10 Apr 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)
祥宇 崔
祥宇 崔 il 10 Apr 2023
Thanks a lot!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by