access a page in 3d matrix at time t in ode45
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Jan
2018년 3월 16일
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!