Kardafol Posted February 2, 2007 Share Posted February 2, 2007 I'm wondering if anyone has any idea how I should start making a XY graph, then plot a quadratic equation on it. So far, I have the following (Solves the equation aslong as it's in a 'ax^2+bx+c=0' form) class Quadratic { //varaibles public $pat = '/^(-?[0-9.]*)x\^2([-+][0-9.]*)x([+-][0-9.]+)=0$/i'; public $a = 0; public $b = 0; public $c = 0; function setABCByEquation($expr) { if (preg_match($this->pat, $expr, $ans)) { $this->a = $ans[1]; $this->b = $ans[2]; $this->c = $ans[3]; return $this->checkVars(); } else return 0; } function setABCByValues($va = 1, $vb = 0, $vc = 1) { $this->a = $va; $this->b = $vb; $this->c = $vc; return $this->checkVars(); } function checkVars() { if ($this->a == '-') $this->a = -1; else if ($this->a == 0) $this->a = 1; if ($this->b == '-') $this->b = -1; else if ($this->b == '' || $this->b == '+') $this->b = 1; $this->b = ereg_replace("[^-0-9.]", "", $this->b); $this->c = ereg_replace("[^-0-9.]", "", $this->c); return 1; } function solve() { if ($this->a == 0 || $this->c == 0) return 'err'; $pre = sqrt(abs(($this->b*$this->b) - (4*$this->a*$this->c))); $ans[0] = (-$this->b + $pre) / (2 * $this->a); $ans[1] = (-$this->b - $pre) / (2 * $this->a); return $ans; } // Helper functions (clear();, getEquation() } /* Syntax: $equation = new Quadratic(); $equation->setABCByEquation('x^2+4x+8=0'); $ans = $equation->Solve(); echo 'x = '.$ans[0].', '.$ans[1]; //Assuming no errors were found. */ As the equation is quadratic, the line should be smooth, and curve eather up or down. I've never used the image functions with PHP, and I'm not quite sure where to start. It would be nice if someone could help me get started on this. Link to comment https://forums.phpfreaks.com/topic/36837-newbie-help-graphing-quad-equations/ Share on other sites More sharing options...
JasonLewis Posted February 2, 2007 Share Posted February 2, 2007 there is a person who made an awesome calculator, cant remember his/her name right now,that i think did this. is studied quadratics in maths and they would be hard to put on a graph in php. unless there is a seperate function for it. if you go here, there is a list of all the image functions a tad way down the page: http://au2.php.net/manual/en/ref.image.php Link to comment https://forums.phpfreaks.com/topic/36837-newbie-help-graphing-quad-equations/#findComment-175772 Share on other sites More sharing options...
hitman6003 Posted February 2, 2007 Share Posted February 2, 2007 The first phpfreaks competition focused on creating a php based "graphing calculator". I recommending checking out some of the submissions to that competition: http://www.phpfreaks.com/forums/index.php/board,64.0.html Specifically this page: http://www.phpfreaks.com/forums/index.php/topic,115293.15.html Link to comment https://forums.phpfreaks.com/topic/36837-newbie-help-graphing-quad-equations/#findComment-175817 Share on other sites More sharing options...
Kardafol Posted February 3, 2007 Author Share Posted February 3, 2007 Thanks alot, I will check the links you provided. However I want to make it myself, I just get that feeling of acomplishment Link to comment https://forums.phpfreaks.com/topic/36837-newbie-help-graphing-quad-equations/#findComment-175856 Share on other sites More sharing options...
JasonLewis Posted February 3, 2007 Share Posted February 3, 2007 you can ask the creator on how they did it then expand it. Link to comment https://forums.phpfreaks.com/topic/36837-newbie-help-graphing-quad-equations/#findComment-175862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.