Question

I have installed Sage math on my ubuntu server. I can run sage commands by ssh terminal such as

$sage:   
$sage:  f = x^2
$sage:  f.diff(x)

I would like to do on a php script

exec('sage');
exec('sage: f = 5x^3');
$fprime = exec('sage: latex(f.diff(x))');

echo $fprime; 

I would expect "15x^2" as output but that's not happening .. however on ssh terminal all is good..
all help would be greatly appreciated..

Was it helpful?

Solution

I'm not completely sure of what you want to achieve. PHP's exec function executes a shell command, and that's all. Read http://fr2.php.net/manual/en/function.exec.php.

sage: f = 5*x^3 is not a shell command. You can run sage scripts directly via the command line using the -c switch :

./sage -c 'print latex((5*x^3).diff())'

will print 15 \, x^{2} to the terminal. In PHP you can grab this output by passing a second argument to exec:

exec("./sage -c 'print latex((5*x^3).diff())'", $output);
echo $output[0];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top