Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A geometric sequence is a sequence in which each term is found by multiplying the preceding term by the same value. Its general term is

A geometric sequence is a sequence in which each term is found by multiplying the preceding term by the same value. Its general term is
where is the n-th term of the sequence, is the common ratio obtained by taking any term in the sequence and dividing it by its preceding term, and is the first term of the sequence. Both should be non-zero according to its definition.
Write a recursive function to generate first k terms of a geometric sequence. This function should take ,, and as inputs, and output first terms in an array.
If any of the inputs are non-numeric, or is not an integer greater than or equal to 1, your function should output an empty array, i.e.[].
You are required to use recursion ONLY to solve this problem. Using loops will cost you 1/3 of the points even if you solve it correctly.
Hints:
When checking if k is an integer, built-in functions like isinteger() cannot determine if k is of integer value correctly if k is a single or double (it only determines whether k is of "integer types" in Matlab). Therefore, try some other methods. We don't want to do typecasting here either which might change the original value of k. One possible solution is to check if the remainder after division of k by 1 is 0.
Your function should always produce an output with any k including k=1 when no recursion is needed. Use if-else(if) condtional to include all the edge cases.

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

from the start oi the riaction? 0.07 0.40 06(1) 0.55 0.93

Answered: 1 week ago

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago