How to explain a difference in solutions of integrals between MATLAB and MAPLE?

Dear community,
after solving an integral via MAPLE 2022 (see the solution in blue),
I tried to reproduce the calculation in MATLAB R2021b as a numerical and symbolic expression:
%% integral: numerical expression
%empirical coefficents
vrel = 0.000018;
alpha = 0.08;
beta = -6.75;
h =1;
d =1;
%function
fun = @(theta) (alpha*beta*cos(theta).^4).*(pi*d-8*beta*vrel*cos(theta).^2).^(-2);
%integral
F = integral(fun,0,pi/2)
F = -0.0322
%% integral: symbolic expression
%system parameters
syms theta alpha beta d vrel
%function
fun = (alpha*beta*cos(theta).^4).*(pi*d-8*beta*vrel*cos(theta).^2).^(-2);
%substiution of empirical coefficents
fsub = subs(fun,{alpha, beta, d, vrel}, {0.0814,-6.75,1,0.000018});
%integral
f = int(fsub,theta,0,pi/2);
%evaluation for complex number
c = subs(f, 1+i);
F = double(c)
F = -0.0328
However, the solution between MATLAB and MAPLE differs by 8 magnitudes. My colleauge and me double-checked for typos but couldn't figure out any. I verified the result from MAPLE via comparison to a simplfied solution for the integral.
I am curious to learn about my mistake(s) when adapting the integral into MATLAB!

댓글 수: 3

Hi, I'd suggest to plot the function you are trying to integrete in both software tools. That way, you'll be able to spot if e.g. the software treats the angles in correct units, or operations order is correctly interpreted.
Hi Jiri,
thanks for your suggestion! I checked it, and it seems that both softwares evaluate the function correctly:
MAPLE:
MATLAB:
%empirical coefficents
vrel = 0.000018;
alpha = 0.08;
beta = -6.75;
h =1;
d =1;
%function
fun = @(theta) (alpha*beta*cos(theta).^4).*(pi*d-8*beta*vrel*cos(theta).^2).^(-2);
close all
figure
fplot(@(theta) fun(theta),[0 1.6])
After following @Jiri Hajek's suggestion one gets a smoothly varying curve starting at approximately -0.054 at theta=0 that aproaches zero at pi/2. This curve is everywhere in this interval 0<theta<=1 under the line y = -0.05 + 0.05*x. Therefore the integral has to have a smaller value than the area of the triangle with corners at [0,0], [0,-0.05] and [1,0] which should be -0.05*1/2 or -0.025.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jiri Hajek
Jiri Hajek 2022년 11월 10일
Nicely done graphs! So, just by looking at the graphs, it is clear that:
  • The integral of your function is a negative value, with lower limit on the value being the area of the graph, i.e. about 1,6x(-0,05)= - 0,08
  • Comparing your original results from MATLAB with the above, it seems that both provide good estimates, although it remains to see which one is more precise
  • The MAPLE result is a complete nonsense, 8 orders of magnitude off the target.You have to search for error in your MAPLE implementation, not in MATLAB.

댓글 수: 1

I will try to figure out why my maple solution is incorrect - but this does not belong here.
Thanks Jiri!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2022년 11월 10일

댓글:

2022년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by