[英]Not enough input arguments for ode45 function
I am setting up a function that can solve the following differential equation for a laser system with the listed parameters.我正在设置一个函数,该函数可以为具有所列参数的激光系统求解以下微分方程。 Whenever I run my code though, I keep getting errors that there are not enough input arguments for the equation (dydt).但是,每当我运行我的代码时,我都会不断收到错误,提示方程 (dydt) 没有足够的输入参数。 I am unsure where the fault in the code is occurring, but I believe it may have something to do with how I defined y.我不确定代码中的错误发生在哪里,但我相信这可能与我定义 y 的方式有关。 I expect to get a gaussian distribution in a plot, but the code keeps stopping at dydt.我希望在图中获得高斯分布,但代码一直在 dydt 处停止。 It does not process the variables.它不处理变量。 Thank you!谢谢!
function dydt = 4_Lasers(t,y)
beta=1;
p0=10;
tau2=1e-7;
t = 1;
taupulse=tau2*100000;
taup=tau2/100;
p=p0*exp(-(t/taupulse)^2);
dydt = [(1/tau2)*(p-y(1)-y(1)*y(2)); (y(2)/taup)*
(y(1)-1)+beta*y(1)/tau2];
end
clear; close all;
[t,y] = ode45(@4_Lasers,[0 1e-6],[0; 0]);
plot(t,y(:,1),'r',t,y(:,2),'b')
title('p0=10,taupulse/tau2=1.5,tau2/taup=100');
xlabel('Time t');
ylabel('Amplitude');
legend('Photodensity','population inversion')
Cannot reproduce with this code:无法使用此代码重现:
clear; close all;
[t,y] = ode45(@Lasers,[0 1e-6],[0 0]);
plot(t,y(:,1),'r',t,y(:,2),'b')
title('p0=10,taupulse/tau2=1.5,tau2/taup=100');
xlabel('Time t');
ylabel('Amplitude');
legend('Photodensity','population inversion')
function dydt = Lasers(t,y)
beta=1;
p0=10;
tau2=1e-7;
t = 1;
taupulse=tau2*100000;
taup=tau2/100;
p=p0*exp(-(t/taupulse)^2);
dydt = [(1/tau2)*(p-y(1)-y(1)*y(2)); (y(2)/taup)*(y(1)-1)+beta*y(1)/tau2];
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.