1
votes

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')
1
In Matlab function names or variable names cannot start with a number or underscore. Try renaming it to e.g. fourLasers - rinkert
I tried changing it, but I'm still getting the same error message that there aren't enough input arguments in the dydt line. - generic_screen_name1
I tested your code, and except of this 4_, all goes fine, and plot the results. However they are zeros. - Karls

1 Answers

1
votes

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