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.

조회 수: 1 (최근 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??

채택된 답변

KSSV
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
KSSV 2021년 5월 6일
What is dimension of U_T, Res?
We cannot help unless the complete data and code is shown.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by