1

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.