-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correcting time step width of trajectory plots to equal node_time_int… #283
Correcting time step width of trajectory plots to equal node_time_int… #283
Conversation
I am afraid, this may mess up simulations, where the final time is defined as tf = interval * (num_nodes - 1), |
I don't think this can happen. The results of arrange and linspace with (num_collocation_nodes-1) are equivalent:
It will not really matter which correction we choose. But the current behaviour is definitely not correct :) |
...but if an existing simulation uses tf = interval * (num_nodes - 1), then your change will matter? |
I am not sure I understand you correctly. Where would a current simulation use |
Virtually all the simulations I know or wrote define the starting time t0, mostly t0 = 0 and the final time tf. As regards compatibility, I do not know for sure. |
I see. I don't think you have to worry about this breaking any existing simulations. Here is why: What you pass to opty when creating a problem is only
According to the definition of np.linspace(), the resulting array begins with It doesn't create a problem for the examples because the error only means that the trajectories in the plot are stretched by one sample over the entire plot. You can actually see that in the second plot here. There, the blue traces in the second axis is slightly stretched compared to the true data in orange. To fix the problem, we can either change the command above to the exact same definition as you use for your simulations:
Or we can replace it with np.arange():
Although the input to the function looks slightly different, the results of these two variants are exactly equivalent because the way the two functions interpret an interval are defined differently:
If you prefer, we can also correct the linspace command by -1 instead of using arange. |
I have no preference, it is up to Jason to decide about this. |
Actually, @Peter230655, turns out there is a good reason to prefer linspace over arange. The latter is less numerically stable when using non-integer steps. This caused two of the examples to fail after all. So, we should keep using linspace and add the correction by -1 instead.
|
But yes indeed. The "error" is purely cosmetic and won't really be visible for large sample numbers. |
… ensure correct step width
I had no idea about the instabilitiy of arange. I am not the biggest Python expert, so I always use linspace. |
LGTM! Thanks for your first contribution :) |
Fixing #282