Hi all,
Im getting to grips with some java but having trouble with this loop. I'll explain it just so we're on the same page
im trying to create a loop whereby the time and velocity change each time. I have all the classes and methods necessary and compile up to this loop.
By this i mean, i have the user to ask how many data points they wish to consider (excluding zero as a data point)
i do this by
double m = input.nextDouble(); double step = t/m;
In normal words time is divided by the number of data points hence this is ideal in the loop to us j+=step rather than say 1, 2, 3, 4... which restricts user ability and freedom.
Now, because of the physics (don't worry - simple stuff), the velocity is going to change at each time step. I.e. initial values the user enters e.g. at t = 0, v = (1,0,0)
Again don't worry about the vector, i have solved that part in terms of print, display and so forth.
But how should i do this loop? Here was an attempt which failed:
for(double j = 0; j < v; j+=step)/**needs two loops i.e. begins with t=0, u=v (in this case), then t = step, u = old vf, then t = 2step, u = (new)old vf ...*/ { fetch.calcVelocityf(v, g, t); v = fetch.getVelocityf(v, g, t); System.out.print(v.returnString() + "\t"); for (double i = 0; i < t; i+=step) { System.out.print(t); } } }
In reality terms i want it to give me the velocity and time at each step (data point, user entry see above) and have it sent to print.
I believe the time approach is fine, but unsure on the velocity, v as it is a vector hence j < v means nothing as one is double and the other Vector clas assigned.
Ps don't worry about g, that is the acceleration - also needed!
Note:
fetch is from:
Vector fetch = Vector(); [This is the class i use to make them as vectors, print as vectors via returnString etc]
velocityf is simly final velocity which in this case is changing up until we get the correct number of data points.
If you feel like i could be more informative let me know