// Numbas version: exam_results_page_options {"name": "Solution curves and Vector fields 1 : dy/dx=1-sin(y)", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variablesTest": {"maxRuns": 100, "condition": ""}, "parts": [{"prompt": "

Vector field for the differential equation \\[\\frac{dy}{dx}=f(x,y)=1-\\sin(y)\\]

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

", "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "type": "information", "marks": 0, "scripts": {}, "variableReplacements": [], "showFeedbackIcon": true}], "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)=1-\\sin(y)$, 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)$.

"}, "variable_groups": [], "tags": [], "functions": {"testfield": {"parameters": [], "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 1-Math.sin(y);}\n var str = \"1-Math.sin(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[0]; 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', [[0],[0]], {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; iIf you want to see the solution curve through a particular point then drag the point labeled $(x_0,y_0)$ to it.

\n

The general solution is given by \\[y=x-2\\arctan\\left(1-\\frac{2}{x+C}\\right)\\] for $C$ an arbitrary constant.

\n

The solution through $(0,0)$ is given by $C=2$.

", "variables": {"a": {"group": "Ungrouped variables", "definition": "1", "templateType": "anything", "name": "a", "description": "

Filler variable  - not used.

"}}, "statement": "

{testfield()}

\n

", "extensions": ["jsxgraph"], "name": "Solution curves and Vector fields 1 : dy/dx=1-sin(y)", "type": "question", "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}]}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}