How to comute double integral of a long symbolic vector through parallel computing in Matlab?
4 views (last 30 days)
Show older comments
Is there other ways to comute the double integral of a long symbolic vector through parallel computing in Matlab, except parfor?
e.g. double integral of f over -1<x<1, -1<y<1.
clear
syms x y
f=[sin(x*y), x*y, x^5, y/x^(1/9), sin(x*y)/y, sin(x*y)^3/x*y]
1 Comment
Torsten
on 1 Oct 2022
Edited: Torsten
on 1 Oct 2022
Maybe it helps for the underlying task that
integral_{x=-1}^{x=1} integral_{y=-1}^{y=1} legendreP(x',i) * legendreP(y',j) dx' dy' = 0 for i,j not both 0,
integral_{x=-1}^{x=1} integral_{y=-1}^{y=1} legendreP(x',i) * legendreP(y',j) dx' dy' = 4 for (i,j) = (0,0).
Answers (1)
John D'Errico
on 1 Nov 2022
Edited: John D'Errico
on 1 Nov 2022
In general, you cannot force the symbolic toolbox to use multi-threaded computations. At least, the last time I recall, that was true. Those computations are not possible to directly parallelize. However, as you apparently know, you COULD use parfor. So you could set each computation up, then handled by one core at a time. And since you will have multiple cores at your command, that should not be a problem as long as you have the parallel computing toolbox AND you have the hardware to support it.
But if it is a symbolic result that you need, then no, you cannot use multiple threads. There is no easy way to magically speed up such a symbolic computation. Sorry.
If your goal is a PURELY numerical result, POSSIBLY you could use tool to perform numerical integrations that are not adaptive. For example, you COULD just evluate each function on the same grid of points, then use trapezoidal integration in two dimensions. Easy.
But even there, you will see problems. Some of the functions you show are considerably more complicated than others. And an adaptive tool like integral is smart enough to see where stuff is happening, and then throw more resources at it. So if some of your functions are trivially easy to integrate on a rectangular domains, say x*y, then a double trapezoidal rule with only a few nodes will be entirely adequate. Or you could use a slightly higher order rule, perhaps Simpson's rule, in 2-d. But there will be some functions that may be simply too high an implicit order for a low order rule like trapezoidal rule to be sufficient.
Could you do something more sophisticated? For example, you could use a lower order rule, say Simpson's rule, and then the same on a more finely sub-divided grid. Now use a Richardson extrapolation, decide if the extrpolant yields a better estimate, if not, then sub-divide again, etc.
Or you could use tools like Gauss-Legendre rules one that domain.
So there are many ways you MIGHT decide to try to improve things, but some of them would easily get into some fairly sophisticated mathematics. It is not clear what you do and don't understand about numerical integration and such computations in general. (My guess is not a whole lot, since you are asking this question.)
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!