General instructions:-
Find the root of an algebraic equation f(x) as follows by using a
technique called regula-falsi.
Test your program on at least 3 different kinds of f.
Write a Java method to compute the sin(x) with in a given accuracy
epsilon. It should have two double arguments and return a double value.
sin(x) is given by:
sin(x)=x - x^3/3! + x^5/5! - x^7/7! ....
Do this by using separate methods for x^n and for factorial.
Write the following two recursive methods to check divisibility of a
positive integer n by 3 and 11. Both methods should return boolean values.
(Hint: For b) it will be easier if you write a helper function which is
recursive and does all the work).
Write a program to solve the following puzzle:-
Suppose you are standing at a point,(x,y) in 2-D co-ordinate and want to go to
the origin (0,0)[ Assume both x and y are positive here]. You are allowed to move
either horizontally or vertically by 1 unit at a time i.e., if you are standing
at (x,y) then two possible movements are either to (x-1,y) or ( x, y-1). Find the
total number of possible shortest paths from (x,y) to origin (0,0). [Hint: Use
recursive function].
Write a method to compute factorial of an integer. Verify your result in problem
2 by computing (x+y)!/( x! * y!) using this function.
Write a program that implements this definition of cube numbers:
cube(1) = 1
cube(N) = cube(N-1) + 3*(square(N)) - 3*N + 1
Implement the square() method using this definition
square(1) = 1
square(N) = square(N-1) + 2*N - 1
Write a program to compute the roots of a given quadratic equation a*x^2+b*x+c.
Your program should take a, b and c as inputs. Write a separate method to compute
the discriminant and use it to find the roots in case they are real. Otherwise it
should print "imaginary roots".
Write three Java methods to compute the sum, product, and sum of
reciprocals of two double numbers. Using these methods write three more
methods to compute the arithmetic mean, geometric mean, and harmonic mean of
the first n natural numbers. Write another method to compute the maximum
and minimum of three double numbers. Use these methods in main to compute and
print the three means and the maximum and minimum of the three means computed
above. Properly decide the arguments and return types of the methods.
Write a Java method to compute the expression 1/sqrt(1-x^2).
From main use this method to print the value of the expression for
x=1.3, -0.4, 0.8, 0, 2, -1. Your program should use the method only if x is in
the proper range; otherwise it should only print an appropriate message on the
screen.
Write a method to compute n choose r, given n and r. Use this method from
main to compute the sum of the binomial coefficients for various values of n.
Write a recursive method to compute if a given positive integer n is a
palindrome. It may help to pass the number of digits in n as an argument of
the method (in addition to n). To start with, you can compute the number of
digits in n within main before the first call to the recursive method. The
return type of the method should be boolean.
A Mersenne number is a number that is one less than a power of two, ie, a number of the form 2^n - 1. A Mersenne number that is also prime is called a Mersenne prime. It has the property that the exponent n is also prime, ie, a Mersenne prime has the form 2^p - 1, where p is prime. For example, taking p=2, 2^2 - 1 = 3, which is prime, and therefore a Mersenne prime. However, not every number of the form 2^p - 1 (p prime) is a prime number. Write a program that generates Mersenne primes for increasing prime numbers p, till you find a prime number for which the corresponding Mersenne number is not a Mersenne prime. Report this prime number. Your program should have the following methods:
(i) A method named generatePrime() that generates prime numbers.
(ii) A method named mersenneNumber() that takes a number n as argument and returns the corresponding Mersenne number 2^n - 1.
(iii) A method named isPrime() that takes a number n as argument and returns true if it is prime, false if it is composite.
Use method (i) to generate prime numbers using a loop. For each prime number generated, compute the corresponding Mersenne number using method (ii). Use method (iii) to check if the Mersenne number computed is also a Mersenne prime.
Write a program to convert a decimal number to a hexadecimal number. Your program should use the following two methods : The first method converts the given decimal number to binary. The second method converts the binary number obtained from the first method to hexadecimal.
The exponential function has the following Maclaurin series:
e^x = summation over k=0 to infinity { x^k / k! }.
Write a program to compute the value of e^(-1) using the above series, upto an error of 0.001%. To calculate the error, you will need a standard value of e^(-1), which you can obtain using the method Math.exp(). Your program should have a method that computes x^k / k!. This method will be called for increasing values of k from inside a loop in the main method. The sum of the return values of these calls will give an approximation for e^(-1). Exit from the loop when the error becomes less than 0.001%.
Write a Java program which computes sinh (x) where
sinh (x) = {summation over k = 0 to infinity } (x^(2k+1)) / (2k+1)!.
Use separate methods for calculating factorial and power (You can use
Math.pow). x can be any real number (double).
Use first 10 terms of the expansion to approximate the value of sinh (x).
Write a program to compute cube root of a number x using the fact that
if p is an approximation for cube root of X then q = (2p+x/(p*p))/3 is a
better one. Final cube-root may differ by 0.001. Write a separate method to
compute q.
Write a Java program with a main method and a method f. Your program should
call f at least 10 times and using recursion, method argument and return
value, it should print the number of times f is called.
Write a Java program to compute value of a expression (ax+b)^c. Use a
method nCr which uses recursion to compute binomial coefficients.