MzA1Y2E3ZDA4YzBjMmRkYTBkYWMzYmI3NWZlNjAyOTE1YmEyNDQ5YjFiYTQ5OTYwMjcxYTA0ZDQ4NDUxMzlmZg.msfhaec9.eyJ1cmwiOiIvcGwvY291cnNlX2luc3RhbmNlLzIvaW5zdGFuY2VfcXVlc3Rpb24vMTc0LyIsImF1dGhuX3VzZXJfaWQiOiIxIn0
Skip to main content Accessibility guide
PrairieLearn Go home
  • XC 101, SectionA
  • Assessments
  • Gradebook
  • C4
Load from disk
  • Dev User student
    View type
    ✓ Staff view staff ✓ Student view student ✓ Student view without access restrictions student
    Effective user
    Customize…
    Course Requests Settings Log out

Regenerate assessment instance

Warning: Regenerating the assessment instance will select a new set of questions from this assessment. Any progress on the current assessment instance will be lost.

Are you sure you want to regenerate the assessment instance?

Course staff: Regenerate your assessment instance to pick up changes to the assessment or to get a fresh set of questions.

C4.34. 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.

  • Matlab/Octave
  • Mathematica
  • NumPy
  • R
  • SymPy
1
2
3
4
5
a = 8.00;
d = 5.03;
x = [8.00, 12.00, 8.00];
x1 = [8.00 12.00; 8.00 12.00];
x2 = [8.00 12.00 8.00; 8.00 12.00 8.00; 8.00 12.00 8.00];
1
2
3
4
5
a = 8.00;
d = 5.03;
x = { 8, 12,  8};
x1 = {{ 8, 12}, { 8, 12}};
x2 = {{ 8, 12,  8}, { 8, 12,  8}, { 8, 12,  8}};
1
2
3
4
5
6
7
import numpy as np

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

a = 8.00
d = 5.03
x = Matrix([ 8, 12,  8])
x1 = Matrix([[ 8, 12], [ 8, 12]])
x2 = Matrix([[ 8, 12,  8], [ 8, 12,  8], [ 8, 12,  8]])

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.

  • Matlab/Octave
  • Mathematica
  • NumPy
  • R
  • SymPy
1
2
x = [8, 12, 8]; % This is an array
x1 = [8 12; 8 12]; % This is a 2D matrix
1
2
x = { 8, 12,  8}; (* This is an array *)
x1 = {{ 8, 12}, { 8, 12}}; (* This is a 2D matrix *)
1
2
3
4
import numpy as np

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

x = Matrix([ 8, 12,  8]) # This is an array
x1 = Matrix([[ 8, 12], [ 8, 12]]) # 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.

  • Matlab/Octave
  • Mathematica
  • NumPy
  • R
  • SymPy
1
2
3
4
5
a = 8;
b = 12;
d = 5.03103732;
c = 0.36;
xC = [0.36, 8.00, 0.36];
1
2
3
4
5
a = 8;
b = 12;
d = 5.03103732;
c = 0.36;
xC = {0.36, 8.00, 0.36};
1
2
3
4
5
6
7
import numpy as np

a = 8
b = 12
d = 5.03103732
c = 0.36
xC = np.array([0.36, 8.00, 0.36])
1
2
3
4
5
a = 8
b = 12
d = 5.03103732
c = 0.36
xC = c(0.36, 8.00, 0.36)
1
2
3
4
5
6
7
from sympy import *

a = 8
b = 12
d = 5.03103732
c = 0.36
xC = Matrix([0.36, 8.00, 0.36])

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.

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

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

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

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".

  • Matlab/Octave
  • Mathematica
  • NumPy
  • R
  • SymPy
1
x1 = [8 12; 8 12];
1
x1 = {{ 8, 12}, { 8, 12}};
1
2
3
import numpy as np

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

x1 = Matrix([[ 8, 12], [ 8, 12]])

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.

  • Mathematica
  • NumPy
  • R
  • SymPy
1
x1 = {{ 8, 12}, { 8, 12}};
1
2
3
import numpy as np

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

x1 = Matrix([[ 8, 12], [ 8, 12]])

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.

  • Matlab/Octave
  • NumPy
  • R
  • SymPy
1
d = 5.03103732;
1
2
3
import numpy as np

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

d = 5.03103732

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

  • NumPy
  • SymPy
1
2
3
import numpy as np

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

x1 = Matrix([[ 8, 12], [ 8, 12]])
Additional attempts available with new variants

Correct answer

Collection 4

Assessment overview
Total points: 0/360
Score:
0%

Question C4.34

Value: 2
All variants: Open (current)
Total points: — /10
Auto-graded question

This form is only for reporting errors in the question itself. Do not use this form if you just don't know how to answer the question.

Previous question Next question

 Personal Notes

No attached notes

Attached files will be saved here for your reference. These files act as personal notes and can be used for your own review purposes. They are not used for grading.

Max file size: 10 MB

Attached personal notes will be saved here for your reference. These notes can be used for your own review purposes. They are not used for grading.

Staff information

Student details

Dev User
dev@example.com

Question

QID:
element/variableOutput
Title:
Element pl-variable-output: Display matrix and scalar data

Variant

Started at:
2026-08-04 16:37:31 (CDT)
Duration:
0s
Show/Hide answer
{}

Assessment instance

Assessment:
gallery/elements
Started at:
2026-08-04 16:37:17 (CDT)
Duration:
0s
View log
This box is not visible to students.