While I am running this code I get this error, could anyone knows how to solve it ? (Unable to perform assignment because the size of the left side is 1-by-41 and the size of)

2 vues (au cours des 30 derniers jours)
clear all
clc
%Geometry definition
L=0.3; %Length of the The rectangular bar in meter
W=0.4; %Width of the The rectangular bar in meter
%Material properties
alpha=11.234E-05; %theraml diffusivity
% computional details
x_min=0;
y_min=0;
i_max=31;
j_max=41;
delta_t=0.2;
t_max=10; %maximum time to get the solution for in sec
n_max=length(0:delta_t:t_max);
delta_x=L/(i_max-1);
delta_y=W/(j_max-1);
d=alpha*delta_t/(delta_x)^2;
%Solution initializing
M1_store_x=zeros(j_max,i_max,n_max); %3d matrix to save time data for i
M2_store_y=zeros(j_max,i_max,n_max); %3d matrix to save time data for j
T=zeros(i_max,j_max);
%Boundary conditions
T(i_max,:)=10; %upper
T(1,:)=40; %lower
T(:,j_max)=0.0; %right
T(:,1)=0.0; % left
Tx=T;
Ty=T;
%Initial conditions
for i=2:30;
for j=2:40;
T(i,j)=0;
end
end
%processing
%loop for x sweep
for n=1:n_max
b_vec=zeros(i_max,1);
b_vec(1,1)=0;
b_vec(i_max,1)=0;
for j=2:j_max-1
for i=2:i_max-1
b_vec(i)=T(i,j)+d*(T(i-1,j)+T(i+1,j)+T(i,j-1)+T(i,j+1)-4*T(i,j));
end
ut =b_vec;
Tx(j,:)=ut;
%storing the values in 3D matrix
M1_store_x(:,:,n)=Tx;
end
%-------------------y sweep--------------
%declaring the vector
b_vec=zeros(ny,1);
b_vec(1,1)=40;
b_vec(ny,1)=10;
for i = 2:i_max-1
for j = 2:j_max-1
b_vec(j)=T(i,j)+d*(T(i-1,j)+T(i+1,j)+T(i,j-1)+T(i,j+1)-4*T(i,j));
end
ut1 = b_vec;
Ty(:,i)=ut1;
end
M2_store_y(:,:,k)=Ty;
end
%plotting
solution_x=0:0.05:L;
solution_y=0:dy:W;
T_final = zeros(j_max,length(0:5:i_max));
s=1;
for k=1:5:i_max
T_final(:,s)= M2_store_y(:k,10);
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
s=s+1;
end
figure(1);
[xx,yy]= meshgrid(solution_x,solution_y);
mesh(xx,yy,T_final)
title('10 s Solution of FTCS Method')
xlabel('W')
ylabel('L')
zlabel('Temperatur(ºC)')
  4 commentaires
Walter Roberson
Walter Roberson le 2 Déc 2022
You cannot get to the %processing section until the syntax error is fixed in the %plotting section.
Seifeldin Mohamed
Seifeldin Mohamed le 2 Déc 2022
I am checking each section by evaluate selection and I get the error in the %processing section !!. could you please check this section. Please

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 2 Déc 2022
b_vec=zeros(i_max,1);
That is a column vector
b_vec(1,1)=40;
b_vec(ny,1)=10;
for i = 2:i_max-1
for j = 2:j_max-1
b_vec(j)=T(i,j)+d*(T(i-1,j)+T(i+1,j)+T(i,j-1)+T(i,j+1)-4*T(i,j));
end
Stays a column vector
ut =b_vec;
ut is assigned the column vector
Tx(j,:)=ut;
The column vector is assigned to a row of Tx.
Assigning a column vector to a row is legal in MATLAB. The problem is that the column vector has the same number of elements as there are rows in Tx, rather than having the same number as there are columns in Tx.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by