with(plots): with(linalg): # Usage plot_pargrm([vec1,vec2],optional_color,optional_thickness) plot_pargrm_2d := proc( vecs::list) local vec1, vec2,gr,color_name, thickness_val; if (nargs < 3) then thickness_val := 3; else thickness_val := args[3]; fi: if (nargs < 2) then color_name := red else color_name := args[2] fi: vec1 := op(1,vecs); vec2 := op(2,vecs); gr := polygonplot(map(convert,[[0,0],vec1,evalm(vec1+vec2),vec2],list),color=eval(color_name),thickness=thickness_val): end: pargrm_image_2d := proc(vecs::list, A::array ) local vec1, vec2, im_vec1, im_vec2, gr_orig, gr_new,color_name, thickness_val; if (nargs < 4) then thickness_val :=3 else thickness_val := args[4] fi: if (nargs < 3) then color_name := red; else color_name := args[3]; fi: vec1 := op(1,vecs); vec2 := op(2,vecs); im_vec1 := evalm(A &* vec1); im_vec2 := evalm(A &* vec2); gr_orig := plot_pargrm_2d([vec1, vec2 ], blue); gr_new := plot_pargrm_2d([im_vec1,im_vec2], color_name, thickness_val); [gr_orig,gr_new]; end: help_pargrm_2d := proc() printf(`Basic Usage is:\n`); printf(`\n`); printf(`\t\tgr := plot_pargrm_2d([ v1, v2 ], A)\n`); printf(`\t\tdisplay(gr);\n`); printf(`\n`); printf(`where v1 and v2 are vectors in R^2 and A is a 2 by 2 matrix.\n`); printf(`\n`); printf(`The parallelogram with vertices 0, v1, v1+v2, and v2 is drawn in blue.\n`); printf(`The parallelogram with vertices 0, Av1, A(v1+v2), and Av2 is drawn in red.\n`); printf(`\n`); end: # Usage plot_pargrm([vec1,vec2,vec3],optional_color,optional_thickness) plot_pargrm_3d := proc( vecs::list) local vec1, vec2,vec3,gr,color_name, thickness_val; if (nargs < 3) then thickness_val := 3; else thickness_val := args[3]; fi: if (nargs < 2) then color_name := red else color_name := args[2] fi: vec1 := op(1,vecs); vec2 := op(2,vecs); vec3 := op(3,vecs); gr := polygonplot3d([map(convert,[[0,0,0],vec1,evalm(vec1+vec2),vec2],list),map(convert,[[0,0,0],vec1,evalm(vec1+vec3),vec3],list),map(convert,[[0,0,0],vec2,evalm(vec3+vec2),vec3],list),map(convert,[vec3,evalm(vec1+vec3),evalm(vec1+vec2+vec3),evalm(vec2+vec3)],list),map(convert,[vec2,evalm(vec1+vec2),evalm(vec1+vec2+vec3),evalm(vec2+vec3)],list),map(convert,[vec1,evalm(vec2+vec1),evalm(vec3+vec2+vec1),evalm(vec3+vec1)],list)],color=eval(color_name),thickness=thickness_val): end: pargrm_image_3d := proc(vecs::list, A::array ) local vec1, vec2, vec3, im_vec1, im_vec2, im_vec3, gr_orig, gr_new,color_name, thickness_val; if (nargs < 4) then thickness_val :=3 else thickness_val := args[4] fi: if (nargs < 3) then color_name := red; else color_name := args[3]; fi: vec1 := op(1,vecs); vec2 := op(2,vecs); vec3 := op(3,vecs); im_vec1 := evalm(A &* vec1); im_vec2 := evalm(A &* vec2); im_vec3 := evalm(A &* vec3); gr_orig := plot_pargrm_3d([vec1, vec2,vec3 ], blue); gr_new := plot_pargrm_3d([im_vec1,im_vec2,im_vec3], color_name, thickness_val); [gr_orig,gr_new]; end: help_pargrm_3d := proc() printf(`Basic Usage is:\n`); printf(`\n`); printf(`\t\tgr := plot_pargrm_3d([v1, v2, v3], A);\n`); printf(`\t\tdisplay(gr);\n`); printf(`\n`); printf(`where v1, v2, and v3 are vectors in R^3 and A is a 3 by 3 matrix.\n`); printf(`\n`); printf(`The parallelopiped with vertex at 0 and edges from 0 of v1, v2, and v3 is drawn in blue.\n`); printf(`The parallelopiped with vertex at 0 and edges from 0 of Av1, Av2, and Av3 is drawn in red.\n`); printf(`\n`); printf(`One may also specify color and thickness as optional additional arguments,e.g.:\n`); printf(`\n`); printf(`\t\tgr := plot_pargrm_3d([v1, v2, v3], A, red, 2);\n`); printf(`\n`); end: #help_pargrm_3d(); #help_pargrm_2d(); help_pargrm := proc() help_pargrm_2d(); printf(`There is also a function\n\t help_pargrm_3d();\ndescribing the 3 dimensional case.\n`); end: help_pargrm();