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??

採用された回答

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.
Jamie Al
Jamie Al 2021 年 5 月 6 日
Oh sorry, I see the problem now!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by