Simple While Loop Problem [MATLAB]

  • Thread starter Thread starter nickadams
  • Start date Start date
  • Tags Tags
    Loop Matlab
Click For Summary
SUMMARY

The discussion focuses on creating a MATLAB script using a while loop to determine the number of years required for a bank account to exceed $100,000, given an initial amount (s) and an annual interest rate (inter). The user attempts to derive a general equation for the account balance over time but struggles with implementing this in MATLAB. The specific test cases provided are for s = 500 with inter = 5 and s = 1 with inter = 50. The goal is to effectively utilize a while loop to calculate the total amount in the account until it surpasses the target amount.

PREREQUISITES
  • Understanding of MATLAB programming
  • Knowledge of while loops and control structures in programming
  • Basic financial concepts such as interest calculation
  • Familiarity with mathematical series and summation
NEXT STEPS
  • Learn how to implement while loops in MATLAB
  • Research MATLAB's syntax for defining functions and variables
  • Explore financial calculations in MATLAB, specifically compound interest
  • Study how to analyze and visualize data trends in MATLAB
USEFUL FOR

This discussion is beneficial for students learning MATLAB, particularly those tackling financial modeling and iterative programming concepts. It is also useful for educators looking to provide practical examples of while loops in programming assignments.

nickadams
Messages
182
Reaction score
0

Homework Statement



Write a script using a while loop that calculates the number of years it will take your bank account to accumulate at least $100,000 if you begin with s number of dollars, and you add that same amount at the end of each year. In addition, your account pays a percentage of interest, inter, every year.

Test your code for s = 500, inter = 5 and s = 1, inter = 50.

Homework Equations



In an attempt to find a general equation of money in the account as a function of years, I wrote the equation for the first 4 years and looked for a trend. The general form I found looks like...

$n = \frac{inter^n * s}{100^n} + 2*\frac{inter ^(n-1) * s}{100^ (n-1)} + \frac{inter ^(n-2) * s}{100^(n-2)} + \frac{inter^(n-3) * s}{100^(n-3)} + \frac{inter^(n-4) * s}{100^(n-4)}

... and it keeps adding these terms until the x in "inter^(n-x)" and "100^(n-x)" is equal to n. As you can see, when x is equal to n, the final term will be just an s. That is what we want because at the end of every year we add "s" to the account.

The Attempt at a Solution



How can I get that above equation in a general form so that I can use it in MATLAB to find dollars in the account as a function of years?

In order to solve the problem, I feel that I need to set up a while loop that will terminate once the dollars in the account exceed 100,000. But the problem is that I don't know how to put my function into MATLAB, and I also don't know how to identify how many years it took for the total $ to exceed 100,000.Please help!
 
Physics news on Phys.org
bump?
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K