Unable to perform assignment because the size of the left side is 8-by-1 and the size of the right side is 8-by-1001.
2 次查看(过去 30 天)
显示 更早的评论
I am getting this error where I am sure the size of the left-side = the right side in this code, what else can be causing this problem?
Unable to perform assignment because the size of the left side is 8-by-1 and the size of the right side is 8-by-1001.
Error in RK4
U_RK(:,j) = U_T(:,j)-(dt./dx)*a(k)*(Res);
function [ U_RK ] = RK4( U_T,Res, dx, dt, N,k )
U_RK = U_T;
a = zeros(4,1);
a(1) = 0.25;
a(2) = 1.0/3.0;
a(3) = 0.5;
a(4) = 1.0;
for j = 2:N-2
U_RK(:,j) = U_T(:,j)-(dt./dx)*a(k)*(Res); % error here
end
end
But U_Rk(:,j) is initailly set to = U_T, and is initizalize this way:
L = 1; %domain length
x = 0:dx:L;
N = length(x);
U_T= zeros(8,N);
So how is the LHS does not equal the RHS??
0 个评论
采纳的回答
KSSV
2021-5-6
The error is clear, you are trying to save more number of elements in the initilaized matrix.
Example:
A = zeros(3,3) ; % initialize A to 3x3 zeros matrix, to save data later
A(:,1) = rand(1,3) ; % no error, because column should have three elements and we have three here
A(:,2) = rand(1,5) ; % error, because column should have three elements, but you are saving five elements, This is not allowed
So, similiarly in your case, U_RK is a array with 8 rows, where you should save 8*1 array; but the RHS is giving you an array of size 8*1001.
Check the dimensions of your code and then initialize the matrix properly.
3 个评论
KSSV
2021-5-6
What is dimension of U_T, Res?
We cannot help unless the complete data and code is shown.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!