Question: 1 Recursion Warm-up (matlab) For this problem you are going to rewrite some simple iterative algorithms as recur- sive algorithms. The goal is to build

1 Recursion Warm-up (matlab)

For this problem you are going to rewrite some simple iterative algorithms as recur-

sive algorithms. The goal is to build your understanding of how recursion works and

the importance of constructing a proper base case for your algorithm.

1.1 Sum

Implement a recursive function that calculates the mathematical sum(tylor series expansion sine)

which approximates sin(x). You can verify your result by comparing it to the sine

function. For suciently large n, the above should practically equal the sine function.

You will need to come up with a suitable recursive identity and base case for this sum.

Use the following function header:

function y = sumRecursive(x,n)

1.2 n-choose-k

Write a MATLAB function with a header

function y = nchoosekRecursive(n,k)

where y is the number of combinations of k 0 elements that can be generated from

a set of n k items. We call this quantity n-choose-k.

Take extra care to properly dene the base case in your recursion. Be sure to explic-

itly check that n k. If n < k, return 0.

You may not use the built-in MATLAB function nchoosek

Here are some typical inputs and expected outputs:

7

2

= 21

5

3

= 10

5

4

= 5

4

4

= 1

3

0

= 1

0

0

= 1

100

5

= 75287520

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!