Results 1 to 5 of 5

Math Help - MATLAB ODE45 in a for cycle

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    3

    MATLAB ODE45 in a for cycle

    Hi guys,


    As you can guess from the title, I want to have a for cycle that calls ode45 solver in each iteration, as ode45(odefun, tspan, yinitial).

    The differential equation that I define for odefun (in order to dy/dt, for instance) has some parameters that have to assume different values in each iteration. The problem is that I only find examples with odefun receiving t and y as input parameters...

    How can I add more input parameters to odefun, in order to import different values for each iteration of the for cycle?



    Thanks for all the help!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rber View Post
    Hi guys,


    As you can guess from the title, I want to have a for cycle that calls ode45 solver in each iteration, as ode45(odefun, tspan, yinitial).

    The differential equation that I define for odefun (in order to dy/dt, for instance) has some parameters that have to assume different values in each iteration. The problem is that I only find examples with odefun receiving t and y as input parameters...

    How can I add more input parameters to odefun, in order to import different values for each iteration of the for cycle?



    Thanks for all the help!
    From this page :

    Example:

    Code:
    function yprime = myode(t, y, c)
    yprime = c*y;
    Code:
    for k = -2:2
      [t,y] = ode45(@myode, [0 3], 1, [], k);
    figure
    plot(t, y)
    title(['Solution for k = ' num2str(k)])
    end
    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2010
    Posts
    3
    I tried that but it only worked for one parameter... If I try to pass more (I need to pass at least four) it doesn't work...

    I also tried to put all of them in an array, but it didn't work neither...
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rber View Post
    I tried that but it only worked for one parameter... If I try to pass more (I need to pass at least four) it doesn't work...

    I also tried to put all of them in an array, but it didn't work neither...
    Then try making them globals.

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Feb 2010
    Posts
    3
    Passing them to global variables isn't working neither...


    BTW, this is part of the code where I call ode45:

    Tc_i=65;

    for n=1:length(Ta)
    t_i(n)=(n-1)*15*60;
    t_f(n)=n*15*60;
    qs_s=qs(n);
    Ta_s=Ta(n);
    v_s=v(n);
    I_s=I(n);
    [t,Tc]=ode45(@myode, [t_i(n) t_f(n)], Tc_i);
    strcat(t_total,t);
    strcat(Tc_total,Tc);
    Tc_i=Tc(length(Tc));
    end



    This is the function myode that I defined:

    function xprime=myode(t,Tc,qs_s,Ta_s,v_s,I_s)

    ALFA=0.5;
    R20=1.093e-4;
    ALFA_R=4.03E-3;

    EPS=0.6;
    SIGMA=5.6704e-8;

    d=0.023;

    Sal=264.42e-6;
    Cal=2432700*pi()*d;
    Sac=61.7e-6;
    Cac=3578800*pi()*d;

    C=Sal*Cal+Sac*Cac;

    xprime=(qs_s+(R20*(1+ALFA_R*(Tc-20)))*I^2-EPS*SIGMA*pi()*d*((Tc+273.15)^4-(Ta_s+273.15)^4)-8.55*(v_s*d)^0.448*(Tc-Ta_s))/C;

    end
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab ode45
    Posted in the Math Software Forum
    Replies: 8
    Last Post: October 24th 2009, 11:22 AM
  2. Matlab ode45
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: October 24th 2009, 05:23 AM
  3. Solving IVP in Matlab (ode45)
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 15th 2008, 09:01 PM
  4. ode45 Matlab
    Posted in the Math Software Forum
    Replies: 6
    Last Post: November 29th 2008, 08:21 PM
  5. ode45 MATLAB
    Posted in the Math Software Forum
    Replies: 2
    Last Post: September 24th 2008, 04:02 AM

Search Tags


/mathhelpforum @mathhelpforum