You are viewing this question as it will appear in the manual grading interface. Return to the normal view when you are done.

Element pl-variable-output: Display matrix and scalar data

The questions below were designed to showcase the different features of pl-variable-output. The goal of pl-variable-output is to allow users to easily copy parameters (scalar values or 2D matrices) for various computational tools.

Within this question, you can observe the default behavior of the pl-variable-output element. In particular, the default matrix output has Matlab, Mathematica, and NumPy tabs. The default active tab is Matlab, this can be changed using the attribute default-tab. This element has the ability to display any 2D matrix or scalar value and they are displayed with 2 digits after the decimal.

1
2
3
4
5
a = 5.00;
d = 37.75;
x = [5.00, 9.00, 5.00];
x1 = [5.00 9.00; 5.00 9.00];
x2 = [5.00 9.00 5.00; 5.00 9.00 5.00; 5.00 9.00 5.00];
1
2
3
4
5
a = 5.00;
d = 37.75;
x = {5, 9, 5};
x1 = {{5, 9}, {5, 9}};
x2 = {{5, 9, 5}, {5, 9, 5}, {5, 9, 5}};
1
2
3
4
5
6
7
import numpy as np

a = 5.00
d = 37.75
x = np.array([5, 9, 5])
x1 = np.array([[5, 9], [5, 9]])
x2 = np.array([[5, 9, 5], [5, 9, 5], [5, 9, 5]])
1
2
3
4
5
a = 5.00
d = 37.75
x = c(5, 9, 5)
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
x2 = matrix(c(5, 9, 5, 5, 9, 5, 5, 9, 5), nrow = 3, ncol = 3, byrow = TRUE)
1
2
3
4
5
6
7
from sympy import *

a = 5.00
d = 37.75
x = Matrix([5, 9, 5])
x1 = Matrix([[5, 9], [5, 9]])
x2 = Matrix([[5, 9, 5], [5, 9, 5], [5, 9, 5]])

This example lowers the number of displayed digits to 0 for the entire element and introduces comments for each variable. This uses the optional element parameter digits.

1
2
x = [5, 9, 5]; % This is an array
x1 = [5 9; 5 9]; % This is a 2D matrix
1
2
x = {5, 9, 5}; (* This is an array *)
x1 = {{5, 9}, {5, 9}}; (* This is a 2D matrix *)
1
2
3
4
import numpy as np

x = np.array([5, 9, 5]) # This is an array
x1 = np.array([[5, 9], [5, 9]]) # This is a 2D matrix
1
2
x = c(5, 9, 5) # This is an array
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE) # This is a 2D matrix
1
2
3
4
from sympy import *

x = Matrix([5, 9, 5]) # This is an array
x1 = Matrix([[5, 9], [5, 9]]) # This is a 2D matrix

Under this variant, we opt to change the number of displayed digits to 0 for the entire element, but explicitly specify 8 digits for the real number d and 2 digits for c and xC . This uses the optional variable parameter digits.

1
2
3
4
5
a = 5;
b = 9;
d = 37.75189198;
c = 0.88;
xC = [0.88, 5.00, 0.88];
1
2
3
4
5
a = 5;
b = 9;
d = 37.75189198;
c = 0.88;
xC = {0.88, 5.00, 0.88};
1
2
3
4
5
6
7
import numpy as np

a = 5
b = 9
d = 37.75189198
c = 0.88
xC = np.array([0.88, 5.00, 0.88])
1
2
3
4
5
a = 5
b = 9
d = 37.75189198
c = 0.88
xC = c(0.88, 5.00, 0.88)
1
2
3
4
5
6
7
from sympy import *

a = 5
b = 9
d = 37.75189198
c = 0.88
xC = Matrix([0.88, 5.00, 0.88])

The variables in the Mathematica tab are reformatted if they are reserved in Mathematica (C, D, E, I, K, N, O). These reserved variables are appended with an 'm' in the Mathematica tab only.

1
2
3
4
5
6
7
C = [5, 9, 5]; % The Mathematica tab adds an 'm' to the variable name
D = [5 9; 5 9];
E = 9;
I = 5;
K = 9;
N = 5;
O = 9;
1
2
3
4
5
6
7
Cm = {5, 9, 5}; (* The Mathematica tab adds an 'm' to the variable name *)
Dm = {{5, 9}, {5, 9}};
Em = 9;
Im = 5;
Km = 9;
Nm = 5;
Om = 9;
1
2
3
4
5
6
7
8
9
import numpy as np

C = np.array([5, 9, 5]) # The Mathematica tab adds an 'm' to the variable name
D = np.array([[5, 9], [5, 9]])
E = 9
I = 5
K = 9
N = 5
O = 9
1
2
3
4
5
6
7
C = c(5, 9, 5) # The Mathematica tab adds an 'm' to the variable name
D = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
E = 9
I = 5
K = 9
N = 5
O = 9
1
2
3
4
5
6
7
8
9
from sympy import *

C = Matrix([5, 9, 5]) # The Mathematica tab adds an 'm' to the variable name
D = Matrix([[5, 9], [5, 9]])
E = 9
I = 5
K = 9
N = 5
O = 9

The default active tab is Matlab, in this example the default active tab is NumPy. This is done by setting the optional parameter default-tab="numpy".

1
x1 = [5 9; 5 9];
1
x1 = {{5, 9}, {5, 9}};
1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

All computational languages are displayed by default. These can be turned off using the element attributes show-matlab, show-mathematica, show-numpy, and show-r. In this example, we remove the the Matlab tab. The default active tab will be the first one in the list, in this case: Mathematica.

1
x1 = {{5, 9}, {5, 9}};
1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

When a tab is not displayed, the default active tab can still be set. In this case, the Mathematica tab is hidden and NumPy is set as the default active tab.

1
d = 37.75189198;
1
2
3
import numpy as np

d = 37.75189198
1
d = 37.75189198
1
2
3
from sympy import *

d = 37.75189198

Any tab can be displayed alone. In this case, the Matlab, Mathematica, and R tabs are hidden and the NumPy tab is displayed alone.

1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

Correct answer

1
2
3
4
5
a = 5.00;
d = 37.75;
x = [5.00, 9.00, 5.00];
x1 = [5.00 9.00; 5.00 9.00];
x2 = [5.00 9.00 5.00; 5.00 9.00 5.00; 5.00 9.00 5.00];
1
2
3
4
5
a = 5.00;
d = 37.75;
x = {5, 9, 5};
x1 = {{5, 9}, {5, 9}};
x2 = {{5, 9, 5}, {5, 9, 5}, {5, 9, 5}};
1
2
3
4
5
6
7
import numpy as np

a = 5.00
d = 37.75
x = np.array([5, 9, 5])
x1 = np.array([[5, 9], [5, 9]])
x2 = np.array([[5, 9, 5], [5, 9, 5], [5, 9, 5]])
1
2
3
4
5
a = 5.00
d = 37.75
x = c(5, 9, 5)
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
x2 = matrix(c(5, 9, 5, 5, 9, 5, 5, 9, 5), nrow = 3, ncol = 3, byrow = TRUE)
1
2
3
4
5
6
7
from sympy import *

a = 5.00
d = 37.75
x = Matrix([5, 9, 5])
x1 = Matrix([[5, 9], [5, 9]])
x2 = Matrix([[5, 9, 5], [5, 9, 5], [5, 9, 5]])
1
2
x = [5, 9, 5]; % This is an array
x1 = [5 9; 5 9]; % This is a 2D matrix
1
2
x = {5, 9, 5}; (* This is an array *)
x1 = {{5, 9}, {5, 9}}; (* This is a 2D matrix *)
1
2
3
4
import numpy as np

x = np.array([5, 9, 5]) # This is an array
x1 = np.array([[5, 9], [5, 9]]) # This is a 2D matrix
1
2
x = c(5, 9, 5) # This is an array
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE) # This is a 2D matrix
1
2
3
4
from sympy import *

x = Matrix([5, 9, 5]) # This is an array
x1 = Matrix([[5, 9], [5, 9]]) # This is a 2D matrix
1
2
3
4
5
a = 5;
b = 9;
d = 37.75189198;
c = 0.88;
xC = [0.88, 5.00, 0.88];
1
2
3
4
5
a = 5;
b = 9;
d = 37.75189198;
c = 0.88;
xC = {0.88, 5.00, 0.88};
1
2
3
4
5
6
7
import numpy as np

a = 5
b = 9
d = 37.75189198
c = 0.88
xC = np.array([0.88, 5.00, 0.88])
1
2
3
4
5
a = 5
b = 9
d = 37.75189198
c = 0.88
xC = c(0.88, 5.00, 0.88)
1
2
3
4
5
6
7
from sympy import *

a = 5
b = 9
d = 37.75189198
c = 0.88
xC = Matrix([0.88, 5.00, 0.88])
1
2
3
4
5
6
7
C = [5, 9, 5]; % The Mathematica tab adds an 'm' to the variable name
D = [5 9; 5 9];
E = 9;
I = 5;
K = 9;
N = 5;
O = 9;
1
2
3
4
5
6
7
Cm = {5, 9, 5}; (* The Mathematica tab adds an 'm' to the variable name *)
Dm = {{5, 9}, {5, 9}};
Em = 9;
Im = 5;
Km = 9;
Nm = 5;
Om = 9;
1
2
3
4
5
6
7
8
9
import numpy as np

C = np.array([5, 9, 5]) # The Mathematica tab adds an 'm' to the variable name
D = np.array([[5, 9], [5, 9]])
E = 9
I = 5
K = 9
N = 5
O = 9
1
2
3
4
5
6
7
C = c(5, 9, 5) # The Mathematica tab adds an 'm' to the variable name
D = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
E = 9
I = 5
K = 9
N = 5
O = 9
1
2
3
4
5
6
7
8
9
from sympy import *

C = Matrix([5, 9, 5]) # The Mathematica tab adds an 'm' to the variable name
D = Matrix([[5, 9], [5, 9]])
E = 9
I = 5
K = 9
N = 5
O = 9
1
x1 = [5 9; 5 9];
1
x1 = {{5, 9}, {5, 9}};
1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

All computational languages are displayed by default. These can be turned off using the element attributes show-matlab, show-mathematica, show-numpy, and show-r. In this example, we remove the the Matlab tab. The default active tab will be the first one in the list, in this case: Mathematica.

1
x1 = {{5, 9}, {5, 9}};
1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
x1 = matrix(c(5, 9, 5, 9), nrow = 2, ncol = 2, byrow = TRUE)
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

When a tab is not displayed, the default active tab can still be set. In this case, the Mathematica tab is hidden and NumPy is set as the default active tab.

1
d = 37.75189198;
1
2
3
import numpy as np

d = 37.75189198
1
d = 37.75189198
1
2
3
from sympy import *

d = 37.75189198

Any tab can be displayed alone. In this case, the Matlab, Mathematica, and R tabs are hidden and the NumPy tab is displayed alone.

1
2
3
import numpy as np

x1 = np.array([[5, 9], [5, 9]])
1
2
3
from sympy import *

x1 = Matrix([[5, 9], [5, 9]])

Student view placeholder

In student views this area is used for assessment and score info.
Tools

Staff information

Question

Title:
Element pl-variable-output: Display matrix and scalar data

Variant

Started at:
2026-08-05 00:35:46 (CDT)
Duration:
0s
Show/Hide answer
{}
History
dec frac
rad deg