Skip to content
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

Wrong time step width in plots generated by Problem.plot_trajectories() #282

Closed
chris-konrad opened this issue Dec 20, 2024 · 5 comments
Closed

Comments

@chris-konrad
Copy link
Contributor

chris-konrad commented Dec 20, 2024

The time array for trajectory plotting created by Problem.plot_trajectories() covers the interval [0, num_collocation_nodes * node_time_interval] including the limits while forcing the array size to be num_collocation_nodes. As a result, the time spacing is not as expected. This is the default behaviour of np.linspace(). Should be fixed by using np.arange() instead.

Example for num_collocation_nodes = 5, node_time_interval=1:

In[2]: np.linspace(0, num_collocation_nodes * node_time_interval, num=num_collocation_nodes)
Out[2]: array([0.  , 1.25, 2.5 , 3.75, 5.  ])

In[3]: np.arange(0, num_collocation_nodes * node_time_interval, node_time_interval)
Out[3]: array([0, 1, 2, 3, 4])

In the linspace version, the time steps of the resulting array are not 1, which however would be expected because of node_time_interval=1.

@Peter230655
Copy link
Contributor

As I know it, the final time is defined as tf = node_time_interval * (num_collection_nodes - 1),
you defined it as tf = node_time_interval * num_collection_nodes

@chris-konrad
Copy link
Contributor Author

chris-konrad commented Dec 20, 2024

That would fix the problem as well. But it is currently not implemented that way (see: /opty/direct_collocation.py#L400).

@Peter230655
Copy link
Contributor

Peter230655 commented Dec 20, 2024

Maybe you are right, but all the examples I ever saw, the final time was defined a interval * (num-nodes - 1), assuming the starting time is zero.

@chris-konrad
Copy link
Contributor Author

Have a look at np.arange(start, stop, step). It defines the interval as [start,stop). In np.arange(0, num_collocation_nodes * node_time_interval), the end of the interval is stop = num_collocation_nodes * node_time_interval = 5. But this will not be included in the time array. It stops at 4:

In[3]: np.arange(0, num_collocation_nodes * node_time_interval, node_time_interval)
Out[3]: array([0, 1, 2, 3, 4])

@chris-konrad
Copy link
Contributor Author

Solved with #283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants