-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMat1Tools.mw
More file actions
437 lines (368 loc) · 35 KB
/
Mat1Tools.mw
File metadata and controls
437 lines (368 loc) · 35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?xml version="1.0" encoding="UTF-8"?>
<Worksheet>
<Version major="2022" minor="0"/>
<Label-Scheme value="2" prefix=""/>
<View-Properties presentation="false" autoexpanding_sections="true" UserProfileName="Maple Default Profile" NumericFormat-ApplyInteger="true" NumericFormat-ApplyRational="true" NumericFormat-ApplyExponent="false" editable="true">
</View-Properties>
<MapleNet-Properties prettyprint="3" warnlevel="3" compactdisplay="false" preplot="" helpbrowser="standard" displayprecision="-1" echo="1" scientificx="true" unitattributes=""fontweight" = "bold"" imaginaryunit="I" longdelim="true" elisiontermsthreshold="10000" elisiondigitsafter="100" elisiondigitsbefore="100" plotdevice="inline" errorbreak="1" plotoptions="" plotdriver="opengl" quiet="false" elisiontermsbefore="100" elisiontermsafter="100" historytimestamp="false" screenwidth="79" indentamount="4" plotoutput="terminal" screenpixelheight="1080" rtablesize="[10, 10]" useclientjvm="true" format="worksheet" labelwidth="20" postplot="" typesetting="extended" ansi="false" ansicolor="[]" elisiondigitsthreshold="10000" showassumed="1" ansilprint="false" trailingsemicolon="true" errorcursor="false" labelling="true" screenheight="25" prompt="> " verboseproc="1" latexwidth="8.0" ShowLabels="true"/>
<Styles>
<Font name="Heading 1" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Warning" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Output" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 4" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="true" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Line Printed Output" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 2" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="16" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Output" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Inert Output" background="[255,255,255]" bold="false" executable="true" family="Times New Roman" foreground="[144,144,144]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Heading 3" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="true" opaque="false" readonly="false" size="14" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Diagnostic" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[40,120,40]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 1" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Input" background="[255,255,255]" bold="true" executable="true" family="Courier New" foreground="[120,0,14]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Text Output" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 2" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 3" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 4" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Ordered List 5" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Annotation Title" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Header and Footer" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="10" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="HyperlinkError" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[255,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="Atomic Variable" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[175,0,175]" italic="true" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="HyperlinkWarning" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[0,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="Dictionary Hyperlink" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[147,0,15]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="2D Math" background="[255,255,255]" bold="false" executable="true" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Bullet Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Plot" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Annotation Text" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="List Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Dash Item" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="2D Input" background="[255,255,255]" bold="false" executable="true" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Error" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[255,0,255]" italic="false" opaque="false" readonly="true" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Title" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="18" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Text" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Normal" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Caption Reference" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Code" background="[255,255,255]" bold="false" executable="false" family="Courier New" foreground="[255,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Maple Input Placeholder" background="[255,255,255]" bold="true" executable="true" family="Courier New" foreground="[200,0,200]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="true"/>
<Font name="Equation Label" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Author" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Font name="Hyperlink" background="[255,255,255]" bold="false" executable="false" family="Times New Roman" foreground="[0,128,128]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="true" placeholder="false"/>
<Font name="Caption Text" background="[255,255,255]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" opaque="false" readonly="false" size="12" subscript="false" superscript="false" underline="false" placeholder="false"/>
<Layout name="Heading 1" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="4" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Warning" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 4" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Line Printed Output" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="any" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 2" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="2" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Maple Output" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.3" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Heading 3" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Diagnostic" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="any" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Ordered List 1" alignment="left" bullet="numeric" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix="."/>
<Layout name="Text Output" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="newline" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Ordered List 2" alignment="left" bullet="alphabetic" firstindent="0" leftmargin="36" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix="."/>
<Layout name="Ordered List 3" alignment="left" bullet="roman" firstindent="0" leftmargin="72" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix="."/>
<Layout name="Ordered List 4" alignment="left" bullet="ALPHABETIC" firstindent="0" leftmargin="108" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix="."/>
<Layout name="Ordered List 5" alignment="left" bullet="ROMAN" firstindent="0" leftmargin="144" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="-1" bulletsuffix="."/>
<Layout name="Annotation Title" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="12" spacebelow="12" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="HyperlinkError" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="HyperlinkWarning" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Bullet Item" alignment="left" bullet="dot" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Maple Plot" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="List Item" alignment="left" bullet="indent" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Dash Item" alignment="left" bullet="dash" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="3" spacebelow="3" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Error" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Title" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="12" spacebelow="12" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Normal" alignment="left" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="0" spacebelow="0" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Layout name="Author" alignment="centred" bullet="none" firstindent="0" leftmargin="0" rightmargin="0" linespacing="0.0" spaceabove="8" spacebelow="8" linebreak="space" pagebreak-before="false" initial="0" bulletsuffix=""/>
<Pencil-style name="Pencil 1" pen-color="[0,0,0]" pen-height="1.0" pen-width="1.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 2" pen-color="[0,0,255]" pen-height="1.0" pen-width="1.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 3" pen-color="[0,0,0]" pen-height="3.0" pen-width="3.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 4" pen-color="[0,0,255]" pen-height="3.0" pen-width="3.0" pen-opacity="1.0"/>
<Pencil-style name="Pencil 5" pen-color="[255,0,0]" pen-height="5.0" pen-width="5.0" pen-opacity="1.0"/>
<Highlighter-style name="Highlighter 5" pen-color="[255,255,0]" pen-height="48.0" pen-width="48.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 3" pen-color="[51,255,0]" pen-height="24.0" pen-width="24.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 4" pen-color="[0,255,255]" pen-height="32.0" pen-width="32.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 1" pen-color="[255,153,255]" pen-height="12.0" pen-width="8.0" pen-opacity="0.8"/>
<Highlighter-style name="Highlighter 2" pen-color="[255,204,0]" pen-height="14.0" pen-width="14.0" pen-opacity="0.8"/>
</Styles>
<Startup-Code startupcode=""/>
<Task-table>
<Task-category name="<default>"/>
</Task-table>
<Task/>
<Group labelreference="L11" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">restart</Text-field>
</Input>
</Group>
<Group hide-input="false" labelreference="L1" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">Mat1Tools := module()
description "Tools used in the DTU course 01005 - Advanced Engineering Mathematics 1";
option package;
export
dot, prik, cross, kryds, vop, intervalsolve, paraplot, grad, srhs, slhs, condgf, vlen, div, jacobi, curl, rot, pint, flux, vsolve, tint, com, pnorm, plotnorm, hessian;
local columnMatrixToVector;
with(LinearAlgebra):
with(plots):
with(Integrator8):
columnMatrixToVector := proc(X)
if LinearAlgebra[ColumnDimension](X) = 1 and type(X, Matrix) then
return convert(X,Vector):
else
return X:
end if;
end proc:
dot := proc(x::Vector,y::Vector)
description "Scalar product, dot product of two vectors; Takes two vectors and returns the dot product of them. dot(<a,b>,<c,d>) -> a*c + b*d":
return VectorCalculus[DotProduct](columnMatrixToVector(x),columnMatrixToVector(y));
end proc:
prik:= dot:
cross := proc(x::Vector, y::Vector)
description "Cartesian product, cross product of two vectors. Takes two 3 dimensional vectors and returns the cross
product/normal vector of them. cross(<a,b,c>,<d,e,f>) -> <b*f - c*e, -a*f + c*d, a*e - b*d]>":
return convert(VectorCalculus[CrossProduct](columnMatrixToVector(x),columnMatrixToVector(y)),Vector);
end proc:
kryds := cross:
vlen := proc(v::Vector)
description "Computes the length of the given vector. I.e. vlen(<x,y>) -> sqrt(x^2 + y^2)":
return sqrt(dot(v, v));
end proc:
vop := proc(v)
description "Extract operands from a vector expression. I.e. vop(<1,2,3>) -> 1,2,3";
return op(convert(v,list));
end proc:
intervalsolve := Student[Calculus1][Roots]:
paraplot := proc(r::{procedure},range::{list(range)})
description "Parametric plot (paraplot) is a function which plots parametric equations. Takes the parametric equation and a list of ranges for the variables in the parametric equation.":
local var,i; var:=op(1,eval(r)):
if (numelems(range)=1) then
if (numelems(r(var))=2) then
return plot([vop(r(var)),var=range[1]],_rest); # Kurve i 2D
else
return plot3d(r(var),var=range[1],_rest) # Kurve i 3D
end if:
elif (numelems(range)=2) then
if (numelems(r(var))=2) then
return plot3d(<r(var),0>,var[1]=range[1],var[2]=range[2],orientation=[-90,0],lightmodel=none,_rest); # Plan i 2D
else
return plot3d(r(var),var[1]=range[1],var[2]=range[2],_rest); # Flade i 3D
end if:
elif (numelems([var])=3) then
return plots[display](Integrator8[sideFlader](r,[seq(vop(convert(range[i],list)),i=1..3)],[8,8,8]),_rest);
end if;
end proc:
grad:= proc(f::{procedure},x::{list})
description "Computes the gradient of the given function, with regard to the passed variables. I.e. grad(unapply(x+y,x,y),[x,y]) -> <1,1>.":
return convert(VectorCalculus[Gradient](f(vop(x)),x),Vector[column]);
end proc:
srhs := proc(X, type:=whattype(X))
description "Takes a list, vector, column matrix, or similar containing only equations and returns the right-hand side of the equations. slhs([x=0,y=10,z=15]) -> [0,10,15]":
local i, l:
l := convert(X, list):
return convert([seq(rhs(l[i]),i=1..numelems(l))],type);
end proc:
slhs := proc(X, type:=whattype(X))
description "Takes a list, vector, column matrix, or similar containing only equations and returns the left-hand side of the equations. slhs([x=0,y=10,z=15]) -> [x,y,z]":
local i, l:
l := convert(X, list):
return convert([seq(lhs(l[i]),i=1..numelems(l))],type);
end proc:
condgf := proc(V, $)
description "Takes a vector field in 2 or 3 dimensions as a list, vector, or similar and checks if it lives up to the mandatory criteria for being a gradient field. checkGradient(<y*cos(x*y), z+x*cos(x*y), y>) -> Condition satisfied.":
if numelems(V) > 3 then
return "The vectorfield must have a dimension of at most 3.";
elif numelems(V) < 2 then
return "The vectorfield must have a dimension of at least 2.";
elif numelems(V) = 2 then
if simplify(diff(V[1],y)) <> simplify(diff(V[2],x)) then
return "Not gradient field. ", Diff(V__1,y) <> Diff(V__2,x)
else
return "Condition satisfied."
end if;
else
if simplify(diff(V[1],y)) <> simplify(diff(V[2],x)) then
return "Not gradient field. ", Diff(V__1,y) <> Diff(V__2,x)
elif simplify(diff(V[1],z)) <> simplify(diff(V[3],x)) then
return "Not gradient field. ", Diff(V__1,z) <> Diff(V__3,x)
elif simplify(diff(V[2],z)) <> simplify(diff(V[3],y)) then
return "Not gradient field. ", Diff(V__2,z) <> Diff(V__3,y)
else
return "Condition satisfied."
end if;
end if;
end proc:
div := proc(V::{Vector, procedure})
description "Creates a procedure/function for the divergence of the passed vector field.":
local v;
if type(V, procedure) then
v := V(op(1, eval(V)));
else
v := V;
end if;
if numelems(v) = 2 then
VectorCalculus[SetCoordinates]('cartesian'[x,y]);
unapply(VectorCalculus[Divergence](VectorCalculus[VectorField](v)), [x, y]);
else
VectorCalculus[SetCoordinates]('cartesian'[x,y,z]);
unapply(VectorCalculus[Divergence](VectorCalculus[VectorField](v)), [x, y, z]);
end if;
end proc:
jacobi := proc(r::{procedure})
description "Computes the jacobi function of a parametric equation variable of up to 3 variables":
local i, var;
var := op(1, eval(r));
r := unapply(columnMatrixToVector(r(var)),var):
if numelems([var]) = 1 then
return simplify(vlen(diff(r(var), var))) assuming var::real;
elif numelems([var]) = 2 and numelems(r(var)) = 2 then
return simplify(abs(VectorCalculus[Jacobian](r(var), [var], determinant)[2])) assuming var[1]::real, var[2]::real;
elif numelems([var]) = 2 then
return simplify(vlen(cross(diff(r(var), var[1]), diff(r(var), var[2])))) assuming var[1]::real, var[2]::real;
elif numelems([var]) = 3 then
return simplify(abs(VectorCalculus[Jacobian](r(var), [var], determinant)[2])) assuming var[1]::real, var[2]::real, var[3]::real;
else
return "Incorrect number of dimensions";
end if;
end proc:
curl := proc(V::{Vector, procedure})
description "Creates a rotation procedure/function for the given vector field.":
local v, var;
VectorCalculus:-BasisFormat(false);
if type(V, procedure) then
v := V(op(1, VectorCalculus:-eval(V)));
var := [op(1, VectorCalculus:-eval(V))];
return unapply(VectorCalculus:-Curl(Student[VectorCalculus][VectorCalculus:-VectorField](v)), var);
else
v := V;
return VectorCalculus:-Curl(Student[VectorCalculus][VectorCalculus:-VectorField](v));
end if;
end proc:
rot := curl:
pint := proc(r::{procedure}, integrateRange::{list(range)}, f::{procedure} := 1)
description "Paramatric equation integration (pint) integrates the parametric equation given in the given intervals, optionally with the provided weight function.":
local var, i;
var := [op(1, eval(r))];
return simplify(int(f(vop(r(vop(var))))*jacobi(r), seq(var[i] = integrateRange[i], i = 1 .. numelems(integrateRange))));
end proc:
flux:= proc(V::{procedure}, r::{procedure}, integrateRange::{list(range)})
description "Computes the flux of the provided 3D vector field throughout the provided parameterized surface or solid object (assuming it's closed) in the given intervals.":
local var, i;
var := op(1, eval(r));
if numelems([var]) = 2 then:
return int(dot(convert(V(vop(r(var))), Vector), pnorm(r)(var)), var[1]=integrateRange[1], var[2]=integrateRange[2]);
elif numelems([var]) = 3 then:
# Gauss divergence theorem
return int(
div(V)(vop(r(var)))*jacobi(r),
var[1]=integrateRange[1], var[2]=integrateRange[2], var[3]=integrateRange[3]);
else:
return "Can only determine flux of surfaces. (Too many variables received)";
end if:
end proc:
vsolve := proc(veq, vars)
description "Solves the given vector equation for the variables defined in the second argument.":
local i, s, l, r, subeq:
l := lhs(veq):
r := rhs(veq):
subeq := []:
if not numelems(l) = numelems(r) then
return "Left and right side of equation must be of equal size";
end if;
# Create sub equations
for i from 1 to numelems(l) do
subeq := [op(subeq),l[i] = r[i]]:
end do:
s := solve(subeq,vars):
if not s = NULL then
return s;
else
return "No solutions found";
end if;
end proc:
tint := proc(V::{procedure}, r::{procedure}, integrateRange::{range})
description "Calculates the tangential line integral of a vector field V along a given line with the parametric equation r.
V := (x,y) -> <-y,x>:
r:=u-><cos(u),sin(u)>:
interval:=0..2*Pi:
tint(V,r,interval)->2*Pi":
local var;
var := op(1,eval(r));
return simplify(int(dot(V(vop(r(var))), diff(r(var),var)),var=integrateRange))
end proc:
com := proc(f::{procedure}, r::{procedure}, integrateRange::{list(range)})
description "Determines the center of mass (COM) given the weight function f, the parametric equation r and it's variable intervals.":
local var, i, jac, coordinate__funcs, coordinate_integrals, mass_func, coordinate_func, mass:
var := [op(1, eval(r))]:
jac := jacobi(r):
mass := pint(r,integrateRange,f):
mass_func := f(vop(r(vop(var)))):
coordinate__funcs := seq(r(vop(var))[i],i=1..numelems(var)):
coordinate_integrals := []:
for coordinate_func in coordinate__funcs do:
coordinate_integrals := [op(coordinate_integrals), int(mass_func*coordinate_func*jac, seq(var[i] = integrateRange[i], i = 1 .. numelems(integrateRange)))]:
end do:
1/mass*convert(coordinate_integrals,Vector);
end proc:
pnorm := proc(r::{procedure})
description "Determines the normal vector of the parameterized surface given as r.
r := (u,v) -> <u,0,v>:
pnorm(r)-><0,-1,0>";
local var:
var := op(1,eval(r)):
if not numelems([var]) = 2 then:
return "Parametric equation must be a surface"
else:
return unapply((simplify(cross(
diff(r(var),var[1]),
diff(r(var),var[2]))) assuming (var[1])::real assuming (var[2])::real),
var);
end if:
end proc:
plotnorm := proc(r::{procedure}, limits::{list(range)})
local var, i, var_vals;
description "Plots the normal vector of the parameterized surface given as r.";
var := op(1,eval(r));
if (nops([var]) <> 2) then
return "Parametric equation must be a surface";
end if;
if (nops(limits) <> nops([var])) then
return "Wrong number of limits";
end if;
var_vals := seq((op(limits[i])[1]+op(limits[i])[2])/2, i=1..nops(limits));
plots[display](paraplot(r, limits),plots[arrow](r(var_vals), pnorm(r)(var_vals), length=1));
end proc;
hessian := proc(f::{procedure})
description "Creates a procedure/function for the hessianmatrix of a given function.
f := (x,y) -> x^2 + y^2 + x*y:
hessian(f)-><2, 1; 1, 2>":
local vars:
vars := op(1,eval(f)):
unapply(VectorCalculus[Hessian](f(vars),[vars]),vars);
end proc:
end module;</Text-field>
</Input>
<Output><Text-field style="2D Output" layout="Maple Output"><Equation executable="false" style="2D Output" display="LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEqTWF0MVRvb2xzRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEpJkFzc2lnbjtGJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1GIzYrLUY2Ni9RJ21vZHVsZUYnLyUlYm9sZEdGMS9GM1ElYm9sZEYnLyUrZm9udHdlaWdodEdGV0Y7Rj5GQEZCRkRGRkZIL0ZLUSYwLjBlbUYnL0ZORmVuLUkobWZlbmNlZEdGJDYkLUYjNiYtRiw2I1EhRicvJStmb3JlZ3JvdW5kR1EoWzAsMCwwXUYnLyUpcmVhZG9ubHlHRj1GOUY5LUknbXNwYWNlR0YkNiYvJSdoZWlnaHRHUSYwLjBleEYnLyUmd2lkdGhHUSYwLjVlbUYnLyUmZGVwdGhHRmlvLyUqbGluZWJyZWFrR1ExZmlyc3Rwcm9jbmV3bGluZUYnLUY2Ni1RJC4uLkYnRjlGO0Y+RkBGQkZERkZGSC9GS1EsMC4yMjIyMjIyZW1GJ0Zmbi1GZW82JkZnb0Zqb0ZdcC9GYHBRNmRlY3JlYXNlaW5kZW50bmV3bGluZUYnLUY2Ni9RK2VuZH5tb2R1bGVGJ0ZURlZGWEY7Rj5GQEZCRkRGRkZIRlpGZm5GX29GYm9GOUY5">LV9JLFR5cGVzZXR0aW5nRzYkJSpwcm90ZWN0ZWRHSShfc3lzbGliRzYiSSxtcHJpbnRzbGFzaEdGKDYkNyM+SSpNYXQxVG9vbHNHRihgNjpJJGRvdEc2JEYmL0knX2xvY2FsR0YmSTBfbjE4OTE1MTIxNjMwNzJHRihJJXByaWtHNiRGJi9GM0kwX24xODkxNTEyMTYzMDA4R0YoSSZjcm9zc0c2JEYmL0YzSTBfbjE4OTE1MTIxNjI5NzZHRihJJmtyeWRzRzYkRiYvRjNJMF9uMTg5MTUxMjE2Mjk0NEdGKEkkdm9wRzYkRiYvRjNJMF9uMTg5MTUxMjE2MjkxMkdGKEkuaW50ZXJ2YWxzb2x2ZUc2JEYmL0YzSTBfbjE4OTE1MTI5NzY3MjBHRihJKXBhcmFwbG90RzYkRiYvRjNJMF9uMTg5MTUxMjk3NjY4MEdGKEklZ3JhZEc2JEYmL0YzSTBfbjE4OTE1MTIxNjI4ODBHRihJJXNyaHNHNiRGJi9GM0kwX24xODkxNTEyMTYyODQ4R0YoSSVzbGhzRzYkRiYvRjNJMF9uMTg5MTUxMjE2MjgxNkdGKEknY29uZGdmRzYkRiYvRjNJMF9uMTg5MTUxMjE2Mjc4NEdGKEkldmxlbkc2JEYmL0YzSTBfbjE4OTE1MTIxNjI3NTJHRihJJGRpdkc2JEYmL0YzSTBfbjE4OTE1MTIxNjI3MjBHRihJJ2phY29iaUc2JEYmL0YzSTBfbjE4OTE1MTIxNjI2ODhHRihJJWN1cmxHNiRGJi9GM0kwX24xODkxNTEyMTYyNjU2R0YoSSRyb3RHNiRGJi9GM0kwX24xODkxNTEyMTYyNjI0R0YoSSVwaW50RzYkRiYvRjNJMF9uMTg5MTUxMjE2MjU5MkdGKEklZmx1eEc2JEYmL0YzSTBfbjE4OTE1MTIxNjI1NjBHRihJJ3Zzb2x2ZUc2JEYmL0YzSTBfbjE4OTE1MTIxNjI1MjhHRihJJXRpbnRHNiRGJi9GM0kwX24xODkxNTEyMTYyNDk2R0YoSSRjb21HNiRGJi9GM0kwX24xODkxNTEyMTYyNDY0R0YoSSZwbm9ybUc2JEYmL0YzSTBfbjE4OTE1MTIxNjI0MzJHRihJKXBsb3Rub3JtRzYkRiYvRjNJMF9uMTg5MTUxMjk3NjY0MEdGKEkoaGVzc2lhbkc2JEYmL0YzSTBfbjE4OTE1MTIxNjI0MDBHRihJMF9tMTg5MTUxMjE2MzEwNEdGKDYjSTVjb2x1bW5NYXRyaXhUb1ZlY3Rvckc2Iy9GM0kwX24xODkxNTExNzE3OTM2R0YoNyNGLg==</Equation></Text-field>
</Output>
</Group>
<Group labelreference="L4" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">packageName := "Mat1Tools.mla":</Text-field>
</Input>
</Group>
<Section collapsed="false" isCollapsible="true" drawButton="true" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title><Text-field style="Heading 1" layout="Heading 1">maple/lib dir</Text-field></Title>
<Group hide-input="false" labelreference="L8" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">savepath := FileTools:-JoinPath(["lib",packageName],base=mapledir): # Maple/lib</Text-field>
</Input>
</Group>
</Section>
<Section collapsed="false" isCollapsible="true" drawButton="true" MultipleChoiceAnswerIndex="-1" MultipleChoiceRandomizeChoices="false" TrueFalseAnswerIndex="-1" EssayAnswerRows="5" EssayAnswerColumns="60"><Title><Text-field style="Heading 1" layout="Heading 1">Current dir</Text-field></Title>
<Group hide-input="false" labelreference="L9" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">savepath := cat(currentdir(),kernelopts(dirsep),packageName): # Current dir</Text-field>
</Input>
</Group>
</Section>
<Group labelreference="L3" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal">savelib('Mat1Tools',savepath);</Text-field>
</Input>
</Group>
<Group labelreference="L10" drawlabel="true" applyint="true" applyrational="true" applyexponent="false">
<Input><Text-field prompt="> " style="Maple Input" layout="Normal"></Text-field>
</Input>
</Group>
</Worksheet>