I’ve been working on this c++ program for a little while and I’ve finally got it to run. Unfortunately, it does not work and the values seem to be not changing. Does anyone see what’s wrong? Thanks
double vxw = vwind*1.467*sin(phiwind*pi/180.0); //ft/s wind speed in x direction
double vyw = vwind*1.467*cos(phiwind*pi/180.0); //ft/s wind speed in y direction
///Sfml code down here...
///Use vector math using horizontal angle and magnitude(distance) of ball vector find the coordinate points in the x and y direction
vector<double>distance_final(double x, double y, double z, double vx, double vy, double vz, double t)
{
///Final distances are calculated here in this function using all previous variable
vector<double> result = acceleration(t,vx,vy,vz,z); ///Result of the acceleration function, gets three values from the acceleration function and puts them into this vector
double a1x = result[0];
double a1y = result[1];
double a1z = result[2];
double k1x = dt*a1x;
double k1z = dt*a1z;
double k1y = dt*a1y;
@B3anss,
Please put your code in code tags so that we can see its structure, and also so that we can run it in CPP shell without having to download it.
At the moment, for each timestep ... you are calling the Runge-Kutta update (routine distance_final) SIX times! You should just call it once per timestep.
Moreover, you are not updating your generalised coordinates (x,y,z,vx,vy,vz) at all - you are just putting them in an unused array bruhVector[].
To be honest, it would be simpler just to pass x,y,z,vx,vy,vz as reference parameters; then they will be updated in the Runge-Kutta routine and returned to the calling procedure. You don't need to push_back and then return a 6-element vector.
For the long term, if you used a valarray to hold your dependent variables (positions and velocities), then your Runge-Kutta routine would be only one sixth of the size. Just saying.
Please edit your post and put your code between code tags.
Are you using a debugger, and can you trace through the code using one?
Any idea at all what is happening and where things start to go wrong?
edit:
Like lastchance, I see a great deal of confusion here.
I can't really deduce what the plan is (there are few comments and hardly more than a "it's broke, what's wrong" question here).
For you to see what's wrong, I re-iterate the question: Do you have a debugger, and have you traced through to see what is happening?
This may be your best option at the moment. You'll see things you don't expect happen (which we can't see from here since we can't read your mind).
In order to be of real help (despite the fact you may get lots of helpful observations, none will likely fix the problem(s) ), we need to better recognize what the plan really is here.
Why, for example, do you have x_path_RK4 (and another for y and then z), as opposed to one container of a 3d vector object?
Oh, and while we look at it, you do realise that pow(e, (-t/tau))
is more obviously coded as exp(-t/tau)
There are quite a few gems in that code when we delve into it! double az = adragz+aMagz-32.174;
I have this horrible feeling that you are working in imperial units!
Might be best if you started by setting the drag coefficient and Magnus-effect coefficient to zero, so that you can compare the results for basic projectile motion without the effects of friction or spin.