why get different values when matlab also use maple for calculation?. Maple vs Matlab??
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have this problem where the maple show very small result but matlab show very large value. I have written the code in Maple and Matlab. I'm working on this from last 4 days and didn't find any result, why this is happening.
Thank you in advance and please share if you know the reason behind this difference.
n,m,omega1 are real numbers n>m, n and m are integer, omega>0, n=m+2, and m is any odd no.s greater then 2.
%%%%%% MATLAB CODE
clc; clear; close;
n=5;m=3;omega1=500;
fun_matlab=(omega1*gamma(n/2)*gamma(m/2 + 1)*hypergeom(m/2 + 1, [3/2, 1 - n/2], omega1^2/4))/(2*gamma(m/2 + n/2 + 1)) + (omega1*omega1^n*pi^(1/2)*gamma(-n/2)*hypergeom(m/2 + n/2 + 1, [n/2 + 1, n/2 + 3/2], omega1^2/4))/(4*2^n*gamma(n/2 + 3/2));
fun_matlab = 6.575169876935467e+209
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% MAPLE CODE
restart; Digits:=500: n:=5: m:=3: omega1:=500:
Fun_maple:=evalf((omega1*GAMMA(n/2)*GAMMA(m/2 + 1)*hypergeom([m/2 + 1], [3/2, 1 - n/2], omega1^2/4))/(2*GAMMA(m/2 + n/2 + 1)) + (omega1*omega1^n*Pi^(1/2)*GAMMA(-n/2)*hypergeom([m/2 + n/2 + 1], [n/2 + 1, n/2 + 3/2], omega1^2/4))/(4*2^n*GAMMA(n/2 + 3/2)));
Fun_maple := -1.81414220781335980673653067232748014592172464361706594606931258364*10^(-209)
2 Kommentare
Antworten (1)
Walter Roberson
am 24 Dez. 2021
fun_matlab=(omega1*gamma(n/2)*gamma(m/2 + 1)*hypergeom(m/2 + 1, [3/2, 1 - n/2], omega1^2/4))/(2*gamma(m/2 + n/2 + 1)) + (omega1*omega1^n*pi^(1/2)*gamma(-n/2)*hypergeom(m/2 + n/2 + 1, [n/2 + 1, n/2 + 3/2], omega1^2/4))/(4*2^n*gamma(n/2 + 3/2));
n and m are double precision. omega is double precision. The gamma() calls are being evaluated at double precision, and your hypergeom() calls are being evaluated at double precision. Double precision is not accurate enough for your purposes.
3 Kommentare
Walter Roberson
am 24 Dez. 2021
Bearbeitet: Walter Roberson
am 24 Dez. 2021
sqrt(pi) was also a problem.
n = sym(5); m = sym(3); omega1 = sym(500);
Pi = sym(pi);
fun_matlab = (omega1*gamma(n/2)*gamma(m/2 + 1)*hypergeom(m/2 + 1, [3/2, 1 - n/2], omega1^2/4))/(2*gamma(m/2 + n/2 + 1)) + (omega1*omega1^n*Pi^(1/2)*gamma(-n/2)*hypergeom(m/2 + n/2 + 1, [n/2 + 1, n/2 + 3/2], omega1^2/4))/(4*2^n*gamma(n/2 + 3/2));
string(fun_matlab)
double(vpa(fun_matlab,500))
But if your question is whether it can be done in double precision in MATLAB, then I doubt it. The calculation involves cosh(500) and sinh(500) which are about 10^216 and differ by about 10^-218 so you would need more than 434 digits of precision.
John D'Errico
am 24 Dez. 2021
Bearbeitet: John D'Errico
am 24 Dez. 2021
Even if you use the symbolic toolbox, with everything in sym form, a large value is still produced, not the infinitessimally small one apparently produced from Maple.
n=sym(5);m=sym(3);omega1=sym(500);
digits 5000
fun_matlab=(omega1*gamma(n/2)*gamma(m/2 + 1)*hypergeom(m/2 + 1, [3/2, 1 - n/2], omega1^2/4))/(2*gamma(m/2 + n/2 + 1)) + (omega1*omega1^n*pi^(1/2)*gamma(-n/2)*hypergeom(m/2 + n/2 + 1, [n/2 + 1, n/2 + 3/2], omega1^2/4))/(4*2^n*gamma(n/2 + 3/2));
vpa(fun_matlab)
double(fun_matlab)
It is different from that which MATLAB produced without the aid of syms though.
Siehe auch
Kategorien
Mehr zu Numbers and Precision finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!