This only works with MathJax inline SVG and Console output at the moment.
using the gnuplot syntax:
local symmath = require 'symmath'
local GnuPlot = symmath.export.GnuPlot
GnuPlot:plot{
title = 'test plot',
xrange = {-2,2},
{'x**2.', title='test plot "x**2."'},
{'x**3.', title='test plot "x**3."'},
}
using symmath expressions:
local symmath = require 'symmath'
local GnuPlot = symmath.export.GnuPlot
local x = symmath.var'x'
GnuPlot:plot{
title = 'test expression',
xrange = {-2,2},
{x^2, title=GnuPlot(x^2)},
{x^3, title=GnuPlot(x^3)},
}
using plot member function:
local symmath = require 'symmath'
local x = symmath.var'x'
-- unless it's assigned to another var, or an argument of a function call, math operators will screw up Lua grammar so a subsequent member call is ignored
-- to get around this I'm wrapping the call in print()
-- but take note: (x^2):plot(...) will cause a Lua error
print((x^2):plot{
title = 'test expression',
xrange = {-2,2},
{title=GnuPlot(x^2)}, -- the first table is assumed to be associated with the calling expression
})
using Lua data for formula:
local symmath = require 'symmath'
local GnuPlot = symmath.export.GnuPlot
local n = 50
local xmin, xmax = -10, 10
local xs, ys = {}, {}
for i=1,n do
local x = (i-.5)/n * (xmax - xmin) + xmin
xs[i] = x
ys[i] = math.sin(x) / x
end
GnuPlot:plot{
title = 'test data title',
style = 'data linespoints',
data = {xs, ys},
{using = '1:2', title = 'test data sin(x)/x'},
}
using symmath expressions, code generation, and Lua data:
local symmath = require 'symmath'
local GnuPlot = symmath.export.GnuPlot
local x = symmath.var'x'
local f = symmath.sin(x) / x
local ff = symmath.export.Lua:toFunc{input={x}, output={f}}
local n = 50
local xmin, xmax = -10, 10
local xs, ys = {}, {}
for i=1,n do
local x = (i-.5)/n * (xmax - xmin) + xmin
xs[i] = x
ys[i] = ff(x)
end
GnuPlot:plot{
title = 'test data title',
style = 'data linespoints',
data = {xs, ys},
{using = '1:2', title = 'test data '..export.GnuPlot(f)},
}
using the gnuplot syntax:
local symmath = require 'symmath'
local GnuPlot = symmath.export.GnuPlot
print'