Recursive formula in matlab


Question1) Create a MATLAB function called question3 that finds the root of an equation numerically using the following recursive formula:

xn+1= xn– f(xn)/g(xn) , for n =1,2,3,……

where g(xn) = (f(xn  +f(xn ))-f(xn  ))/f(xn ) . This iterative procedure should stop when the absolute difference between xn andxn+1is less than a given tolerance epsilon. The function must accept as inputs , a scalar function ‘f’, an initial number ‘x’ and a positive number ‘epsilon’ to terminate the procedure. Hence use this numerical technique to find the root of the equation ex –x2 =0

Question2) Let St be the price of one share of a particular company at time t. If the price St+1 at time t+1 can wither take the value of uStwith probability p1 (where u>1), remain the same with probability p2 or go down to dStwith probability 1-p1-p2 (where 0t}t=020for given u, d, p1,p2 and plot St against t. Hence, by counting the number of paths, calculate the probability that S6 = S0u2d3 . Do this by using the command rand.

Question3) Suppose you are at a casino playing roulette and that you are betting on black to turn up. You start by betting 1 euro. If you win bet another 1 euro in the next game. If you lose you double your previous bet. You will stop playing when you have either won at least 10 euros or lost more than 100 euros. Create a script file called question6 to simulate this system. Then play the game 5000 times and record your performance. Use the command rand.

Question4) A Legendre polynomial of degree n is given by the following expression:

Pn(x) = (1/2nn!)*(dn/dxn)*(x2-1)n

where(dn/dxn)f is the nth derivative of function f.

(a) Generate the first four polynomials and use the command subplot to plot the resulting graphs. Use the different colours and symbols for the plots

(b) create a Matlab function called legendrepolynomial which for given inputs n and m calculates the integral

∫Pn(x)Pm(x) dx

using the trapezoid rule with a suitability chosen number of gridpoints. Comment on the output obtained.

Note: Limits of integral from -1 to 1

Question5) A Eulerian number Pn,kis the number of permutations p1p2….pn of the numbers 1,2,….,n in which there are k places with pjj+1. For example P3,1= 4 because there are four permutations having one ascent which hare 132,213,231,312. This number can be generated using the following recurrence relation

Pn,0 = 1 for all n>=0

Pn,k= 0 for all k>=n

Pn,k= (k+1)Pn-1,k+ (n-k)Pn-1,k-1  for all k=1,2,…..,n-1

(a) create a function called euleriannumber which generates a Eulerian number for a given n and k

(b) create a script file called euleriannidentity which calls the function euleriannumber and then verifies the identity

∑in = ∑Pn,k(m+k+1 , n+1)

for given m,n and k, where (m+k+1 , n+1) = (m+k+1)!/((n+1)!*(m+k-n)!)

note: limits of in= from i=1 to m

limits of Pn,k(m+k+1 , n+1) = from k=0 to n-1

Request for Solution File

Ask an Expert for Answer!!
MATLAB Programming: Recursive formula in matlab
Reference No:- TGS0874

Expected delivery within 24 Hours