Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use MATLAB to solve the following problems. Please include well detailed

ID: 3798309 • Letter: P

Question

Please use MATLAB to solve the following problems. Please include well detailed comments so that I can understand all functions and processes. Do not use a for or while loop. Thanks in advance.

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 m-1, 0 -1 (b) a F 3a. n-1, a0 (c) an an-1 2n 3, ao 4 (d) an an-1 an-2 an-3, ao 1, a1 1, a2 2 Note: In MATLAB, the first index will be 1 and not 0. So the first six terms will be a(1), a(2), a (3), a (4), a(5), a(6) whereas in C++ it will be a 0, a 1], a 21, a 3, a 4], a 5 If you're implementing in C++, do not use pow function but create a recursive function raisePow(x,n) that solves an. In MATLAB, you can simply use the operator An 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 "ithag", then the vowel, whereas if the letter is a consonant, it is just included normally For instance, the word "dog" would be "dithagog" "math" would be "mit hagath"

Explanation / Answer

TEST BENCH:

%% Test program

A=[];
for i=1:6
A(i)=recur1(i);
end
disp(A)
B=[];
for i=1:6
B(i)=recur2(i);
end
disp(B)
C=[];
for i=1:6
C(i)=recur3(i);
end
disp(C)
D=[];
for i=1:6
D(i)=recur4(i);
end
disp(D)

%% Test program

A=[];
for i=1:6
A(i)=recur1(i);
end
disp(A)
B=[];
for i=1:6
B(i)=recur2(i);
end
disp(B)
C=[];
for i=1:6
C(i)=recur3(i);
end
disp(C)
D=[];
for i=1:6
D(i)=recur4(i);
end
disp(D)

function f=recur1(n)
if n==1
f=-1;
else
f=-2*recur1(n-1);
end
end

function f=recur2(n)
if n==1
f=1;
else
f=3*(recur2(n-1)^2);
end
end

function f=recur3(n)
if n==1
f=4;
else
f=recur3(n-1) +2*n +3 ;
end
end

function f=recur4(n)
if n==1
f=1;
elseif n==2 f=1;
elseif n==3 f=2;
else
f=recur4(n-1)-recur4(n-2)-recur4(n-3) ;
end
end

OUTPUT:

-1 2 -4 8 -16 32

1.0e+14 *

0.0000 0.0000 0.0000 0.0000 0.0000 6.1767

4 11 20 31 44 59

1 1 2 0 -3 -5