keep getting mtimes error and don't understand why

Hello everybody
my problem is this. I'm building a code for a simulator but i keep getting mtimes error even thought my matrices and vectors have completely the same values. Here's the code
n = 1000; % Number of vector elements
L = 1; % Depth [mum]
h = L/n; % Spacial step size
dt =1; % Time step size [s]
T_fin = 1000; % End time value
m = 1/dt;
T = 1023; % Temprature [K]
% err = 1e-4; % Accepted error (recommended 1e-6)
t = 1:dt:T_fin; % Time vector
x = linspace(0,L,n); % Spacial vector
% Definition constants (From problem definition)
C_I_0=10 ; % Initial concentration of C_I [mum^-3]
C_s_0 =10; % Initial concentration of C_s [mum^-3]
C_i_0 = 10^(-2); % Initial concentration of C_i [mum^-3]
C_c_0 = 10^(-5); % Initial concentration of C_c [mum^-3]
D_B = 7.87*10^(8)*exp(-3.75/((8.6e-5)*T)); % Diffusion of B [mum^2/s]
D_I = 149*10^(8)*exp(-4.68/(8.6e-5*T)); % Diffusion of Silicon self I [mum^2/s]
C_I_eq=10^(-3); %[mum^-3]
C_Istar=C_I_0*exp(-0.56/(8.6e-5*T));%[cm^-3[
C_sp=10^(-4); %[cm^-3[
C_ip=10^3;%[mum^-3[
C_cp=10^7;%[mum^-3[
K_f = -1e-29*t+9e-28;% Kf value [mum^3/s]
K_b=K_f*C_Istar; % [1/s]
K_1b=K_b;
K_1f=K_f;
%%Initial conditions
C_I =C_i_0* ones(T_fin,n); % Initial guess
C_s =C_sp* ones(T_fin,n); % Initial guess
C_i = C_ip* ones(T_fin,n); % Initial guess
C_c =C_cp* ones(T_fin,n); % Initial guess
C_i(1,:) = C_ip*exp(-(x-0.5).^2/(2*0.106)^2);
C_I(1,:) =C_I_0 ;
C_s(1,:) = C_sp*exp(-(x-0.5).^2/(2*0.106)^2);
C_c(1,:) = C_cp*exp(-(x-0.09).^2/(2*0.127)^2);
D_i=D_B*(C_I/C_I_eq);
figure ; plot(x,C_s(1,:));
%%Where the FUN is
for j = 1:T_fin-1
C_s(j+1,:) = C_s(j,:) + dt*(K_1f(j)*C_i(j,:)-K_1b(j)*C_s(j,:)*C_I(j,:));
if(j<=100)
for i = 2: n-1
C_i(j+1,i) = C_i(j,i) + (dt/h^2)*D_B*(C_i(j,i+1)-2*C_i(j,i)+C_i(j,i-1)) - C_s(j,i) - dt*(K_f(j)*C_i(j,i)-K_b*C_s(j,i)*C_I(j,i)); % Assuming D_i is constant in time
C_c(j+1,i) = C_c(j,i) + (dt/h^2)*D_I*(C_I(j,i+1)-2*C_I(j,i)+C_I(j,i-1));
end
end
if(j>100)
K_b=40; %[mum^-3]
C_c(j+1,:) = C_c(j,:) + dt*(-K_b*C_c(j,:));
for i=1:n-1
C_i(j+1,i) = C_i(j,i) + (dt/h^2)*D_i(j)*(C_i(j,i+1)-2*C_i(j,i)+C_i(j,i-1)) - C_s(j,i) - dt*(K_f(j)*C_i(j,i)-K_b*C_s(j,i)*C_I(j,i));
C_I(j+1,i) = C_I(j,i) + (dt/h^2)*D_I*(C_I(j,i+1)-2*C_I(j,i)+C_I(j,i-1)) + C_s(j,i) + dt*(K_f(j)*C_i(j,i)-K_b*C_s(j,i)*C_I(j,i)) - C_c(j,i) - dt*(K_f(j)*C_I(j,i)*C_c(j,i)-K_b*C_c(j,i));
end
end
end
%%Plotting
figure;
semilogy(x,C_s(2,:));
title('At time T=1'); xlabel('Depth [\mum]'); ylabel('Concentration of Boron [cm^-3]');
%figure;
%semilogy(x,C_i(1,:)+C_s(1,:));
%title('At time t=0'); xlabel('Depth [\mum]'); ylabel('Concentration of Boron [cm^-3]');
Be very glad if anyone could help

1 comentario

Jan
Jan el 27 de Feb. de 2016
Please format the code an mention the line, which causes the error. See the "{} Code" button.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 27 de Feb. de 2016

0 votos

Your arrays are quite definitely not all the same size. For example, ‘C_s’ is (1000x1000), ‘K_1f’ is (1x1000) and the others are similarly variegated. You can probably add and multiply the results of those operations if they end up all being the same dimensions, but you cannot as you have written your equations.
I don’t know what you’re doing, so I can’t suggest a solution, for example whether you need to do matrix or array operations. You will have to sort those problems yourself.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Feb. de 2016

Editada:

el 27 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by