Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 1 of 1
Thread: Flot Graphs: Algorithms & Arrays

06242012, 03:59 PM #1
 Join Date
 Aug 2011
 Location
 221B Baker Street
 Posts
 2
 Thanks
 0
 Thanked 0 Times in 0 Posts
Flot Graphs: Algorithms & Arrays
So I'm a bit of an amateur in this sort of javascript, so I'm stuck.
Briefly, Flot is a jquery plugin for plotting graphs.
We have written an algorithm that we want for plotting a graph, but when tested, it does not give the desired effect.
This is the code:
Code:<script type="text/javascript"> $(function () { var x_data = []; // (x,t)data to plot var v_data = []; // (v,t)data to plot var t = new Array(); // array/vector of timevalues var x = new Array(); // array/vector of xvalues var v = new Array(); // array/vector of vvalues //pendulum properties and computational parameters var L = 1; // [m] size of the pendulum var omega = 1; // [Hz=1/s] reference frequency var a = L/10; // [m] initial position (amplitude) of the pendulum var dt = 0.001; // [s] timestep in computation var T = 10; // [s] maximum computation time //initial data t[0] = 0; x[0] = a; v[0] = 0; x_data.push([t[0], x[0]]); v_data.push([t[0], v[0]]); time = 0; i = 0; while (time < T) { // t_next = t_old + dt; t[i+1] = t[i] + dt; x[i+1] = x[i] + dt * v[i]; v[i+1] = v[i]  dt * omega^2 *x[i+1]; time = t[i+1]; x_data.push([time, x[i+1]]); // adding (t,x)values v_data.push([t[i+1], v[i+1]]); i = i + 1; } $.plot($("#placeholder"), [ { data: x_data, lines: { show: true, steps: true } } ]); }); </script>
Thanks.

This is now resolved.Last edited by sophieasia; 06252012 at 10:50 AM. Reason: RESOLVED