Search code examples
matlabodedifferential-equations

Variable input in ode 45, MATLAB


I'm having a problem on sending a variable input to the ode45 function.

I have this code:

function T_pdot=f_massa_log(t,T,u)
    T_dot=(1-u)*T*log10(1/T);
end

And I call it as:

[t,T_dot]=ode45(@f_massa_log,[0 50],0.01,odeset,u);

When u is constant, this works fine, but now I need to send u as a function changing in time, and it's not working.

Can someone help? Thanks


Solution

  • I assume you are trying to solve for T in terms of t, given a known function u of t. You can simply do this in you derivative function:

    function T_pdot=f_massa_log(t,T,u)
        u=sin(t); %// for example
        T_dot=(1-u)*T*log10(1/T);
    end
    

    and call ode45 as you did before.