<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/technology/cnxml/schema/dtd/0.5/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" id="new">
  <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Programming with M-Files: A Personal Finance Example Using While Loops</name>
  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
  <md:version xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">1.4</md:version>
  <md:created xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2006/02/27 15:34:26 US/Central</md:created>
  <md:revised xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2006/08/22 13:19:50.780 GMT-5</md:revised>
  <md:authorlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
      <md:author xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="morrell">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Darryl </md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Morrell</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">morrell@asu.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="morrell">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Darryl </md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Morrell</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">morrell@asu.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Credit Card Debt</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">M-file</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">MathScript</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">MATLAB</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Octave</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Personal Finance</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">While Loop</md:keyword>
  </md:keywordlist>

  <md:abstract xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">This is an example of using an m-file script to compute the number of months necessary to pay off a credit card debt using the minimum monthly payment.</md:abstract>
</metadata>
  <content xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S1">
    <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">A Personal Finance Example</name>

    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy1">
      A student decides to finance their college education using a credit card. They charge one semester's tuition and then make the minimum monthly payment until the credit card balance is zero. How many months will it take to pay off the semester's tuition? How much will the student have spent to pay off the tuition?
    </para>
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy2">
      We can solve this problem using an m-file script. We define the following variables:
      <list xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="vars" type="bulleted">
  <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <m:math>
    <m:ci>
      <m:msub>
        <m:mi>b</m:mi>
        <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
  </m:math> - Balance at month <m:math><m:ci>n</m:ci></m:math>.
  </item>
  <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
      <m:math>
    <m:ci>
      <m:msub>
        <m:mi>p</m:mi>
        <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
  </m:math> - Payment in month  <m:math><m:ci>n</m:ci></m:math>.
  </item>
  <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
      <m:math>
    <m:ci>
      <m:msub>
        <m:mi>f</m:mi>
        <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
  </m:math> - Finance charge (interest) in month  <m:math><m:ci>n</m:ci></m:math>.</item>
</list>
    </para>
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy3">
      The <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">finance charge</emphasis> <m:math>
    <m:ci>
      <m:msub>
        <m:mi>f</m:mi>
        <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
  </m:math>is the interest that is paid on the balance each month. The finance charge is computed using the monthly interest rate <m:math> <m:ci>r</m:ci></m:math>:
<equation xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="eq2">
  <m:math>
    <m:apply>
      <m:eq/>
      <m:ci>
	<m:msub>
	  <m:mi>f</m:mi>
	  <m:mi>n</m:mi>
	</m:msub>
      </m:ci>
      <m:apply>
	<m:times/>
	<m:ci>r</m:ci>
	<m:ci>
	  <m:msub>
	    <m:mi>b</m:mi>
	    <m:mi>n</m:mi>
	  </m:msub>
	</m:ci>
      </m:apply>
    </m:apply>
  </m:math>
</equation>
Credit card interest rates are typically given as an annual percentage rate (APR). To convert the APR to a monthly interest rate, use the following formula:
<equation xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="eq3">
  <m:math>
    <m:apply>
      <m:eq/>
      <m:ci>r</m:ci>
      <m:apply>
	<m:minus/>
	<m:apply>
	  <m:power/>
	  <m:apply>
	    <m:plus/>
	    <m:cn>1</m:cn>
	    <m:apply>
	      <m:divide/>
	      <m:ci>APR</m:ci>
	      <m:cn>100</m:cn>
	    </m:apply>
	  </m:apply>
	  <m:apply>
	    <m:divide/>
	    <m:cn>1</m:cn>
	    <m:cn>12</m:cn>
	  </m:apply>
	</m:apply>
	<m:cn>1</m:cn>
      </m:apply>
    </m:apply>
  </m:math>
</equation>
More information on how to compute monthly rates can be found <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" src="http://en.wikipedia.org/wiki/Credit_card_interest">here</link>.
    </para>
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy4">
      Credit cards usually have a <emphasis xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">minimum monthly payment</emphasis>. The minimum monthly payment is usually a fixed percentage of the balance; the percentage is required by federal regulations to be at least 1% higher than the monthly interest rate. If this minimum payment would be below a given threshold (usually $10 to $20), the minimum payment is instead set to the threshold. For a threshold of $10, the relationship between the balance and the minimum payment can be shown in an equation as follows:
<equation xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="eq4">
  <m:math>
    <m:apply>
      <m:eq/>
      <m:ci>
	<m:msub>
	  <m:mi>p</m:mi>
	  <m:mi>n</m:mi>
	</m:msub>
      </m:ci>
      <m:apply>
	<m:ci type="fn">max</m:ci>
      <m:apply>
	<m:times/>
	<m:apply>
	  <m:plus/>
	  <m:ci>r</m:ci>
	  <m:cn>0.01</m:cn>
	</m:apply>
	<m:ci>
	  <m:msub>
	    <m:mi>b</m:mi>
	    <m:mi>n</m:mi>
	  </m:msub>
	</m:ci>
      </m:apply>
      <m:cn>10</m:cn>
      </m:apply>
    </m:apply>
  </m:math>
</equation>
    </para>
    
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy99">
To compute the balance for one month (month <m:math><m:apply><m:plus/> <m:ci>n</m:ci><m:cn>1</m:cn></m:apply></m:math>) from the balance for the previous month (month <m:math> <m:ci>n</m:ci></m:math>), we compute the finance charge on the balance in the previous month and add it to the previous balance, then subtract the payment for the previous month:
<equation xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="eq1">
  <m:math>
    <m:apply>
      <m:eq/>
      <m:ci>
	<m:msub>
	  <m:mi>b</m:mi>
<m:mrow>
   <m:mi>n</m:mi>
   <m:mo>+</m:mo>
   <m:mn>1</m:mn>
</m:mrow>
	</m:msub>
      </m:ci>
      <m:apply>
	<m:plus/>
	<m:ci>
	  <m:msub>
	    <m:mi>b</m:mi>
	    <m:mi>n</m:mi>
	  </m:msub>
	</m:ci>
	<m:apply>
	  <m:minus/>
	  <m:ci>
	    <m:msub>
	      <m:mi>f</m:mi>
	      <m:mi>n</m:mi>
	    </m:msub>
	  </m:ci>
	  <m:ci>
	    <m:msub>
	      <m:mi>p</m:mi>
	      <m:mi>n</m:mi>
	    </m:msub>
	  </m:ci>
	</m:apply>
      </m:apply>
    </m:apply>
  </m:math>
</equation>
    </para>
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="xyzzy100">
In the following exercises, we will develop the program to compute the number of months necessary to pay the debt. We will assume that the card APR is 14.9% (the <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" src="http://money.cnn.com/pf/informa/index.html">average rate on a student credit card</link> in mid February 2006) and that the initial balance charged to the card is $2203 (the <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" src="http://www.asu.edu/sbs/FallUndergradEastWest.htm">in-state tuition at Arizona State University at the Polytechnic Campus  for Spring 2006 semester</link>).
    </para>
    <exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="E1">
      <problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P1">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P1a">
          Write code to compute the monthly interest rate <m:math> <m:ci>r</m:ci></m:math> from the APR using <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="eq3"/>.
        </para>
      </problem>
      <solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S11"><code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="block">
APR = 14.9;
r = (1+APR/100)^(1/12)-1;
</code></para>
      </solution>
    </exercise>

    <exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="E2">
      <problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P2">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P2a">
          Write code to compute the minimum monthly payment <m:math>
    <m:ci>
      <m:msub>
        <m:mi>p</m:mi>
        <m:mi>n</m:mi>
      </m:msub>
    </m:ci>
  </m:math> using <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="eq4"/>.
        </para>
      </problem>
      <solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S2"><code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="block">bn = 2203;
pn = max((r+0.01)*bn,10);
</code></para>
      </solution>
    </exercise>

    <exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="E3">
      <problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P3">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P3a">
          Write code to compute the  balance at month <m:math><m:apply><m:plus/> <m:ci>n</m:ci><m:cn>1</m:cn></m:apply></m:math> in terms of the balance at month <m:math> <m:ci>n</m:ci></m:math>  using <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="eq1"/>.
        </para>
      </problem>
      <solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S3"><code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="block">
fn = r*bn;
bn = bn + fn - pn;
</code></para>
      </solution>
    </exercise>

    <exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="E4">
      <problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P4">
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P4a">
	  Place the code developed for <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="E3"/> into a while loop to determine how many months will be required to pay off the card.
	</para>
      </problem>
      <solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S4">
	  This space intentionally left blank.
	</para>
      </solution>
    </exercise>

    <exercise xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="E5">
      <problem xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P5">
	<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="P5a">
	  Modify your code from  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="E4"/> to plot the monthly balance, monthly payment, and total cost-to-date for each month until the card is paid off.
	</para>
      </problem>
      <solution xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="S5">
	  This space intentionally left blank.
	</para>
      </solution>
    </exercise>


  </section>

</content>
  
</document>
