'Cannot call or index into a temporary array' error message when setting up a set of coupled odes for ode45.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vincenzo Pratley
am 14 Aug. 2018
Beantwortet: Steven Lord
am 14 Aug. 2018
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 Kommentare
Akzeptierte Antwort
Steven Lord
am 14 Aug. 2018
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 Kommentare
Weitere Antworten (1)
Nicholas Galang
am 14 Aug. 2018
Bearbeitet: Nicholas Galang
am 14 Aug. 2018
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 Kommentare
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!