Compound interest loops problem (matlab)

In summary, the conversation discusses a problem involving investing in a Certificate of Deposit (CD) and provides code for calculating the final value of the CD based on the initial investment, interest rate, and term length. Part (b) of the problem involves using a while loop to determine the number of years it takes for the value of the CD to exceed twice the original investment amount. The conversation also mentions some attempts at solving the problem and potential issues encountered.
  • #1
gfd43tg
Gold Member
950
50

Homework Statement



(a) Suppose you decide to invest money in a Certificate of Deposit (CD). Write code that assigns
to the variable FinalValue the final value of the CD based on the following variables:
Investment: the initial amount of money invested in the CD,
Rate: the annual interest rate of the CD, and
Term: the term length of the CD in years.
The interest of the CD should be compounded annually (i.e., at the end of each year the
value of the CD increases by the interest rate times the current value of the CD). Example:
If Investment equals 100, Rate = 0.0235 and Term equals 1, then FinalValue should be
assigned a value of 102.35.

(b) Write code that assigns to the variable numYears, an integer number of years required for
the value of the CD to exceed twice the original value given by the variable Investment (as
in Problem 1a) with the interest rate given by the variable Rate (as in Problem 1a).


Homework Equations





The Attempt at a Solution


I got part (a) of the problem
Code:
Rate = 0.05;
Term = 10;
Investment = 1000;

FinalValue = Investment;
for k = 1:Term
    FinalValue = FinalValue + Rate*FinalValue;
end

But now I am stuck on part (b). I don't know how to incorporate numYears into my while loop. Also, when I run what I have right now in its present form, I get FinalValue = 1000
Code:
Rate = 0.05;
Investment = 1000;

FinalValue = Investment;
while FinalValue < 2*Investment;
      FinalValue = FinalValue + Rate*FinalValue;
end

Edit: I didn't realize that the while will skip the commands in the loop if false. I assumed it would check for truth, and if not true, redo the loop until true. Hence I changed the > to a <. That seems backwards to me...


Now I know FinalValue is 2.0789e+03. I ran it without the commas and 15 executions gives me that value. Now I need to figure out how to assign numYears to the number of times the loop executed.

Edit: nevermind, just found out about the Count
 
Last edited:
Physics news on Phys.org
  • #2
I'm sorry you are not generating any responses at the moment. Is there any additional information you can share with us? Any new findings?
 

Related to Compound interest loops problem (matlab)

1. What is a compound interest loop problem in Matlab?

A compound interest loop problem in Matlab refers to a situation where a set of calculations are performed repeatedly, with each calculation using the results of the previous one. This is often used to model the growth of an investment or loan over time, where the interest is compounded periodically.

2. How do you set up a compound interest loop in Matlab?

To set up a compound interest loop in Matlab, you need to first define the initial variables such as the principal amount, interest rate, and time period. Then, you can use a for loop to calculate the new balance after each compounding period, using the previous balance as the new principal amount. The loop will continue until the desired time period is reached.

3. What are the benefits of using a compound interest loop in Matlab?

Using a compound interest loop in Matlab allows for quick and accurate calculations of the growth of an investment or loan over time. It also allows for easy manipulation of variables, such as changing the interest rate or time period, to see how it affects the final balance. This can be useful for financial planning and decision-making.

4. Are there any limitations to using a compound interest loop in Matlab?

One limitation of using a compound interest loop in Matlab is that it assumes a constant interest rate and compounding period. In real-life situations, these may vary, which can affect the accuracy of the results. Additionally, the calculations may become more complex if there are additional factors involved, such as taxes or fees.

5. Can compound interest loops be used for other types of calculations in Matlab?

Yes, compound interest loops can be used for other types of calculations in Matlab, such as population growth, chemical reactions, or any situation where a value is dependent on its previous value. The concept of a compound interest loop can be applied to a wide range of mathematical and scientific problems.

Similar threads

Replies
3
Views
913
  • General Math
Replies
6
Views
1K
  • Precalculus Mathematics Homework Help
Replies
2
Views
853
  • Precalculus Mathematics Homework Help
Replies
7
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
Replies
9
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • General Math
Replies
1
Views
2K
Replies
2
Views
10K
Back
Top