1 Vicage

Subscripted Assignment Dimension Mismatch Simulink In Matlab

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); endfunction 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

t2 is a cable all of whose variables are cell arrays. That's almost certainly not what you want.

Assigning one row at a time is sometimes not the best way to create a table, but if you really need to do that, you probably want to preallocate both the size and the data types of the table's variables, and then assign each row.

>> t = table(cell(4,1),NaN(4,1),NaN(4,1),NaN(4,1),'VariableNames',{'f1','f2','f3','f4'}) t = 4×4 table f1 f2 f3 f4 __ ___ ___ ___ [] NaN NaN NaN [] NaN NaN NaN [] NaN NaN NaN [] NaN NaN NaN >> t(1,:) = {'001' 2 3 4} t = 4×4 table f1 f2 f3 f4 _____ ___ ___ ___ '001' 2 3 4 [] NaN NaN NaN [] NaN NaN NaN [] NaN NaN NaN >> t(2,:) = {'002' 5 6 7} t = 4×4 table f1 f2 f3 f4 _____ ___ ___ ___ '001' 2 3 4 '002' 5 6 7 [] NaN NaN NaN [] NaN NaN NaN

Note the right-hand side of those assignments. Normally, if the LHS is a parenthesis subscript expression, the RHS needs to be the same type, a table in this case. But table providea a conveneince where a RHS that's a cell array is treated as if cell2table were called on it. Because you have mixed types in each row, that's helpful.

Leave a Comment


Your email address will not be published. Required fields are marked *