Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve the following problems using basic MATLAB functions and processes. Please include well detailed comments so that I can understand all steps. I am

Please solve the following problems using basic MATLAB functions and processes. Please include well detailed comments so that I can understand all steps. I am new to MATLAB so please explain as if you were teaching a beginner. Thanks in advance. Be sure to read the instructions carefully.

image text in transcribed

Problems In this lab, you may use MATLAB to implement the Recursion problems. Do not use a for or a while loop to implement a recursive function. L. Recursion: Sum of Even numbers in a range (25 points Write the comments with input, output, description, and test cases for a recursive function that adds up all the even numbers in a range Given a range 1 to 10 sumEvenNum 10) sumEvenNum (2,5) an8 2. Recurrence Relations (25 points) Write recursive functions with test cases that output the first six terms of the sequence defined by each of these recurrence relations and initial conditions (a) an ao (b) as 3a ao (c) an-1 2n 3, ao (d) an 1,a 1,a2 an-2 an-3, ao Note: In MATLAB, the first index wi e 1 and not 0. So the first six terms will be a(1 a(2), a(3, a(4), a (5), al whereas in C++ it will be aloj, alij, a12, al3, a 4], a15 If you're implementing in C++, do not use pow function but create a recursive function raise Pow( x,n) that solves rR In MATLAB, you can sim ply use e operator acAn 3. Recursion: Sort Game (One of the reasons why we sort) (25 points) Write a recursive function that guesses a number between 0 and x (x being an input number to the function). If you guess too high, it tells you that and continues. If you guess too low. t tells you that and cont es. If you guess the n per, it tells you how many guesses you your output might look something like this: took and stops So Guess a num between 0 and 100: 33 33 is too high Guess a num between 0 and 100: 12 12 is too high. Guess a num between 0 and 100: 6 6 is too low Guess a num between 0 and 100 8 is too low Guess a num between 0 and 100 9 is too low Guess a num between 0 and 100 11 11 is too high Guess a num between 0 and 100: 10 you guessed 10 in 6 guesses Note: write two functions. The first takes as an input parameter a number, and generates a random number between 0 and that input number. It then calls the second, recursive function with about 3 input parameters, including the first function's input parameter (in the above example, that was the number 100) and the random number (in the above example, that was 10). It is in the recursive function that the user is asked to guess a number. Try testing the function using 8,16,32,64 as the upper limit of the random number (or, in other terms, as input into the first function This is one of the reasons we sort sets (lists) of numbers so often t is incredibly more efficient to find a number if we're searching through a sorted set of mumbers than it is to find a number while searching through a randomly ordered set of n Tubers I. Recursion: Cipher (25 points) Write the comments with input, output, and test cases for a recursive function that creates a gibberish" language. So if a letter in a word is a vowel, it is replaced with ag", then the vowel, whereas if the letter is a consonant, it is just included normally. For instance, the word "dog" would be "dithagog

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions