Results 1 to 3 of 3

Math Help - ode45 MATLAB

  1. #1
    Newbie
    Joined
    Aug 2008
    Posts
    11

    Red face ode45 MATLAB

    Hi everyone,

    Im trying to solve a system of 4 1st order differential equations using ode45, ode23s and using euler method,

    Starting off with ode45, I have a function called solvede and im trying to use that with my main script file to model the behaviour of xdot over 10 seconds - but I still havent been able to run the model correctly

    If you could spot why the code won't work Id appreciate any input
    > my code is:

    The function>>

    function xdot = solvede(x, t)



    a = 1.33;
    b = 0.5*cos(x(1) - x(3));
    c = 0.5*sin(x(1) - x(3))*x(3)^2 + 73.575*sin(x(1));
    d = 0.5*cos(x(1) - x(3));
    e = 0.333;
    f = 24.525*sin(x(3));


    xdot(1) = x(2);
    xdot(2) = ((b*f - c*e)/(a*e - b*d));
    xdot(3) = x(4);
    xdot(4) = ((f*a - c*d)/(b*d - e*a));


    return

    The main scipt file that calls the function:


    %Setting up time range
    tspan(1) = 0;
    tspan(2) = 10;

    %Setting up initial conditions
    x = [pi 0 pi 0];

    %Calling ODE solver
    [xdot,t] = ode45(@solvede,tspan,x);
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Try changing the first line of the derivative definition from:

    function xdot = solvede(x, t)

    to

    function xdot = solvede(t, x)

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Aug 2008
    Posts
    11

    ode45 MATLAB

    Thanks CaptainBlack, I tried that and it worked, Ive developed my programme far enough so that it delivers the two graphs desired for x(:,1) and x(:,3) against time using the ODE45 method;

    Does anyone have any ideas how to form a solution of the system of equations with the same output but using the Euler method instead the euler method had the step size 'h' as a variable so it's a bit more complicated

    Below is the code I used for solving it with ode45
    >>Coding that calls function pendulumODE to solve equations

    %This computer routine will solve the differential non linear system of
    %equations and plot the angles phi1 and phi2 against time.

    %Calling the ODE solver function pendulumODE
    [t,x] = ode45(@pendulumODE,[0 10],[pi; 0; -pi; 0]);

    %Plot the curves for X1 and X3 which represent phi1 and phi2 respectively
    plot(t,(pi/180)*x(:,1), t,(pi/180)*x(:,3));

    %Labelling the x and y axis and features of the graph
    title('Solutions for phi1 and phi2 for initial conditions x(0) = [pi 0 -pi 0]')
    xlabel(
    'Time, seconds');
    ylabel(
    'Angles in radians')
    legend(
    'phi1', 'phi2')
    grid
    on
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. MATLAB ODE45 in a for cycle
    Posted in the Math Software Forum
    Replies: 4
    Last Post: February 17th 2010, 08:07 AM
  2. Quick MATLAB ode45 question
    Posted in the Math Software Forum
    Replies: 3
    Last Post: November 16th 2009, 11:40 PM
  3. Matlab ode45
    Posted in the Math Software Forum
    Replies: 8
    Last Post: October 24th 2009, 12:22 PM
  4. Solving IVP in Matlab (ode45)
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 15th 2008, 10:01 PM
  5. ode45 Matlab
    Posted in the Math Software Forum
    Replies: 6
    Last Post: November 29th 2008, 09:21 PM

Search Tags


/mathhelpforum @mathhelpforum