having an error in a matlab code due to ' assignment A(I) = B, the number of elements in B and I must be the same.'
2 次查看(过去 30 天)
显示 更早的评论
Hi every body, i have a problem in a matlab code, i need your help:
the function , i call is here: so my probleme is that i have this error , and i don't really understand:
In an assignment A(I) = B, the number of elements in B and I must be the same.
function dy = dynamiquelaser(t,y)
global to_c g_d alpha_h G_n to_e n_sp phi_inj I_inj i
dy = zeros(3,1); % a column vector
dy(1) = (g_d/to_c)*y(3).*y(1) + 2*sqrt(y(1)*I_inj).*cos(phi_inj-y(2)) ;
dy(2) = ((alpha_h*g_d)/(2*to_c))*y(3) ;
dy(3) = (1/to_e)*(4.5-y(3)-((to_e*G_n.*y(1)).*((y(3))+(1/n_sp))));
i=i+1
end
t=0:1e-12:3e-9;
[T,Y] = ode45(@dynamiquelaser,t,[10 5 5]);
the script that call the function described previously
i have a problem in the line number one, this function, is used in program that resolve the system using the solver ODE 45, is there any syntax code error?
Thank you for your help
the different values of the numerical parameters if someone want to run the code
clc
clear all
close all
global to_c g_d alpha_h G_n to_e n_sp gamma_c N_th N_t to_p t i h c n lambda0 L e l omega0 w_inj
L = 200*1e-6;
l = 3*1e-6 ;
e = 0.15*1e-6;
V = 9*1e-17;
c = 3*1e8;
h = 1.054571726*1e-34;
q = 1.60217656535*1e-19;
lambda0=1500*1e-9;
omega0=2*pi*c/lambda0;
gamma_c= 0.05;
I_th = 10.5*1e-3;
to_e = 181*1e-12;
N_t = 1.77*1e21;
N_th = 1.53*1e22;
to_p = 10*1e-12;
G = 1.9*1e-18 ;
G_n = 1.5*1e-10;
alpha_h = 6.5;
n = 3.8;
to_c =(2*n*L)/c;
g_d = gamma_c*G_n*N_th*to_c;
n_sp = N_th/( N_th - N_t);
i=0;
t=0:1e-12:3e-9;
phi_inj=1e15;
I_inj=1e19;
0 个评论
采纳的回答
Walter Roberson
2016-11-4
You did not declare some variables as global in the defining routine.
Adjusted code is attached.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!