Final answer:
To complete the recursive function RaiseToPower() in MATLAB, modify the assignment statement to multiply the base value with the result of the recursive call. For the PrimeChecker function, assign different values to primeResult based on test cases.
Step-by-step explanation:
To complete the recursive function RaiseToPower() in MATLAB, you need to modify the assignment statement below:
resultVal = 1;
Inside the else statement, you can call the RaiseToPower function recursively by multiplying the base value with the result of the recursive call, like this:
resultVal = baseVal * RaiseToPower(baseVal, exponentVal-1);
This implementation will calculate the power of a given base value and exponent using recursion. For example, if the userBase is 2 and the userExponent is 4, the output raisedValue will be assigned as 16 (i.e. 2^4).
The skeleton code provided in the PrimeChecker function can be completed to determine if a number is prime. Make the following modifications:
- For test case 1, assign primeResult with 0 if testVal is 0 or 1.
- For test case 2, assign primeResult with 1 if testVal is only divisible by 1 and itself.
- For test case 3, use the % operator to check if testVal can be evenly divided by divVal. If it can, assign primeResult with 0.
- In the else case, assign primeResult with the result of the recursive call to PrimeChecker with testVal and (divVal - 1).
Calling CheckValue(1) will return 0, indicating that 1 is not prime. Calling CheckValue(5) will return 1, indicating that 5 is prime.