How to vectorize integral2?
조회 수: 4 (최근 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?
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!