Application Center - Maplesoft

App Preview:

Plot with Grid

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Plot_with_Grids.mws

Plot with Grid

Yufang Hao, yhao@student.math.uwaterloo.ca

This worksheet contains a simple user-defined procedure that plots a function with grid.

>   

>    restart;

>    # pre: f - the function to be plotted
#      x1 - lower bound of the domain x
#      x2 - upper bound of the domain x
#      y1 - lower bound of the range y
#      y2 - upper bound of the range y
#      m - number of vertical lines in grids
#      n - number of horizontal lines in grids
# post: the function is plotted with grids
plotwithgrids := proc(f,x1,x2,y1,y2,m,n)
  local ver_lines, hor_lines, f_plot:
    hor_lines := seq(plottools[line]([x1,y1+i*(y2-y1)/n],
                     [x2,y1+i*(y2-y1)/n],color=green),i=0..n):
    ver_lines := seq(plottools[line]([x1+i*(x2-x1)/m,y1],
                     [x1+i*(x2-x1)/m,y2],color=red),i=0..m):
    f_plot := plot(f,x1..x2,color=blue, thickness=2):
    plots[display](ver_lines,hor_lines,f_plot):
end proc: # end proc

>    plotwithgrids(sqrt,0,4,0,2,20,10);

[Maple Plot]

>    plotwithgrids(sin,0,2*Pi,-1,1,16,8);

[Maple Plot]

>   

>