How to vectorize integral2?

2 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2023-4-10
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 个评论
Walter Roberson
Walter Roberson 2023-4-10
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by