Clear Filters
Clear Filters

access a page in 3d matrix at time t in ode45

1 view (last 30 days)
i am solving for the g matrix in LQT control- before that i solved p for t[0:20] and i got a 3d matrix. to solve g i need a certain page in P matrix at every t sample in the ode45 solver. how can i achieve that
----------------------
this is the piece of code in the main code
[tp,p]=ode45(@(t,p)mRiccati2(tp, p, A, B,C, Q , R), tspan,pf);
P=reshape(P',size(A,1),size(A,2),size(T,1));
[tg,g]=ode45(@(tg,g)Gfunc2(tg, g, A, B, C, Q , R , Z),tp, gf);
-----------------
this is mReccati2:
function dXdt = mRiccati2(t, X, A, B ,C, Q, R)
X = reshape(X, size(A));
E= B*inv®*B.';
dXdt = -A.'*X - X*A + X*E*X - C.'.*Q.*C ;
dXdt = dXdt(:);
-----------------
this is function g "where the problem present":
function dXdt = Gfunc(t, X, A, B, C, Q, R , Z)
global p tp P
E= B*inv®*B.';
W=C.'.*Q;
dXdt= (interp1(tp,P(:,:,????),t).*E - A.')*X -C.'.*Q.*Z;
"i need to access certain page every time sample."
  2 Comments
Jan
Jan on 16 Mar 2018
How could we know, what you need instead the "????"? The explanation "access certain page every time sample" does not define clearly, what you need here. But there is a general problem:
Using interp1 in a function to be integrated is a bad idea, because the result is not smooth. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047. Matlab's integrators cannot handle non-smooth functions correctly. If you are lucky, you get an error message, but without luck you get a final value, which is dominated by rounding errors.
The explicit calculation of the inverse of a matrix is deprecated. See:
doc inv
mohamed elkattan
mohamed elkattan on 16 Mar 2018
well,i got your point here but i can't come with a better idea the problem here is that
for every output g in a time sample in t i need a page in P
that is: at page(i) in p i get a g(i) every t sample

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!