Need help creating dummy variables for plotting

3 vues (au cours des 30 derniers jours)
Kyle O'Connell
Kyle O'Connell le 29 Oct 2017
Before I get started into the details here is a link to my code -- https://pastebin.com/R7uCcCsF
Essentially what I'm doing is solving a force ODE using the Runge Kutta numerical integration method. In my code I have a vector, r, which is a position vector with initial values 0 such that r = [x,y,z]. Now I'm solving for r in this runge kutta algorithm and would like to plot all 3 components of the position at each point in time (i.e., plot the trajectory and not just the final point). For this I know I need to create a dummy variable(s). I was looking around but am finding it difficult to apply to my particular case.
I know it goes something like that the variable you'd like to plot and say it's force then your dummy variable would look something like dummyf = force(i); but for my r I have r(1) = x, r(2) = y and so on and so r(i) doesn't write out all 3 values of r at time step i, instead it selects the last value of the i-th (where i can only run from 1 to 3) component of r, which is not what I want at all.
I then tried writing dummy variables like x = r(1), y = r(2) and so on inside the for loop and then plotting them afterwards but to no avail. Then I wrote a second set of variables which I called dummyx, dummyy and dummyz which were defined like; dummyx = x(i); I figured since x was recording the value of r(1) at each time step then defining something as x(i) would plot the value of x at each i we iterate through. However this doesn't seem to be the case.. can anyone help me out here?

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by