- #1
hagopbul
- 357
- 37
Hello all:
I am reading a comutacomputa physics book and trying a code from it in MATLAB it is not working and due to my lack of knowledge in this field I can't see where is the mistake hope you can take a look
<mentor: add code tags>
I am reading a comutacomputa physics book and trying a code from it in MATLAB it is not working and due to my lack of knowledge in this field I can't see where is the mistake hope you can take a look
Java:
import java.lang .*;
public class Motion {
static final int n = 100000, j = 500;
public static void main(String argv[]) {
double x[] = new double[n+1];
double v[] = new double[n+1];
double dt = 2*Math.PI/n;
x[0] = 0;
v[0] = 1;
for (int i=0; i<n; ++i) {
x[ i+1 ] = x[ i ] + v[ i ]*dt;
v[ i+1 ] = v[ i ] - x[ i ]*dt;
}
double t=0 ;
double jdt = j*dt;
for (int i=0; i<=n; i+=j) {
System.out.println(t +""+x [ i ]+""+ v[ i ]);
t += jdt;
}
}
}
<mentor: add code tags>
Last edited by a moderator: