Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to find the value y from this polynomial

–2 votes
asked Nov 3, 2019 by Zainab Aslami (100 points)

 How to find the value y from  this polynomial y = (x-1/x)+(x-1/x)2/2+(x-1/x)3/3+(x-1/x)4/4

4 Answers

0 votes
answered Nov 4, 2019 by anonymous

Either using loop or Recursive function , the result can be achieved . 

import java.util.Scanner;

public class Main

{

  public static void main (String[]args)

  {

    try

    {

      Scanner scanner = new Scanner (System.in);

      System.out.print ("Enter X Value : ");

      int x = scanner.nextInt ();

      int limit = 4;

      double y = 0;

      for (int i = 1; i <= limit; i++)

                    y += returnMultiply (x, i);

      System.out.println ("Y : " + y);

    }

    catch (Exception ex)

    {

      ex.printStackTrace ();

    }

  }

  private static double returnMultiply (int x, int power)

  {

    double result = 1;

    for (int i = 1; i <= power; i++)

           result *= (double) (x - 1) / x;

    return (double) result / power;

  }

}

0 votes
answered Nov 4, 2019 by gameforcer (2,990 points)

In Python using recursion:

def recur(x, steps = 4):
    if steps > 0:
        return (x**steps) + recur(x, steps - 1)
    else:
        return 0

x = 2
x_n = (x-1)/x
print(recur(x_n, 4))

 and iteration:

x = 2, steps = 4
y, x_n = 0, (x-1)/x
for s in range(1, steps + 1):
    y += (x_n**s)/s

print(y)

0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
clc                                                                                                           @matlab

syms x y

a=input('enter the polynomial');                                                            

b=simplify(a);

disp(b);

output

enter the polynomial

(x-1)/x+((x-1)/x)^2/2+((x-1)/x)^3/3+((x-1)/x)^4/4

(25*x^4 - 48*x^3 + 36*x^2 - 16*x + 3)/(12*x^4)
0 votes
answered Nov 9, 2019 by UTKARSH GUPTA
#include<stdio.h>

#include<math.h>

# define term 4//term of series can be change from here

int main()

{

float a,i,sum=0,x;

printf("enter the value of x :");

scanf("%f",&x);

a=(x-1/x);

for(i=1;i<=term;i++)

{

sum+=pow(a,i)/i;

}printf("sum of series is %f",sum);

return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...