Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php graph an equation

Explorer ,
Mar 21, 2017 Mar 21, 2017

Hi All,

I am struggling with how to graph an equation over its full range. How would one code x squared then call it up to be graphed at each 0.1 increment?

The closest that I have gotten is:

$equ = pow($x,2);

$data = array();

for($x = 0; $x <= 5; $x+.1)$data[ ] = array(' ', $equ);

Thank you All.

Gary

424
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 21, 2017 Mar 21, 2017

Is this what you're looking for?

xsquared.png

<?php

# PHPlot Example: Line graph, 2 lines

require_once 'phplot.php';

# Generate data for:

$end = 5;

$delta = 0.1;

$data = array();

for ($x = 0; $x <= $end; $x += $delta)

  $data[] = array('', $x, pow($x,2));

$plot = new PHPlot(800, 600);

$plot->SetImageBorderType('plain');

$plot->SetPlotType('lines');

$plot->SetDataType('data-data');

$plot->SetDataValues($data);

# Main plot title:

$plot->SetTitle('Line Plot, X Squared');

# Make a legend for the 2 functions:

$plot->SetLegend(array('x^2'));

# Select a plot area and force ticks to nice values:

$plot->SetPlotAreaWorld(0, 0, 5, 25);

# Even though the data labels are empty, with numeric formatting they

# will be output as zeros unless we turn them off:

$plot->SetXDataLabelPos('none');

$plot->SetXTickIncrement(0.5);

$plot->SetXLabelType('data');

$plot->SetPrecisionX(1);

$plot->SetYTickIncrement(2);

$plot->SetYLabelType('data');

$plot->SetPrecisionY(1);

# Draw both grids:

$plot->SetDrawXGrid(True);

$plot->SetDrawYGrid(True);

$plot->DrawGraph();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2017 Mar 23, 2017
LATEST

Thank you Servitor.

I am still fixing some issues with the larger equation that I am using(not x^2).

I appreciate your response and answer.

Gary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines