11.07.2015 Views

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

webMathematica User Guide 85The source for this example is in webMathematica/Examples/SVG/NDSolvePlot.jsp. If youinstalled webMathematica as described above, you should be able to connect to this JSP viahttp://localhost:8080/webMathematica/Examples/SVG/NDSolvePlot.jsp. (You may have someother URL for accessing your server.)The source contains an HTML form that sets up a number of input fields to collect the equation,starting and ending points, as well as initial conditions. These are then fed to a function thatsolves the differential equation and returns a plot of the result formatted as SVG. The SVG isthen displayed with the function SVGDisplay, which is defined in the package MSP`SVG`. Thecode, which inserts the plot, is shown below.MSPBlock[ {$$eqn, $$t0, $$init1, $$init2, $$t1},svg = NDSolveToSVG[ $$eqn, {$$init1, $$init2}, {$$t0,$$t1}] ;SVGDisplay[ svg, {400, 300}]]The actual definition of the function that creates the SVG is shown below. This solves the differentialequation and generates a plot of the result. It then generates Symbolic XML, which representsthe SVG of the result, using the function XML`SVG`GraphicsToSymbolicSVG. Next, itfinds the points that represent the plot of the result and uses these to form an SVG animationof a red ball, which moves along these points. This animation is inserted into the SVG to form anew result, which is returned to be plotted.NDSolveToSVG[ eqn_, init_, lims_List]:=Module[ {sol, dep, t, int, t0, t1},{o,dep,t} = EquationToVariables[ eqn] ;{t0, t1} = lims ;sol=NDSolve[Append[init,eqn],dep,{t,t0,t1}];{int0, int1} = Part[dep /. First[ sol],1,1];If[ t0 < int0, t0 = int0];If[ t1 > int1, t1 = int1];p=ParametricPlot[ {dep[t],dep'[t]} /. sol,{t,t0,t1}, ImageSize ->400];xml = XML`SVG`GraphicsToSymbolicSVG[p];pts="M"First[Cases[ xml,XMLElement["polyline",{"fill" -> _,"points" ->x_},_]->x, Infinity]];newElem=XMLElement["circle",

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!