// Numbas version: exam_results_page_options {"name": "Lois's copy of Solution curves and Vector fields 2 : $dy/dx=x^2-y^2$", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Using Jsxgraph to draw the vector field for a differential equation of the form $\\frac{dy}{dx}=f(x,y)=x^2-y^2$, and also by moving the point $(x_0,y_0)$ you can see the solution curves going through that point.

\n

If you want to modify $f(x,y)$ simply change the definition of  $f(x,y)$ and that of the variable  str in the user defined function testfield in Extensions and scripts. You have to use javascript notation for functions and powers in the definition of $f(x,y)$.

"}, "variablesTest": {"condition": "", "maxRuns": 100}, "parts": [{"variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "variableReplacements": [], "showCorrectAnswer": true, "prompt": "

Vector field for the differential equation \$\\frac{dy}{dx}=f(x,y)=x^2-y^2\$

\n

You change the function $f(x,y)$ by modifying the function $f(x,y)$ in the testfield function defined in Extensions and scripts.

\n

You have to use Javascript notation for powers and standard functions when you define $f(x,y)$ in testfield.

\n

If you want to see the solution curve through a particular point then drag the point labeled $(x_0,y_0)$ to it.

", "scripts": {}, "marks": 0, "type": "information"}], "name": "Lois's copy of Solution curves and Vector fields 2 : $dy/dx=x^2-y^2$", "ungrouped_variables": ["a"], "advice": "

Move the point $(x_0,y_0)$ to see the solutions through that point.

", "preamble": {"js": "", "css": ""}, "statement": "

{testfield()}

\n

", "tags": ["Differential equations", "differential equations", "vector field"], "variables": {"a": {"name": "a", "definition": "1", "description": "

Just a filler - not used. Need a variable to publish.

", "templateType": "anything", "group": "Ungrouped variables"}}, "rulesets": {}, "variable_groups": [], "functions": {"testfield": {"language": "javascript", "definition": "\n var div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',{boundingBox:[-5,5,5,-5],grid:true,axis:true});\n function f(x,y){return x*x-y*y;}\n var str = \"x*x-y*y\";\n var board = div.board;\n for(var i=-10;i<10;i++){\n for(var j=-10;j<10;j++){\n //board.create('point',[i/2,j/2],{size:2,name:'',face:'+'});\n var len=4;\n // the length of a segment is 1/4\n var d=1/(len*(Math.pow(1+Math.pow(f(i/2,j/2),2),0.5)));\n board.create('segment',[[i/2,j/2],[i/2+d,d*f(i/2,j/2)+j/2]]);}\n }\n //var N = board.create('slider',[[-4,4],[4,4],[-5,2.5,5]], {name:'N'});\n var P = board.create('point',[0,0], {name:'(x_0,y_0)'});\n \n function doIt() {\n var txt = JXG.GeonextParser.geonext2JS(str);\n f = new Function(\"x\", \"yy\", \"var y = yy; var z = \" + txt + \"; return [z]\");\n board.update();\n }\n \n function ode() {\n return JXG.Math.Numerics.rungeKutta('heun', [P.Y()], [P.X(), 5], 200, f);\n }\n function ode1() {\n return JXG.Math.Numerics.rungeKutta('heun', [P.Y()], [P.X(), -5], 200, f);\n } \n var g = board.create('curve', [,], {strokeColor:'red', strokeWidth:2});\n g.updateDataArray = function() {\n var data = ode();\n var data1= ode1();\n var h = (5-P.X())/200;\n var h1 = (5+P.X())/200;\n this.dataX = [];\n this.dataY = [];\n for(var i=0; i