📄 input-matrix-operations4
字号:
/* =================================================== */
/* MATRIX OEPRATION IV */
/* */
/* Tests matrix and quantity conversions */
/* =================================================== */
/***********************************/
/* CONVERT FROM MATRIX TO QUANTITY */
/***********************************/
print "\n====== CONVERT MATRIX TO QUANTITY =======\n";
print "\n==== Extract a matrix element from a matrix \n";
X = [ 3, 4, 5; 6, 79, 100; 3, 4, 5];
X = RowUnits(X, [km], [1]);
X = RowUnits(X, [sec], [3]);
X = ColumnUnits(X, [MPa], [1]);
X = ColumnUnits(X, [N*m], [3]);
PrintMatrix(X);
print "\n X[1][1] = ", X[1][1], "\n";
print " X[1][2] = ", X[1][2], "\n";
print " X[1][3] = ", X[1][3], "\n";
print " X[2][1] = ", X[2][1], "\n";
print " X[2][2] = ", X[2][2], "\n";
print " X[2][3] = ", X[2][3], "\n";
print " X[3][1] = ", X[3][1], "\n";
print " X[3][2] = ", X[3][2], "\n";
print " X[3][3] = ", X[3][3], "\n";
print "\n==== Assign matrix element with a quantity of same units \n";
X[1][1] = 2*X[1][1];
X[1][2] = 2*X[1][2];
X[1][3] = 2*X[1][3];
X[2][1] = 2*X[2][1];
X[2][2] = 2*X[2][2];
X[2][3] = 2*X[2][3];
X[3][1] = 2*X[3][1];
X[3][2] = 2*X[3][2];
X[3][3] = 2*X[3][3];
PrintMatrix(X);
print "\n==== Assign matrix element with a quantity of different units \n";
X[1][1] = 2 m;
print "\n X[1][1] = ", X[1][1], "\n";
print "\n==== Assign a non-dimensional matrix element with a quantity with units \n";
X[2][2] = 2 m;
print "\n X[2][2] = ", X[2][2], "\n";
PrintMatrix(X);
print "\n==== Cast a 1x1 matrix into a quantity \n";
X = [100 kPa];
PrintMatrix(X);
print "\n X = ", QuanCast(X), "\n";
print "\n==== Calculate the Euclidean Norm of a vector matrix \n";
X = [1, 2, 3, 4, 5];
Y = [1; 2; 3; 4; 5];
U = L2Norm(X);
V = L2Norm(Y);
PrintMatrix(X, Y);
print "\n";
print "Euclidean Norm of [X] = ", U, "\n";
print "Euclidean Norm of [Y] = ", V, "\n";
X = [1 m, 2 m , 3E-3 km, 4 m, 5 m];
Y = [1 m; 2 m ; 3E-3 km; 4 m; 5 m];
U = L2Norm(X);
V = L2Norm(Y);
PrintMatrix(X, Y);
print "Euclidean Norm of [X] = ", U, "\n";
print "Euclidean Norm of [Y] = ", V, "\n";
print "\n====== SCALE MATRIX =======\n";
print "\n== Amplify Matrix Content by a factor of 2 \n";
X = One([4]);
X = ColumnUnits(X, [ksi, lbf, ksi, ft]);
X = RowUnits(X, [psi, in, kips, lb]);
Y = X*2;
Z = 2*X;
PrintMatrix(X, Y, Z);
print "\n== Amplify Matrix Content by a factor of 2 in \n";
Y = X*2 in;
Z = (2 in)*X;
PrintMatrix(X, Y, Z);
print "\n== Reduce Matrix Content by a factor of 2 in \n";
print "X [1][4] = ", X[1][4],"\n";
Y = X/2 in;
print "Y [1][4] = ", Y[1][4],"\n";
PrintMatrix(X, Y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -