フィルターのクリア

ODE45 and 3D arrays

3 ビュー (過去 30 日間)
Salar
Salar 2016 年 7 月 27 日
コメント済み: James Tursa 2016 年 7 月 27 日
Hello,
I have a question about 3D-arrays and ODE45. I have a 3D array called "A". "A" contains a set of a matrices at different instants of time, so for example A(:,:,1) will give me a matrix at T_0 . I also have a equation that I need to solve using ODE45. btw all the matrices in A are 6X6. My equation is Phi_dot(:,:,k) = A(:,:,k)*Phi, I'm trying to integrate this, but I keep getting an error on "indices". I would really appreciate it if you could help me with this. Thank you. My code is below :
function [ Phi_dot ] = Phi( A, Phi, t )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Phi_dot = A*Phi;
end
Phi_0 = eye(6);
tspan = [0 pi];
opts = odeset('RelTol',1e-12,'AbsTol',1e-12);
for k = 1:i
[t1, Phi] = ode45(@(t,Phi) Phi(A(:,:,k),Phi(:,:,k),t),tspan,Phi_0,opts);
end

採用された回答

James Tursa
James Tursa 2016 年 7 月 27 日
編集済み: James Tursa 2016 年 7 月 27 日
1) Don't use (:,:,k) subscripting on Phi in your derivative function. ode45 only knows about Phi as a 36-element column vector.
2) Don't use Phi for multiple things! You are using it as the dummy variable in your anonymous function, and as the derivative function name, and as the input variable in your derivative function, and as the return variable from ode45. Use different names for these. Partly because some of these will cause errors, and partly for readability.
3) Make sure your derivative function reshapes the column vector input into a matrix, and then returns a column vector.
E.g.,
[t1, PhiResult] = ode45(@(t,Phi) PhiFun(A(:,:,k),Phi,t),tspan,Phi_0,opts);
:
function [ Phi_dot ] = PhiFun( A, Phi, t )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Phi_dot = A*reshape(Phi,6,6);
Phi_dot = Phi_dot(:);
end
Then of course you will probably want to add some code to save the desired results from each iteration (the way it is now the results of each iteration overwrite the previous iteration).
  2 件のコメント
Salar
Salar 2016 年 7 月 27 日
Thank you for your response. My only problem with this is that for my k value, this is taking forever! Would you able to suggest a faster approach maybe I could try? Thank you!
James Tursa
James Tursa 2016 年 7 月 27 日
Do you mean i is large?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by