Speed of vpaintegral vs. int+vpa
Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here.Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here. Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here. integral, speed MATLAB Answers — New Questions