I am trying to design a question, where studenst have to find the equation of a linear function given its graph. For this to work, I have to be able to draw gridlines, which for some reason is not possible in Maple TA with the ordinary plot function. I know it should be possible using an applet; given the problems this is going to create with all the different browsers, however, this is not a viable solution. I have found another solution which is unreasonably complex but should work. The problem is that sometimes it doesn't work. When I press Refresh algorithm preview in the Question Designer I get "Broken Maple plot. Verify your plot statement" roughly every third time I refresh the preview. Any help would be greatly appreciated.

The algorithm is here:

$a1=range(-4,4,1);

$a2=range(1,4,1);

condition:not(eq($a1,$a2));

$px=range(0,5,1);

$y0=range(0,5,1);

$x0=if(gt($a1,0),$px,-$px);

$f=$a1/$a2*(x-$x0)+$y0;

$G=plotmaple("

plots[display](

[plots[coordplot](cartesian, [-10 .. 10, -10 .. 10], grid = [11, 11], color = grey),

plot($f, x = -10 .. 10, y = -10 .. 10, color = [green, blue, red], thickness = 2, tickmarks = [[1], [1]], labels = [``, ``]),

plots[textplot]([0, 10, 'y'], align = {above, right}),

plots[textplot]([10, 0, 'x'], align = {above, right})

],

labels = [``, ``], axes = normal, view = [-10 .. 10, -10 .. 10]),

plotoptions='width=350,height=350'");

$g=gcd($a1,$a2);

$at=$a1/$g;

$an=$a2/$g;

$a=if(eq($an,1),$at,$at/$an);

$ans=$a*x+($y0-$a*$x0);