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.
    조회 수: 6 (최근 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에서 Performance and Memory에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

