'Cannot call or index into a temporary array' error message when setting up a set of coupled odes for ode45.
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to solve a set of coupled first order odes with respect to time,t. In some of the equations, I need to evaluate some of the functions I am solving for at a shifted time.
An simple example of what I am trying to do is as follows:
Let y be a function of t, y = y(t). The the ode has a term like this:
dy/dt = (arbitrary function of time)*y(t-epsilon), where epsilon is an arbitrary constant.
Here is part of my code:
function ydot = ODE(t,y,k,epsilon,angle)
ydot=zeros(12,1);
ydot(5) = -(1/k(3))*y(5)+ k(9)*y(6)-k(10)*y(5)+Theta_xy(t,epsilon,angle)*y(1)(t-5*sqrt(2*epsilon));
%Pexy
ydot(6) = -(1/k(3))*y(6)+ k(9)*y(8)-k(9)*y(6)+k(10)*y(5)-k(9)*y(6)+Theta_xy(t,epsilon,angle)*y(2)(t-5*sqrt(2*epsilon));
%Pixy
ydot(7) = -(1/k(6))*y(7)+k(11)*y(8) -k(12)*y(7)+Theta_xy(t,epsilon,angle)*y(3)(t-5*sqrt(2*epsilon));
%Lexy
ydot(8) = -(1/k(6))*y(8)+k(8)*y(6)-k(7)*y(8)+k(12)*y(7)-k(11)*y(8)+Theta_xy(t,epsilon,angle)*y(4)(t-5*sqrt(2*epsilon));
Where k is an array of constants and the components of y are functions we want to solve for in ode45.
The troublesome terms are the final terms in each equation. How do I deal with this?
0 件のコメント
採用された回答
Steven Lord
2018 年 8 月 14 日
Let y be a function of t, y = y(t). The the ode has a term like this:
dy/dt = (arbitrary function of time)*y(t-epsilon), where epsilon is an arbitrary constant.
Then you don't have a system of Ordinary Differential Equations or ODEs.
0 件のコメント
その他の回答 (1 件)
Nicholas Galang
2018 年 8 月 14 日
編集済み: Nicholas Galang
2018 年 8 月 14 日
The problem is that when you call y(1) that creates a temporary array which you cannot index into. In order to get the value in a multidimensional array you must use the syntax y(i,j) instead of y(i)(j). If you are trying to multiply the two numbers together, you must explicitly use the * symbol because the following line of code
y(1)(t-5*sqrt(2*epsilon))
is creating a temporary array at y(1) then trying to access the value at t-5*sqrt(2*epsilon). In order to multiply the two numbers use the following syntax.
y(1)*(t-5*sqrt(2*epsilon))
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!