How to use Runge Kutta method to solve state space equation
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to use the Runge Kutta method to solve
xdot = Ax + Bu
Matrices A and B are constants and the input vector u is a known function of time. I am looking to get values for x. I have seen lots of posts about runge kutta but am very confused as to how to get it to work in matlab.
2 Commenti
James Tursa
il 3 Dic 2021
What have you done so far? What specific problems are you having with your code?
Risposte (1)
Walter Roberson
il 8 Dic 2021
Modificato: Walter Roberson
il 8 Dic 2021
(4 by 4) * (4 by 1) --> 4 by 1
(4 by 12) * (12 by 1) --> 4 by 1
4 by 1 + 4 by 1 --> 4 x 1
So that calculation sounds plausible -- but only if your uc timeseries has only 1 column.
However... you are passing in uc as the initial conditions, as well as using uc independently inside the code. If uc has 12 rows and it also forms the initial conditions, then the first x2 value passed into the code would have 12 rows, and you would be ding (4 by 4) * (12 x something) which is going to fail.
When you are looking to get an output that has 4 rows, then your initial conditions should have 4 rows.
Also we recommend against using global. See http://www.mathworks.com/help/matlab/math/parameterizing-functions.html . Oh and remember that Bc*uc is independent of your x2 value, so there is no point re-calculating Bc*uc each iteration: might as well calculate it once outside the function and pass the combination in.
8 Commenti
Walter Roberson
il 15 Dic 2021
You indicate that your time series has 12 rows and 21 columns. Timeseries have one row per time instance so that would describe a time series with 12 time instances and 21 elements for each time. But your code requires that you find 12 values at any given time, which would imply that the columns are time and the rows are the values you need.
To be more correct, timeseries objects can have two different organizations:
- 2 dimensional data in which number of rows matches number of times, and columns are the data; OR
- 3 or more dimensional data in which the final dimension must match the number of times, and the previous dimensions are the data for that time
As you have 2 dimensional data that is 12 x 21 then the number of time instances for you data must be 12. But the structure of your problem implies that the number of time instances should be 21 and that you want 12 values at each time.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!