Error message "Subscripted assignment dimension mismatch" when trying to solve set of ODEs

3 views (last 30 days)
I am trying to solve the set of 3 differential equations:
dTs(1) = 2*gd*Ts(3)-Ts(1)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j));
dTs(2) = -Ts(2)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j));
dTs(3) = gd*Ts(2)-Ts(3)/TT(j)-aa*Ts(3)*(Ts(1)+Ts(2))/(TT(j)*GG(j))-2*gd*GG(j);
whereas the factors TT(j) and GG(j) are in a loop. When I run the code I receive the error message: "Subscripted assignment dimension mismatch", and It looks like the ODE module fails to converge at t>~100s. In this case I sometimes cut the higher end of tspan (called tx in my code) to times that are smaller than 100 and then the code delivers a solution, but I need the response at larger times too. It might also help to know that the factor aa should be very small (<1e-6) in order for the code to deliver any solution. Here the entire code:
tx=[0 100]
for j=1:iGT % Solving the DE for individual relaxation modes
j
[tt,Ts] = ode23(@fTs,tx,[0 0 0]);
T110(:,j)=Ts(:,1);
T220(:,j)=Ts(:,2);
T120(:,j)=Ts(:,3);
end
function dTs=fTs(t,Ts)
dTs = zeros(3,1); % a column vector
dTs(1) = 2*gd*Ts(3)-Ts(1)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j));
dTs(2) = -Ts(2)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j));
dTs(3) = gd*Ts(2)-Ts(3)/TT(j)-aa*Ts(3)*(Ts(1)+Ts(2))/(TT(j)*GG(j))...
-2*gd*GG(j);
end
  1 Comment
Torsten
Torsten on 12 Aug 2016
Edited: Torsten on 12 Aug 2016
The size of the matrix Ts returned from ode23 can vary within your for-loop (depending on how many steps the solver has taken). Thus it is not possible to write the results in the matrices T110, T220 and T120 as you do it.
As a remedy, you can define a common tspan-vector for all runs:
tspan = linspace(0,100,20);
...
[tt,Ts] = ode23(@fTs,tspan,[0 0 0]);
By the way: The values TT(j) and GG(j) are known in function dTs ?
Best wishes
Torsten.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!