How to Create Numbers for an Exponential Growth Curve as a PHP Function

How to Create Numbers for an Exponential Growth Curve as a PHP Function thumbnail
Bacterial growth rates are an example of exponential data

If your savings account balance of one penny is doubled each day for 30 days, you will become a multimillionaire. That is the power of exponential growth. In exponential arithmetic, there is no straight-line, one-to-one relationship between the data. If you plotted each day against the money in the account on a graph, you would see a sharply rising curve. Your body eliminates certain drugs in a non-linear, exponential manner with a falling curve. You can simulate this process using the PHP (Hypertext Preprocessor) language math function "exp()" to calculate data points for the curve.

Instructions

    • 1

      Launch Notepad, the standard, plain-text editor application.

    • 2

      Type the following PHP code in the text editor:

      <?php

      // print the headers formatted

      printf("%s %'-50s","Time", "Concentration");

      // constants. $dose is the amount of drug. $rate is the elimination constant

      $dose=500;

      $rate=0.350;

      echo '';

      for($hour=0;$hour<=24;$hour ++)

      {

      // these os the function to calculate the data for exponential curve

      $concentration=$dose*exp(-$rate*$hour);

      // print the results formatted

      printf("%d %'-50f", $hour, $concentration);

      echo '';

      }

      ?>

    • 3

      Click the "File" menu, and then select the "Save" option. Save under the file name "test.php."

    • 4

      Click on the "File" menu and select "Quit" or "Exit" to close the text editor.

    • 5

      Launch Internet Explorer. Type the FTP URL or IP address of the your Web server in the address bar, and then press "Enter." For example, type:

      ftp://yourwebserver.com

      Replace "yourwebserver.com" with the correct server URL. Be sure to use "ftp://" instead of "http://" in the URL. Enter your user name and password, and then click "Log On."

    • 6

      Upload the file "test.php" to the root directory of the Web server.

    • 7

      End the FTP session by closing Internet Explorer.

    • 8

      Launch Internet Explorer again, and enter the appropriate URL to access the PHP file. For example, enter:

      http://yourdomainname.com/test.php

      Replace "yourdomainname.com" with the domain name or IP address of the Web server.

    • 9

      Press the "Enter" key to load the URL and run the PHP file. The browser should display:

      The time and drug concentration every hour for 24 hours. The concentration should go from 500 down to 0.112434.

Tips & Warnings

  • You can make your PHP code more readable and easier to maintain by using indentation and blank lines to set apart and highlight sections of code. You may understand your code perfectly now, but in a few months, the logic may not be so obvious. Add comments liberally throughout your script to help explain the reasoning behind the code.

  • Some scientific and financial calculations can take a lot of time and computer resources. If you use a shared hosting plan for your website, there may be a limit on how long your script can run. As you develop your formulas and PHP code, consider how much time it would take to execute your program. For instance, 1000 data points will make a smoother looking curve, but it may take too long to process.

Related Searches:

References

  • Photo Credit Thinkstock/Comstock/Getty Images

Comments

Related Ads

Featured