"Unable to perform assignment because the size of the left side is 11-by-1 and the size of the right side is 11-by-11." Error

1 次查看(过去 30 天)
Hi,
I am trying to solve finite volume approximation shceme. the error comes from line 42--> ui(:,n)=inv(AB)*ci. I believe that ui should be column vector of 11 rows in order to solve u for time step. So, I am not sure how to fix that
clc
r=1; %length
t=10; %time
p=10; %number of r-grid
q=400; %number of time-grid
dxr=r/p; %length step
dtr=t/q; %time step
nr=fix(p);
xr=[0:p+1]*dxr;
ntr=fix(q);
tr=[0:q]*dtr;
D= 0.1; %diffusion
rr=D*dtr/dxr^2;
BC1=2;
u0=zeros(nr+1,1); %initial C
ui=u0;u
ci= zeros(nr+1,1);
% BC 1 for
%diffusivity constant used to beta
if rr > 0.5
fprintf('gain parameter > 0.5')
end
for n=2:ntr+1
% adjust first BC Dirichlet
AB(1,1)=-5/2*rr;
AB(1,2)=3/2*rr;
AB(2,1)=rr;
ci(1)=BC1;
for i=2:nr
%internal points
% build the A matrix for internal nodes
AB(i,i) = (1-(2*rr)+(rr/(i+1))-(rr/(i-1))); %for Ci
AB(i+1,i)= (rr-(rr/(i-1))); %for C(i-1)
AB(i,i+1) = (rr+(rr/(i+1))); %for C(i+1)
ci(i)=0;
end
% second BC Nuemann
AB(p+1,p)=(rr-(rr/39));
AB(p+1,p+1) =((2*rr/39)+(rr/39)-rr);
AB(p+1,p-1)=rr;
ci(p+1)=0;
ui(:,n)=inv(AB).*ci;
end
figure (1)
plot(xr, ui)

采纳的回答

Walter Roberson
Walter Roberson 2021-4-5
Your code has
ui(:,n)=inv(AB).*ci;
but your text description says
ui(:,n)=inv(AB)*ci
Notice the difference: .* compared to * . The .* version is the wrong one, and the * version is the right one.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by