Question

In: Computer Science

(TestSumSeries.java) Write a recursive method that sums up the following series: s(i) = 1/1+ 3/3+3/5+5/7+⋯+ (i+1)/(2i+1)+(i+2)/(2i+1)...

(TestSumSeries.java) Write a recursive method that sums up the

following series:

s(i) = 1/1+ 3/3+3/5+5/7+⋯+ (i+1)/(2i+1)+(i+2)/(2i+1) i = 0, 1, 2, 3, … When i is even, the term is (i+1)/(2i+1) When i is odd, the term is (i+2)/(2i+1) In the main method, display the s(i) for i = 0, 1, 2, 3, 4, 5

Solutions

Expert Solution

Code Segment:

import java.io.*;

public class TestSumSeries{
 // Recursive method to compute sum of the series
  public static double series_sum(int i)
  {    

       // if i becomes negative stop adding, return 0
       if(i<0)
       return 0;


      // if i is non-negative, do the computation    
       else

       {

       // if i is even 
       if(i%2==0)
       {   
           // add the term corresponding to even i 
           return((double)(i+1)/(2*i+1) + series_sum(i-1));
       }

       // if i is odd
       else
       {  // add the term corresponding to odd i
          return((double)(i+2)/(2*i+1) + series_sum(i-1));
       }


        }


  }


  public static void main(String[] args) {
  
        double result;
    
    // loop from 0 to 5
        for(int i=0; i<=5;i++)
        { 
         // calling the series_sum method for every i from 0 to 5
     result = series_sum(i);

     // printing the result
        System.out.println("s("    + i   + ") =  " + result);
        System.out.println();

    }

}

}

Output:


Related Solutions

[10 marks] (TestSumSeries.java) Write a recursive method that sums up the following series: s(i) = 21+...
[10 marks] (TestSumSeries.java) Write a recursive method that sums up the following series: s(i) = 21+ 24+47+410+…+ i+23i+1+i+13i+1 i = 0, 1, 2, 3, … When i is even, the term is i+23i+1 When i is odd, the term is i+13i+1 In the main method, display the s(i) for i = 0, 1, 2, 3, 4, 5
The following information was obtained: Individual Method 1 Method 2 1 7 5 2 5 9...
The following information was obtained: Individual Method 1 Method 2 1 7 5 2 5 9 3 6 8 4 7 7 5 5 6 The point estimate for the mean difference is The 95% confidence interval for the difference between the two population means is
For the following exercises, write a recursive formula for each arithmetic sequence. a = {−1, 2, 5, ... }
For the following exercises, write a recursive formula for each arithmetic sequence.a = {−1, 2, 5, ... }
Write a recursive formula for the arithmetic sequence −2, −7/2 , − 5, −13/2 , … and then find the 22nd term.
Write a recursive formula for the arithmetic sequence −2, −7/2 , − 5, −13/2 , … and then find the 22nd term.  
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1,...
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1, 7}. Answer the following questions, giving reasons for your answers. a) Is ? ⊆ ?? b)Is ? ⊆ ?? c) Is ? ⊂ ?? d) Is ? ⊆ ?? e) Is ? ⊆ ?? 5) Let ? = {1, 3, 4} and ? = {2, 3, 6}. Use set-roster notation to write each of the following sets, and indicate the number of elements in...
Write a RECURSIVE method that receives 2 strings as parameters. The method will return true if...
Write a RECURSIVE method that receives 2 strings as parameters. The method will return true if the 2nd string is a subsequence of the 1st string. If not, the method will return false. An empty string is a subsequence of every string. This is because all zero characters of the empty string will appear in the same relative order in any string This method must not contain any loops. In java
Consider the following time series data. Month 1 2 3 4 5 6 7 Value 22...
Consider the following time series data. Month 1 2 3 4 5 6 7 Value 22 13 18 11 19 22 14 Round your answers to two decimal places. a. Compute MSE using the most recent value as the forecast for the next period. Mean squared error is What is the forecast for month ? b. Compute MSE using the average of all data available as the forecast for the next period. Mean squared error is What is the forecast...
Consider the following time series data. t 1 2 3 4 5 6 7 yt 10...
Consider the following time series data. t 1 2 3 4 5 6 7 yt 10 9 7 8 6 4 4 a. Construct a time series plot. What type of pattern exists in the data? b. Develop the linear trend equation for this time series. c. What is the forecast for t=8?
Consider the following time series. t 1 2 3 4 5 6 7 Yt 83 61...
Consider the following time series. t 1 2 3 4 5 6 7 Yt 83 61 45 36 29 28 36 b. Develop the quadratic trend equation for the time series. Enter negative value as negative number.(to 3 decimals) Tt = ______ + _______t + ________ t2 c. What is the forecast for t = 8?
Consider the following time series data: Month 1 2 3 4 5 6 7 Value 23...
Consider the following time series data: Month 1 2 3 4 5 6 7 Value 23 15 20 12 18 22 15 (a) Choose the correct time series plot. (i) (ii) (iii) (iv) - Select your answer -Graph (i)Graph (ii)Graph (iii)Graph (iv)Item 1 What type of pattern exists in the data? - Select your answer -Positive trend patternHorizontal patternVertical patternNegative trend patternItem 2 (b) Develop a three-month moving average for this time series. Compute MSE and a forecast for month...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT