// Numbas version: exam_results_page_options {"name": "Practice Questions for Matlab / Python Beginners", "metadata": {"description": "

Curve fitting, function zeros, sequences, etc.

", "licence": "Creative Commons Attribution 4.0 International"}, "duration": 0, "percentPass": "0", "showQuestionGroupNames": true, "shuffleQuestionGroups": false, "showstudentname": true, "question_groups": [{"name": "Polynomials and Zeros", "pickingStrategy": "all-ordered", "pickQuestions": 1, "questionNames": ["", ""], "variable_overrides": [[], []], "questions": [{"name": "Crossing the x-Axis", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "tags": [], "metadata": {"description": "

Use Matlab (or Python) to fit a cubic polynomial to data, and determine where the x-axis is crossed.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

This question tests polynomial curve fitting and root solving.

", "advice": "

By fitting a cubic polynomial to the following data:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
t0123456789
Y$\\var{Y0}$$\\var{Y1}$$\\var{Y2}$$\\var{Y3}$$\\var{Y4}$$\\var{Y5}$$\\var{Y6}$$\\var{Y7}$$\\var{Y8}$$\\var{Y9}$
\n
    \n
  1. The value of Y when t=10 is:
  2. \n
  3. When Y=0, the value of x is:
  4. \n
\n

In Matlab, for example:

\n
t = 0:9;
Y = [{Y0},{Y1},{Y2},{Y3},{Y4},{Y5},{Y6},{Y7},{Y8},{Y9}];
coeffs = polyfit(t, Y, 3);   % fit a cubic polynomial to the data; in Python, use NumPy and np.polyfit(), etc.
y = @(t) polyval(coeffs, t); % define a function based on our curve fit
\n

Q1. y(10) = $\\var{Y10}$

\n
roots(coeffs); % find where the polynomial is zero... here there is only one real solution
\n

Q2. y($\\var{c}$) = 0

", "rulesets": {}, "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"c": {"name": "c", "group": "Ungrouped variables", "definition": "(random(1..49)*2-1)/10", "description": "

The one real root of the polymonial.

", "templateType": "anything", "can_override": false}, "Y0": {"name": "Y0", "group": "Ungrouped variables", "definition": "0.1 * (0^2 - 14*0 + 50) * (0 - c)", "description": "

Value of Y when t=0.

", "templateType": "anything", "can_override": false}, "Y1": {"name": "Y1", "group": "Ungrouped variables", "definition": "0.1 * (1^2 - 14*1 + 50) * (1 - c)", "description": "

Value of Y when t=1.

", "templateType": "anything", "can_override": false}, "Y2": {"name": "Y2", "group": "Ungrouped variables", "definition": "0.1 * (2^2 - 14*2 + 50) * (2 - c)", "description": "

Value of Y when t=2.

", "templateType": "anything", "can_override": false}, "Y3": {"name": "Y3", "group": "Ungrouped variables", "definition": "0.1 * (3^2 - 14*3 + 50) * (3 - c)", "description": "

Value of Y when t=3.

", "templateType": "anything", "can_override": false}, "Y4": {"name": "Y4", "group": "Ungrouped variables", "definition": "0.1 * (4^2 - 14*4 + 50) * (4 - c)", "description": "

Value of Y when t=4.

", "templateType": "anything", "can_override": false}, "Y5": {"name": "Y5", "group": "Ungrouped variables", "definition": "0.1 * (5^2 - 14*5 + 50) * (5 - c)", "description": "

Value of Y when t=5.

", "templateType": "anything", "can_override": false}, "Y6": {"name": "Y6", "group": "Ungrouped variables", "definition": "0.1 * (6^2 - 14*6 + 50) * (6 - c)", "description": "

Value of Y when t=6.

", "templateType": "anything", "can_override": false}, "Y7": {"name": "Y7", "group": "Ungrouped variables", "definition": "0.1 * (7^2 - 14*7 + 50) * (7 - c)", "description": "

Value of Y when t=7.

", "templateType": "anything", "can_override": false}, "Y8": {"name": "Y8", "group": "Ungrouped variables", "definition": "0.1 * (8^2 - 14*8 + 50) * (8 - c)", "description": "

Value of Y when t=8.

", "templateType": "anything", "can_override": false}, "Y9": {"name": "Y9", "group": "Ungrouped variables", "definition": "0.1 * (9^2 - 14*9 + 50) * (9 - c)", "description": "

Value of Y when t=9.

", "templateType": "anything", "can_override": false}, "Y10": {"name": "Y10", "group": "Ungrouped variables", "definition": "0.1 * (10^2 - 14*10 + 50) * (10 - c)", "description": "

Value of Y when t=10.

", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["c", "Y0", "Y1", "Y2", "Y3", "Y4", "Y5", "Y6", "Y7", "Y8", "Y9", "Y10"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

By fitting a cubic polynomial to the following data:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
t0123456789
Y$\\var{Y0}$$\\var{Y1}$$\\var{Y2}$$\\var{Y3}$$\\var{Y4}$$\\var{Y5}$$\\var{Y6}$$\\var{Y7}$$\\var{Y8}$$\\var{Y9}$
\n
    \n
  1. The value of Y when t=10 is: [[0]]
  2. \n
  3. When Y=0, the value of t is: [[1]]
  4. \n
", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "Y10", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "Y10", "maxValue": "Y10", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "c", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "c", "maxValue": "c", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always"}, {"name": "Crossing the x-Axis (quintic)", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "tags": [], "metadata": {"description": "

Use Matlab (or Python) to fit a quintic polynomial to data, and determine where the x-axis is crossed.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

This question tests polynomial curve fitting and root solving.

", "advice": "

By fitting a quintic ($t^5$) polynomial to the following data:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
t1234567
Y$\\var{Y1}$$\\var{Y2}$$\\var{Y3}$$\\var{Y4}$$\\var{Y5}$$\\var{Y6}$$\\var{Y7}$
\n
    \n
  1. The curve crosses the axis in the range $1 < t < 7$ when $t$ =
  2. \n
  3. The maximum value of the curve in this range is $Y$ =
  4. \n
\n

In Matlab, for example:

\n
\n
T = 1:7;
Y = [-15.19,-30.24,-24.75,-2.56,20.25,27.36,14.21];
p = polyfit(T, Y, 5); % Fit an order 5 (quintic) polynomial to the data
\n
\n

Q1. Crosses the axis ...

\n
\n
r = roots(p);               % find where the polynomial is zero...
for i = 1:length(r) % loop through the roots
if r(i) > 1 && r(i) < 7 % check if each is valid
disp(['Crosses at t = ',num2str(r(i),2)]) % print with 2 s.f. if valid
end
end
\n
\n

Q2. Maximum value ...

\n
\n
y = @(t) polyval(p, t);  % define a function with the polynomial coefficients
u = @(t) -y(t); % same function, but upside down
tmax = fminsearch(u, 4); % find t at the minimum of the upsidedown function
fmax = y(tmax); % corresponding value of the correct function
disp(['Max Y = ',num2str(fmax,3)]) % print with 3 s.f.
\n
\n
", "rulesets": {}, "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"c": {"name": "c", "group": "Ungrouped variables", "definition": "siground((random(13..28)*2-1)/10,2)", "description": "

The one real root of the polymonial.

", "templateType": "anything", "can_override": false}, "Y1": {"name": "Y1", "group": "Ungrouped variables", "definition": "0.1*(1)^2*(1-8)^2*(1-c)", "description": "

Value of Y when t=1.

", "templateType": "anything", "can_override": false}, "Y2": {"name": "Y2", "group": "Ungrouped variables", "definition": "0.1*(2)^2*(2-8)^2*(2-c)", "description": "

Value of Y when t=2.

", "templateType": "anything", "can_override": false}, "Y3": {"name": "Y3", "group": "Ungrouped variables", "definition": "0.1*(3)^2*(3-8)^2*(3-c)", "description": "

Value of Y when t=3.

", "templateType": "anything", "can_override": false}, "Y4": {"name": "Y4", "group": "Ungrouped variables", "definition": "0.1*(4)^2*(4-8)^2*(4-c)", "description": "

Value of Y when t=4.

", "templateType": "anything", "can_override": false}, "Y5": {"name": "Y5", "group": "Ungrouped variables", "definition": "0.1*(5)^2*(5-8)^2*(5-c)", "description": "

Value of Y when t=5.

", "templateType": "anything", "can_override": false}, "Y6": {"name": "Y6", "group": "Ungrouped variables", "definition": "0.1*(6)^2*(6-8)^2*(6-c)", "description": "

Value of Y when t=6.

", "templateType": "anything", "can_override": false}, "Y7": {"name": "Y7", "group": "Ungrouped variables", "definition": "0.1*(7)^2*(7-8)^2*(7-c)", "description": "

Value of Y when t=7.

", "templateType": "anything", "can_override": false}, "xmax": {"name": "xmax", "group": "Ungrouped variables", "definition": "0.1 * ((24 + 4 * c) + sqrt((24 + 4 * c)^2 - 320*c))", "description": "

x-value of maximum in range 0<x<8

", "templateType": "anything", "can_override": false}, "fmax": {"name": "fmax", "group": "Ungrouped variables", "definition": "0.1*(xmax)^2*(xmax-8)^2*(xmax-c)", "description": "

f-value of maximum in range 0<x<8

", "templateType": "anything", "can_override": false}, "fmax_min": {"name": "fmax_min", "group": "Ungrouped variables", "definition": "siground(0.99*fmax, 3)", "description": "", "templateType": "anything", "can_override": false}, "fmax_max": {"name": "fmax_max", "group": "Ungrouped variables", "definition": "siground(1.01*fmax, 3)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["c", "Y1", "Y2", "Y3", "Y4", "Y5", "Y6", "Y7", "xmax", "fmax", "fmax_min", "fmax_max"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

By fitting a quintic ($t^5$) polynomial to the following data:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
t1234567
Y$\\var{Y1}$$\\var{Y2}$$\\var{Y3}$$\\var{Y4}$$\\var{Y5}$$\\var{Y6}$$\\var{Y7}$
\n
    \n
  1. The curve crosses the axis in the range $1 < t < 7$ when $t$ = [[0]].
  2. \n
  3. The maximum value of the curve in this range is $Y$ = [[1]].
  4. \n
", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "c", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "c", "maxValue": "c", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "precisionType": "sigfig", "precision": "2", "precisionPartialCredit": "50", "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "fmax", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "fmax_min", "maxValue": "fmax_max", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "siground(fmax, 3)", "precisionType": "sigfig", "precision": "3", "precisionPartialCredit": "50", "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always"}]}, {"name": "Non-Polynomials and Zeros", "pickingStrategy": "all-ordered", "pickQuestions": 1, "questionNames": [""], "variable_overrides": [[]], "questions": [{"name": "Zero of a function", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "tags": [], "metadata": {"description": "

Finding the zero of a non-polynomial function

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

Find where a general function crosses the x-axis.

", "advice": "

In Matlab, the solution should look something like:

\n
f = @(x) {b}*log(x) - {siground(clna,3)}*x^2 + {c}*x^2*log(x) - {siground(blna,3)};
fplot(f,[0,10]); % let's have a look at the function
fzero(f,10)
", "rulesets": {}, "variables": {"a": {"name": "a", "group": "Ungrouped variables", "definition": "random(3..19)/2", "description": "", "templateType": "anything"}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random(2..9)", "description": "", "templateType": "anything"}, "c": {"name": "c", "group": "Ungrouped variables", "definition": "random(2..9)", "description": "", "templateType": "anything"}, "blna": {"name": "blna", "group": "Ungrouped variables", "definition": "b*ln(a)", "description": "", "templateType": "anything"}, "clna": {"name": "clna", "group": "Ungrouped variables", "definition": "c*ln(a)", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["a", "b", "c", "blna", "clna"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Find where the following function crosses the x-axis:

\n

$f(x)=\\var{b}\\ln(x)-\\var{siground(clna,3)}x^2+\\var{c}x^2\\ln(x)-\\var{siground(blna,3)}$

\n

The zero is at $x=$ [[0]].

", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "a", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "a", "maxValue": "a", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "precisionType": "sigfig", "precision": "2", "precisionPartialCredit": "50", "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always"}]}, {"name": "Loops", "pickingStrategy": "all-ordered", "pickQuestions": 1, "questionNames": [""], "variable_overrides": [[]], "questions": [{"name": "Series Stuff", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "tags": [], "metadata": {"description": "

Write a loop in,e.g., Matlab or Python to determine terms in a sequence.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

Determine the terms in a sequence, e.g., by writing a loop in Python or Matlab.

", "advice": "

In Python, for example, the answer might look something like this:

\n
x_0 = {x0}
x_1 = {x1}
x_2 = {x2}
N = {N}
for n in range(3, N+1):
    x_n = ({a})*x_0 + ({b})*x_1 + ({c})*x_2
    x_0 = x_1
    x_1 = x_2
    x_2 = x_n
print(x_n)
", "rulesets": {}, "variables": {"x0": {"name": "x0", "group": "Ungrouped variables", "definition": "random([-3,-2,-1,1,2,3])", "description": "", "templateType": "anything"}, "x1": {"name": "x1", "group": "Ungrouped variables", "definition": "random([-3,-2,-1,1,2,3])", "description": "", "templateType": "anything"}, "x2": {"name": "x2", "group": "Ungrouped variables", "definition": "random([-3,-2,-1,1,2,3])", "description": "", "templateType": "anything"}, "N": {"name": "N", "group": "Ungrouped variables", "definition": "random(16..20)", "description": "", "templateType": "anything"}, "xN": {"name": "xN", "group": "Ungrouped variables", "definition": "sequencer(x0,x1,x2,a,b,c,N)", "description": "", "templateType": "anything"}, "a": {"name": "a", "group": "Ungrouped variables", "definition": "random([-1,1])", "description": "", "templateType": "anything"}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random([1,2])", "description": "", "templateType": "anything"}, "c": {"name": "c", "group": "Ungrouped variables", "definition": "random([-2,-1])", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["x0", "x1", "x2", "N", "a", "b", "c", "xN"], "variable_groups": [], "functions": {"sequencer": {"parameters": [["x0", "number"], ["x1", "number"], ["x2", "number"], ["a", "number"], ["b", "number"], ["c", "number"], ["N", "number"]], "type": "number", "language": "javascript", "definition": "for (var n = 3; n <= N; n++) {\n x3 = a * x0 + b * x1 + c * x2;\n x0 = x1;\n x1 = x2;\n x2 = x3;\n}\nreturn x3;"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

The sequence is defined as:

\n

$x_{n} = \\var{a}x_{n-3} + \\var{b}x_{n-2} \\var{c}x_{n-1}$

\n

and starts $x_0=\\var{x0}$, $x_1=\\var{x1}$, $x_2=\\var{x2}$.

\n

Determine $x_{\\var{N}}$: [[0]]

", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "xN", "marks": "3", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "xN", "maxValue": "xN", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always"}]}, {"name": "What is the Matrix?", "pickingStrategy": "all-ordered", "pickQuestions": 1, "questionNames": [""], "variable_overrides": [[]], "questions": [{"name": "Principal Stresses", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "tags": [], "metadata": {"description": "

Find principal stresses by finding the eigenvalues of the matrix

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

Solve to find the principal stresses by finding the eigenvalues of the matrix.

", "advice": "

In Python, the solution should look something like this:

\n
import numpy as np\n
S = np.asarray([[{siground(sigma_3[0][0],5)},{siground(sigma_3[0][1],5)},{siground(sigma_3[0][2],5)}],[{siground(sigma_3[1][0],5)},{siground(sigma_3[1][1],5)},{siground(sigma_3[1][2],5)}],[{siground(sigma_3[2][0],5)},{siground(sigma_3[2][1],5)},{siground(sigma_3[2][2],5)}]])

values, vectors = np.linalg.eig(S)

# sort values from low to high
principals = np.sort(values)

print('Maximum principal stress = %.3g MPa.' % principals[2])
print('Middle  principal stress = %.3g MPa.' % principals[1])
print('Minimum principal stress = %.3g MPa.' % principals[0])
", "rulesets": {}, "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"sigma_max": {"name": "sigma_max", "group": "Ungrouped variables", "definition": "random(4..10)", "description": "", "templateType": "anything", "can_override": false}, "sigma_min": {"name": "sigma_min", "group": "Ungrouped variables", "definition": "random(-10..-4)", "description": "", "templateType": "anything", "can_override": false}, "sigma_mid": {"name": "sigma_mid", "group": "Ungrouped variables", "definition": "random(-3..3)", "description": "", "templateType": "anything", "can_override": false}, "sigma": {"name": "sigma", "group": "Ungrouped variables", "definition": "matrix([sigma_max,0,0],[0,sigma_mid,0],[0,0,sigma_min])", "description": "", "templateType": "anything", "can_override": false}, "theta_xy": {"name": "theta_xy", "group": "Ungrouped variables", "definition": "random(1..17)*10*pi/180", "description": "", "templateType": "anything", "can_override": false}, "theta_yz": {"name": "theta_yz", "group": "Ungrouped variables", "definition": "random(1..17)*10*pi/180", "description": "", "templateType": "anything", "can_override": false}, "theta_zx": {"name": "theta_zx", "group": "Ungrouped variables", "definition": "random(1..17)*10*pi/180", "description": "", "templateType": "anything", "can_override": false}, "R_xy": {"name": "R_xy", "group": "Ungrouped variables", "definition": "matrix([cos(theta_xy),sin(theta_xy),0],[-sin(theta_xy),cos(theta_xy),0],[0,0,1])", "description": "", "templateType": "anything", "can_override": false}, "R_yz": {"name": "R_yz", "group": "Ungrouped variables", "definition": "matrix([1,0,0],[0,cos(theta_yz),sin(theta_yz)],[0,-sin(theta_yz),cos(theta_yz)])", "description": "", "templateType": "anything", "can_override": false}, "R_zx": {"name": "R_zx", "group": "Ungrouped variables", "definition": "matrix([cos(theta_zx),0,-sin(theta_zx)],[0,1,0],[sin(theta_zx),0,cos(theta_zx)])", "description": "", "templateType": "anything", "can_override": false}, "sigma_1": {"name": "sigma_1", "group": "Ungrouped variables", "definition": "transpose(R_xy)*sigma*R_xy", "description": "", "templateType": "anything", "can_override": false}, "sigma_2": {"name": "sigma_2", "group": "Ungrouped variables", "definition": "transpose(R_yz)*sigma_1*R_yz", "description": "", "templateType": "anything", "can_override": false}, "sigma_3": {"name": "sigma_3", "group": "Ungrouped variables", "definition": "transpose(R_zx)*sigma_2*R_zx", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["sigma_max", "sigma_min", "sigma_mid", "sigma", "theta_xy", "theta_yz", "theta_zx", "R_xy", "R_yz", "R_zx", "sigma_1", "sigma_2", "sigma_3"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Find the principal stresses for the following stress state:

\n

$\\sigma = \\var{siground(sigma_3,5)}$ [MPa]

\n
    \n
  1. Maximum principal stress: $\\sigma_\\text{max}=$ [[0]] [MPa]
  2. \n
  3. Middle principal stress: $\\sigma_\\text{middle}=$ [[1]] [MPa]
  4. \n
  5. Minimum principal stress: $\\sigma_\\text{min}=$ [[2]] [MPa]
  6. \n
", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "smax", "marks": "1", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "sigma_max-0.01", "maxValue": "sigma_max+0.01", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "smid", "marks": "1", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "sigma_mid-0.01", "maxValue": "sigma_mid+0.01", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "smin", "marks": "1", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "sigma_min-0.01", "maxValue": "sigma_min+0.01", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always"}]}], "allowPrinting": true, "navigation": {"allowregen": true, "reverse": true, "browse": true, "allowsteps": true, "showfrontpage": true, "showresultspage": "oncompletion", "navigatemode": "sequence", "onleave": {"action": "none", "message": ""}, "preventleave": true, "startpassword": "", "allowAttemptDownload": false, "downloadEncryptionKey": ""}, "timing": {"allowPause": true, "timeout": {"action": "none", "message": ""}, "timedwarning": {"action": "none", "message": ""}}, "feedback": {"showactualmark": true, "showtotalmark": true, "showanswerstate": true, "allowrevealanswer": true, "advicethreshold": 0, "intro": "

Practice questions for Matlab / Python Beginners

", "end_message": "", "reviewshowscore": true, "reviewshowfeedback": true, "reviewshowexpectedanswer": true, "reviewshowadvice": true, "feedbackmessages": []}, "diagnostic": {"knowledge_graph": {"topics": [], "learning_objectives": []}, "script": "diagnosys", "customScript": ""}, "contributors": [{"name": "Francis Franklin", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1887/"}], "extensions": [], "custom_part_types": [], "resources": []}