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 time-values
var x = new Array(); // array/vector of x-values
var v = new Array(); // array/vector of v-values
//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] time-step 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>

I don't know how to fix it and wondered if anyone could help me out?

Thanks.

-----

This is now resolved.