Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a recursive method to compute the following series: f(n)=1-1/2+1/3-1/4+…+(

ID: 3634650 • Letter: W

Question

Write a recursive method to compute the following series:
f(n)=1-1/2+1/3-1/4+…+(-1)^(n+1) *1/n

The recursive formula is: f(n)= f(n-1) + (-1)^(n+1) *1/n

Use the class BigDecimal for representing these elements of the series.
Write a test main method for this series that enumerates all the elements of the series up to the 100th element.
Remember the elements of the series in an array, so that elements are not recomputed.
Note: Remember the elements of the series in an array, so that elements are not recomputed.

Explanation / Answer

Please Rate:Thanks

please indicate that the program you need in which language?

Iam writing this code in java. please find. Thanks

 

public class BigDecimal {
    public static void main(String[] args){
        double[] big;
        big=new double[100];
        for(int i=1;i<=100;i++)
            big[i-1]=computef(i);
            for(int i=1;i<=100;i++){
        System.out.println("f("+i+") = "+big[i-1]);
    }}
    public static double computef(int n){
        if(n==1)
            return 1.0;
        else
            return Math.pow((-1),(n-1))*1/n+computef(n-1);
    }
   
}

------------------------------------------------------------------------------------------

Output:


f(1) = 1.0
f(2) = 0.5
f(3) = 0.8333333333333333
f(4) = 0.5833333333333333
f(5) = 0.7833333333333332
f(6) = 0.6166666666666666
f(7) = 0.7595238095238095
f(8) = 0.6345238095238095
f(9) = 0.7456349206349207
f(10) = 0.6456349206349207
f(11) = 0.7365440115440116
f(12) = 0.6532106782106782
f(13) = 0.7301337551337552
f(14) = 0.6587051837051838
f(15) = 0.7253718503718505
f(16) = 0.6628718503718505
f(17) = 0.7216953797836152
f(18) = 0.6661398242280596
f(19) = 0.718771403175428
f(20) = 0.6687714031754279
f(21) = 0.7163904507944756
f(22) = 0.6709359053399302
f(23) = 0.7144141662094954
f(24) = 0.6727474995428288
f(25) = 0.7127474995428288
f(26) = 0.6742859610812904
f(27) = 0.7113229981183273
f(28) = 0.6756087124040416
f(29) = 0.7100914710247312
f(30) = 0.6767581376913979
f(31) = 0.7090162022075269
f(32) = 0.6777662022075269
f(33) = 0.7080692325105572
f(34) = 0.6786574678046748
f(35) = 0.7072288963761034
f(36) = 0.6794511185983256
f(37) = 0.7064781456253526
f(38) = 0.6801623561516684
f(39) = 0.7058033817926941
f(40) = 0.6808033817926941
f(41) = 0.7051936256951331
f(42) = 0.6813841018856093
f(43) = 0.7046399158390977
f(44) = 0.681912643111825
f(45) = 0.7041348653340472
f(46) = 0.6823957348992646
f(47) = 0.7036723306439455
f(48) = 0.6828389973106122
f(49) = 0.7032471605759183
f(50) = 0.6832471605759183
f(51) = 0.7028550037131732
f(52) = 0.683624234482404
f(53) = 0.7024921590107058
f(54) = 0.6839736404921873
f(55) = 0.7021554586740055
f(56) = 0.6842983158168626
f(57) = 0.7018421754659854
f(58) = 0.6846007961556405
f(59) = 0.7015499486980133
f(60) = 0.6848832820313466
f(61) = 0.7012767246542975
f(62) = 0.685147692396233
f(63) = 0.7010207082692488
f(64) = 0.6853957082692488
f(65) = 0.7007803236538641
f(66) = 0.685628808502349
f(67) = 0.7005541816366774
f(68) = 0.6858482992837363
f(69) = 0.7003410529069246
f(70) = 0.6860553386212104
f(71) = 0.7001398456634639
f(72) = 0.686250956774575
f(73) = 0.6999495869115613
f(74) = 0.6864360733980478
f(75) = 0.6997694067313811
f(76) = 0.686611511994539
f(77) = 0.699598524981552
f(78) = 0.6867780121610392
f(79) = 0.6994362400091404
f(80) = 0.6869362400091404
f(81) = 0.6992819190214861
f(82) = 0.6870867970702665
f(83) = 0.6991349898413509
f(84) = 0.687230227936589
f(85) = 0.698994933818942
f(86) = 0.6873670268421977
f(87) = 0.698861279715761
f(88) = 0.6874976433521246
f(89) = 0.6987335984083044
f(90) = 0.6876224872971933
f(91) = 0.6986114982862043
f(92) = 0.6877419330688129
f(93) = 0.6984946212408559
f(94) = 0.6878563233685155
f(95) = 0.6983826391579893
f(96) = 0.6879659724913226
f(97) = 0.6982752508418381
f(98) = 0.688071169209185
f(99) = 0.698172179310195
f(100) = 0.688172179310195
BUILD SUCCESSFUL (total time: 1 second)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote