Good luck. I think this is a good learning experience either way.

Here's a trivial example that might help you with thinking through your credit card problem.

Jack has $2000 in his bank account. Assume it's a crappy bank with 0 interest. Every 2 months he withdraws $150. Every 2 months his mother deposits $50 as an allowance. How long until he's out of money?

(Common sense says he's taking $100 every 2 months from his savings, so we know it'll be 40 months. But let's work it through step by step.)

So you start to think about it...

First 2 months: $2000 - $150 + $50 = $1900

Next two months: $1900 - $150 + $50 = $1800

etc.

It doesn't take long to notice that every two months it's the same old pattern. Take the existing balance, subtract his withdrawal amount, add his allowance amount, to get the new balance. We can even write it as an equation: balance = balance - 150 + 50.

So, common sense says,

**while he's still got money** in the account, he can

**do his transaction** (use the equation), and he will

**last for two more months**.

Now it starts to look like an algorithm! I've bolded a few of the action words that help you see it.

Let's rewrite the above statement in a structured algorithm form. It's obvious from the statement that we need to keep track of his

*balance*, and

*how many months*. Those become variables.

So:

while balance > 0 (

**"while he's still got money"**)

balance = balance - 150 + 50 (

**"do the monthly transaction"**)

months = months + 2 (

**"lasts for two more months"**)

end loop

Notice we haven't even touched matlab yet. Now that the algorithm is written in clear terms, you can write it in whatever programming language you want. Matlab, C++, Java, BASIC, Fortran, Perl, whatever.

Now you are in a position to Google search (or ask in these forums) and ask questions such as "what is the syntax of a while loop in Matlab?" or, to calculate years out of months, "How do I do modulus (remainders) in Matlab?"

Do you see the difference between that and your original question of "how do I tell matlab that 1 year has passed"? Your original question mixes up Matlab syntax (what command do I use) with algorithm questions (how do I keep track of credit card payments).

Hope that helps.

Click to expand...