// Numbas version: finer_feedback_settings {"name": "Kollisjoner", "extensions": ["eukleides", "quantities"], "custom_part_types": [{"source": {"pk": 239, "author": {"name": "Timur Zaripov", "pk": 3272}, "edit_page": "/part_type/239/edit"}, "name": "Quantity with units (relative tolerance)", "short_name": "quantity-with-units-relative-tolerance", "description": "
The student enters a quantity with units. Answer accepted as correct within range defined as percentage of expected answer.
", "help_url": "https://github.com/numbas/numbas-extension-quantities", "input_widget": "string", "input_options": {"correctAnswer": "plain_string(settings[\"correctAnswer\"])", "hint": {"static": false, "value": "switch(\n settings[\"hint\"]=\"remind units\",\n \"Include units in your answer.\",\n settings[\"hint\"]=\"show units\",\n \"Give your answer in \"+units_string(settings[\"correctAnswer\"])+\" to \"+string(settings[\"wiggle\"])+\"% accuracy\"\n ,\n \"\"\n)"}, "allowEmpty": {"static": true, "value": false}}, "can_be_gap": true, "can_be_step": true, "marking_script": "mark:\napply(valid_number);\napply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)\n\ninterpreted_answer:\nstudent_quantity\n\nallowed_notation_styles:\n[\"plain\",\"en\"]\n\nmatch_student_number:\nmatchnumber(studentAnswer,allowed_notation_styles)\n\nstudent_number:\nmatch_student_number[1]\n\nraw_student_units:\ntry(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\nstudent_units:\nif(compatible(raw_student_units,correct_units) or settings[\"incompatible_units_action\"]<>\"convert\",\n raw_student_units,\n correct_units\n)\n\nstudent_quantity:\napply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\ncorrect_quantity:\nsettings[\"correctAnswer\"]\n\ncompatible:\nif(compatible(raw_student_units,correct_quantity),\n true\n,\n let(message,\"Your answer does not have the correct dimensions.\",\n if(settings[\"incompatible_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n if(settings[\"incompatible_units_action\"]=\"convert\",\n incorrect(\"Your answer does not have the correct dimensions. It will be marked as if the correct dimensions were used, and then a penalty will be applied.\")\n ,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end()\n )\n );\n false\n )\n)\n\ncorrect_units:\nunits(correct_quantity)\n\nsame_units:\nassert(raw_student_units=correct_units,\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)\n\nhas_units:\nassert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)\n\ncan_compare:\ncompatible or settings[\"incompatible_units_action\"]=\"convert\"\n\nclose_enough:\nif(can_compare,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)\n\nwiggle:\nabs(eval(settings[\"wiggle\"]))*0.01*abs(settings[\"correctAnswer\"])\n\nvalid_number:\nif(isNaN(student_number),\n warn(translate(\"part.numberentry.answer invalid\"));\n fail(translate(\"part.numberentry.answer invalid\"))\n,\n true\n )", "marking_notes": [{"name": "mark", "description": "This is the main marking note. It should award credit and provide feedback based on the student's answer.", "definition": "apply(valid_number);\napply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)"}, {"name": "interpreted_answer", "description": "A value representing the student's answer to this part.", "definition": "student_quantity"}, {"name": "allowed_notation_styles", "description": "", "definition": "[\"plain\",\"en\"]"}, {"name": "match_student_number", "description": "", "definition": "matchnumber(studentAnswer,allowed_notation_styles)"}, {"name": "student_number", "description": "The scalar part of the student's quantity
", "definition": "match_student_number[1]"}, {"name": "raw_student_units", "description": "The units of the student's quantity, before converting.
", "definition": "try(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)"}, {"name": "student_units", "description": "The units of the student's quantity.
\nIf the student used units incompatible with the units in the expected answer, and the \"what to do if incompatible units used\" option is set to \"mark as if correct units used\", the student's units are ignored and the expected units are used instead.
", "definition": "if(compatible(raw_student_units,correct_units) or settings[\"incompatible_units_action\"]<>\"convert\",\n raw_student_units,\n correct_units\n)"}, {"name": "student_quantity", "description": "The student's answer, interpreted as a quantity.
\nMarking fails if the student does not enter a valid quantity.
", "definition": "apply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)"}, {"name": "correct_quantity", "description": "", "definition": "settings[\"correctAnswer\"]"}, {"name": "compatible", "description": "Are the units of the student's quantity compatible with the units of the expected quantity?
", "definition": "if(compatible(raw_student_units,correct_quantity),\n true\n,\n let(message,\"Your answer does not have the correct dimensions.\",\n if(settings[\"incompatible_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n if(settings[\"incompatible_units_action\"]=\"convert\",\n incorrect(\"Your answer does not have the correct dimensions. It will be marked as if the correct dimensions were used, and then a penalty will be applied.\")\n ,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end()\n )\n );\n false\n )\n)"}, {"name": "correct_units", "description": "", "definition": "units(correct_quantity)"}, {"name": "same_units", "description": "/Are the student's quantity and the expected quantity in exactly the same units?
", "definition": "assert(raw_student_units=correct_units,\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)"}, {"name": "has_units", "description": "", "definition": "assert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)"}, {"name": "can_compare", "description": "Can the student's answer be compared with the correct answer? True if compatible units used, or \"mark as if correct units used\" selected.
", "definition": "compatible or settings[\"incompatible_units_action\"]=\"convert\""}, {"name": "close_enough", "description": "Is the student's quantity within the allowed tolerance of the expected answer?
", "definition": "if(can_compare,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)"}, {"name": "wiggle", "description": "", "definition": "abs(eval(settings[\"wiggle\"]))*0.01*abs(settings[\"correctAnswer\"])"}, {"name": "valid_number", "description": "Is the scalar part of the student's answer a valid number?
", "definition": "if(isNaN(student_number),\n warn(translate(\"part.numberentry.answer invalid\"));\n fail(translate(\"part.numberentry.answer invalid\"))\n,\n true\n )\n"}], "settings": [{"name": "correctAnswer", "label": "Correct answer", "help_url": "", "hint": "The expected quantity.", "input_type": "code", "default_value": "", "evaluate": true}, {"name": "hint", "label": "Input hint", "help_url": "", "hint": "", "input_type": "dropdown", "default_value": "remind units", "choices": [{"value": "none", "label": "None"}, {"value": "remind units", "label": "Remind to include units"}, {"value": "show units", "label": "Show required units"}]}, {"name": "allow_unitless", "label": "Allow unitless answer?", "help_url": "", "hint": "If not ticked, the student is prevented from submitting an answer without specifying units.", "input_type": "checkbox", "default_value": true}, {"name": "incompatible_units_action", "label": "What to do if incompatible units used", "help_url": "", "hint": "If the student's answer is given in units incompatible with the correct answer's units:Spørsmål til repetisjon.
\nStudenten må kunne:
\nVi ser på to luftputebiler med masse $m_1=\\var{m1}$ og $m_2=\\var{m2}$.
", "advice": "Det virker ingen eksterne krefter, så bevegelsesmengde er bevart:
\n$m_1v_1+0=m_1u_1+m_2u_2$
\nKollisjonen er elastisk, så kinetisk energi er bevart:
\n$m_1v_1^2+0=m_1u_1^2+m_2u_2^2$
\nDette gir et ligningssett med 2 ukjente som vi kan løse for å finne $u_1$ og $u_2$:
\n{diagram1advice}
\nDet virker ingen eksterne krefter, så bevegelsesmengde er bevart:
\n$\\vec{p}_1+\\vec{p}_2=\\vec{q}$
\nDvs. at $\\vec{q}=(m_1v_1,m_2v_2)$ i dette tilfellet. Fra geometrien til de tre vektorene {diagram2advice} kan vi da se at theta er gitt ved
\n$\\tan{\\theta}=\\frac{m_2v_2}{m_1v_1}$
", "rulesets": {}, "extensions": ["eukleides", "quantities"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"m1": {"name": "m1", "group": "Ungrouped variables", "definition": "qty(random(1..8),\"kg\")", "description": "", "templateType": "anything", "can_override": false}, "m2": {"name": "m2", "group": "Ungrouped variables", "definition": "qty(random(1..8 except scalar(m1)),\"kg\")", "description": "", "templateType": "anything", "can_override": false}, "v0": {"name": "v0", "group": "Ungrouped variables", "definition": "qty(random(2..9),\"m/s\")", "description": "", "templateType": "anything", "can_override": false}, "u1": {"name": "u1", "group": "Ungrouped variables", "definition": "(m1-m2)/(m1+m2)*v0", "description": "Velocity of body 1 after collision. Currently restricting to values greater than 0.
", "templateType": "anything", "can_override": false}, "u2": {"name": "u2", "group": "Ungrouped variables", "definition": "2*m1/(m1+m2)*v0", "description": "", "templateType": "anything", "can_override": false}, "v1": {"name": "v1", "group": "Ungrouped variables", "definition": "qty(random(1..9),\"m/s\")", "description": "", "templateType": "anything", "can_override": false}, "v2": {"name": "v2", "group": "Ungrouped variables", "definition": "qty(random(1..9),\"m/s\")", "description": "", "templateType": "anything", "can_override": false}, "diagram2": {"name": "diagram2", "group": "Ungrouped variables", "definition": "eukleides(\"Pre-collision\",-4,-2.2, 4,2,\n [point(-3,0) .. point(3,0) dashed,\n point(0,-3) .. point(0,3) dashed,\n point(-2,0),\n point(-2,0) .. point(-1,0) arrow label(\"v_1={v1}\"),\n point(0,-2),\n point(0,-2) .. point(0,-1) arrow label(\"v_2={v2}\"),\n point(0,0) .. point(1,1) arrow,\n angle(point(1,0),point(0,0),point(1,1)) label (\"\u03b8\")]\n)", "description": "", "templateType": "anything", "can_override": false}, "U": {"name": "U", "group": "Ungrouped variables", "definition": "vector(scalar(m1*v1),scalar(m2*v2))*(1/scalar(m1+m2))", "description": "", "templateType": "anything", "can_override": false}, "th": {"name": "th", "group": "Ungrouped variables", "definition": "degrees(angle(U,vector(1,0)))", "description": "", "templateType": "anything", "can_override": false}, "diagram2advice": {"name": "diagram2advice", "group": "Ungrouped variables", "definition": "eukleides(\"Pre-collision\",-5,-1,10,6,\n [\n point(0,0) .. point(5,0) arrow label(\"p_1={m1*v1}\"),\n point(5,0) .. point(5,5) arrow label(\"p_2={m2*v2}\",-1.9),\n point(0,0) .. point(5,5) arrow label(\"q={qty(siground(sqrt(scalar((m1*v1)*(m1*v1)+(m2*v2)*(m2*v2))),3),'kg*m/s')}\"),\n angle(point(1,0),point(0,0),point(5,5)) label (\"\u03b8\"),\n angle(point(5,5),point(5,0),point(0,0)) right]\n)", "description": "", "templateType": "anything", "can_override": false}, "diagram1": {"name": "diagram1", "group": "Ungrouped variables", "definition": "eukleides(\"Pre-collision1\",-4,-2.2, 4,2,\n [point(-2,0),\n point(-2,0) .. point(-1,0) arrow label(\"v_1={v0}\"),\n point(0,0)\n ]\n)", "description": "", "templateType": "anything", "can_override": false}, "diagram1advice": {"name": "diagram1advice", "group": "Ungrouped variables", "definition": "eukleides(\"Post-collision1\",\n [point(-3.5,0),\n point(-3.5,0) .. point(-3.5+scalar(u1),0) arrow label(\"u_1={round(u1*100)/100}\"),\n point(0,0),\n point(0,0) .. point(scalar(u2),0) arrow label(\"u_2={round(u2*100)/100}\"),\n ]\n)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "scalar(u1)>=0", "maxRuns": 100}, "ungrouped_variables": ["m1", "m2", "v0", "v1", "v2", "u1", "u2", "U", "th", "diagram2", "diagram2advice", "diagram1", "diagram1advice"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": true, "customName": "Elastisk 1D", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "{diagram1}
\nLa oss si at den første bilen beveger seg med hastighet {v0} og kjører rett i den andre, som står i ro
\nHva blir hastighetene etter kollisjonen dersom kollisjonen er elastisk?
\n$v_1=$[[0]]
\n$v_2=$[[1]]
", "gaps": [{"type": "quantity-with-units-relative-tolerance", "useCustomName": true, "customName": "u1", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "settings": {"correctAnswer": "u1", "hint": "remind units", "allow_unitless": true, "incompatible_units_action": "incorrect", "different_units_action": "convert", "different_units_penalty": "100", "wiggle": "2"}}, {"type": "quantity-with-units-relative-tolerance", "useCustomName": true, "customName": "u2", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "settings": {"correctAnswer": "{u2}", "hint": "remind units", "allow_unitless": true, "incompatible_units_action": "incorrect", "different_units_action": "convert", "different_units_penalty": "100", "wiggle": "2"}}], "sortAnswers": false}, {"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": "La oss si at de kolliderer inelastisk som vist i figuren under.
\n{diagram2}
\nHva blir vinkelen?
\n$\\theta=$[[0]] Oppgi svaret i grader med minst 2% nøyaktighet.
\n", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "theta", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "th*0.98", "maxValue": "th*1.02", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "siground(th,3)", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "B\u00f8rge Irgens", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3579/"}]}]}], "contributors": [{"name": "B\u00f8rge Irgens", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3579/"}]}