Reputation: 11
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). 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. I expect to get a gaussian distribution in a plot, but the code keeps stopping at 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')
Upvotes: 1
Views: 991
Reputation: 6863
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
Upvotes: 1