gamma function error in calculation

% Starting value
The above formula is coded as follows:
syms x a
Y=sym(zeros(1));
Y(1)=0;
a=1/2
for i=1:4
if i==5
A=1
else
A=0
end
if i==4
B=1
else
B=0
end
Y(i+1)=simplify((gamma(a*(i-1)+1)/gamma((a*(i-1)+3/2))*(A-Y(i)+((2*B)/gamma(5/2)))));
end
disp(Y)
But it is showing the calculation error Y(5)=1 but the value is shown in MATLAB is as follows:('2535301200456458897054207582575/2535301200456458802993406410752'). Ecxept Y(5) all values are zeros

回答 (1 件)

VBBV
VBBV 2022 年 4 月 16 日

0 投票

syms x a
Y=sym(zeros(1));
Y(1)=0;
a=1/2
a = 0.5000
for i=1:4
if i==5
A=1;
B = 0;
Y(i+1)=simplify((gamma(a*(i-1)+1)/gamma((a*(i-1)+3/2))*(A-Y(i)+((2*B)/gamma(5/2)))));
else
A=0;
B =1 ;
Y(i+1)=simplify((gamma(a*(i-1)+1)/gamma((a*(i-1)+3/2))*(A-Y(i)+((2*B)/gamma(5/2)))));
end
if i==4
B=1;
A = 0;
Y(i+1)=simplify((gamma(a*(i-1)+1)/gamma((a*(i-1)+3/2))*(A-Y(i)+((2*B)/gamma(5/2)))));
else
B=0;
A = 1;
Y(i+1)=simplify((gamma(a*(i-1)+1)/gamma((a*(i-1)+3/2))*(A-Y(i)+((2*B)/gamma(5/2)))));
end
end
A = 0
B = 0
A = 1
A = 0
B = 0
A = 1
A = 0
B = 0
A = 1
A = 0
B = 1
disp(vpa(Y,4))

3 件のコメント

VBBV
VBBV 2022 年 4 月 16 日
For each if condition , there are few unknown variables e.g. either A or B in the equation.
So, to compute whole equaton for each iteration, values have to be defined with A and B or computed to get final matrix Y.
yogeshwari patel
yogeshwari patel 2022 年 4 月 17 日
The correct value are Y(1)=0; Y(2)=0;Y(3)=0, Y(4)=0, Y(5)=1 and rest value s are zero. Now if I work with pen and paper the values are same as I mention above but when I work with MATLAB code the value of Y(5)=2535301200456458897054207582575/2535301200456458802993406410752 .Why that error is appaering
Torsten
Torsten 2022 年 4 月 17 日
You mix symbolic and floating point parameters in the calculation of Y(5). This will result in reduced accuracy.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGamma Functions についてさらに検索

タグ

質問済み:

2022 年 4 月 16 日

コメント済み:

2022 年 4 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by