Creation of Sets/Array in z^3
Jump to navigation
Jump to search
Tricks and Shortcuts
Description
*Creating an Array
- Comma(,) has to be used to separate the elements(especially when negative numbers are in an array). This removes the ambiguity.
For example:(without comma)
a = [1 2 3; -4*5 -4 6; 7 8 10]
This gives the answer as:
a = 1 2 3
-24 6
7 8 10
with comma:
a = [1 2 3; -4*5, -4 6; 7 8 10]
a = 1 2 3
-20 -4 6
7 8 10
*Notations
- The unit operators work for simple or matrix parameters on both sides. This makes |-| be available for non-unit based subtraction. This is possibly a better notation.
- To do unit based subtractions, do
A=[1m 2m]; B=[4m 5m]; c=A<->B c = [-3m -3m]
- Matrix subtraction, without units.
A=[1m 2m]; B=[4m 5m]; c=A|-|B c = [-3 -3]
*Creating an Array within an interval
- An array can be created within a given interval using this notation. Brackets() are important.
var x = []; xmin = 1 xmax = 2 dx = 0.2 x = (xmin-dx)..(xmax+dx)..(dx); x = [0.8 1 1.2000000000000002 1.4000000000000001 1.6 1.8 2 2.2]
- To get the inverse of a matrix, add ~ to the array.
x = ((xmin-dx)..(xmax+dx)..(dx))
n = x~
n = 0.8
1
1.2000000000000002
1.4000000000000001
1.6
1.8
2
2.2
*Evaluating a Function
- Calculating the value of function "u0" with corresponding values of x.
var x = []; var u0 = []; xmin = 1 xmax = 2 dx = 0.2 x = (xmin-dx)..(xmax+dx)..(dx); u0 = EXP(-2<*>(x|-|0.25)<^>2); u0 = [0.5460744266397094 0.32465246735834974 0.16447445657715493 0.07100535373963703 0.026121409853918226 0.008188701014374078 0.002187491118182886 0.0004979554215032733]
*PLOT
- Graph of x vs u0: Merge x and u0~ arrays using "mergerows" and include .graphin() to plot.
var x =[]; var u0 = []; xmin = 1 xmax = 2 dx = 0.2 x = (xmin-dx)..(xmax+dx)..(dx); u0 = EXP(-2<*>(x<->0.25)<^>2); m = (x).mergerows(u0~).graphin()
The graph looks as shown below.