Cody

Problem 46025. Evaluate the gamma function

Solution 2660459

Submitted on 6 Jul 2020 by Tim
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
z = 3+2i; y = gamma2(z); y_correct = -0.4226372863112003 + 0.871814255696503i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

2   Pass
z = 1+i; y = gamma2(z); y_correct = 0.4980156681183556 -0.1549498283018104i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

3   Pass
z = (1+i)/2; y = gamma2(z); y_correct = 0.818163995 - 0.7633138287i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

4   Pass
z = i; y = gamma2(z); y_correct = -0.154949828301810 - 0.4980156681183566i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

5   Pass
z = 5i; y = gamma2(z); y_correct = -0.00027170388350615125 + 0.0003399328988721375i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

6   Pass
z = 1/2 + 14.1i; y = gamma2(z); y_correct = -2.0555298837259187e-10 - 5.667644214210669e-10i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

7   Pass
z = -1+i; y = gamma2(z); y_correct = -0.1715329199082727 + 0.3264827482100833i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

8   Pass
z = -2-3i; y = gamma2(z); y_correct = -0.0001631724182726072 - 0.001128495917017955i; assert(abs((real(y)-real(y_correct))/real(y_correct)) < 1e-6) assert(abs((imag(y)-imag(y_correct))/imag(y_correct)) < 1e-6)

9   Pass
z = 10*(rand+0.02); y_correct = gamma(z); assert(abs(gamma2(z)-y_correct)/y_correct < 1e-6)

Suggested Problems

More from this Author50

Community Treasure Hunt

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

Start Hunting!