access a page in 3d matrix at time t in ode45
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 16 Mär. 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
Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!