234k views
5 votes
Modify the finance code from p.7 to create a function M-file invest that - takes inputs: princ (the \# of dollars to be initially deposited in a bank account), princ_inc (the \# of dollars you will be adding to the account at the end of each year), princ_des (the \# of dollars you want to have at the end of the investment period), and perc (the annual percentage of interest paid by the bank). - outputs n_yrs (the \# of years it will take your investment to reach princ_des dollars). Check your code by finding the \# of years needed to accumulate at least $10,000 if we initially deposit $500 and add another $500 at the end of each year, and the bank pays 5% annually.

1 Answer

3 votes

Final answer:

The question involves creating a finance function to calculate the number of years needed to reach a desired investment amount, taking into account compound interest and annual additions.

The function should compute the time to accumulate at least $10,000 with a starting balance of $500, yearly addition of $500, and 5% annual interest.

Step-by-step explanation:

The task is to modify a finance code to create a function that can calculate the time required to reach a desired amount of money in an investment account, considering compound interest.

The function should accept four inputs: princ (initial deposit), princ_inc (annual deposit), princ_des (desired amount), and perc (annual interest rate), and output n_yrs (number of years needed).

To check the code, if initially $500 is deposited, with an annual addition of $500, at an interest rate of 5%, we want to find out how long it will take to accumulate at least $10,000.

This problem can be solved by setting up a formula that accounts for the principal amount, the annual additions, and compound interest. As an example, the formula used to calculate the future value of the investment over time is typically:

Future Value = Principal * (1 + Interest Rate) ^ Number of Years + Sum(Annual Addition * (1 + Interest Rate) ^ (Number of Years - Year of Addition))

Using this formula and iterative methods or financial functions, the code can produce the number of years needed to reach the target amount.

User Karatchov
by
7.4k points