Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Improved Euler (Heun) method

  1. Apr 2, 2009 #1
    i am a programmer really, and i am trying to make a program that allows the user to select 1 of a few methods to estimate a graph. I am struggling on the improved Euler (Heun) method.

    This is what i have, if you image in it iterating until 100 seconds has passed.

    dxdt_1 = a*(y - x);
    dydt_1 = x*(b - z) - y;
    dzdt_1 = (x*y) - (c*z);
    printf("dxdt = %.5f\ndydt = %.5f\ndzdt = %.5f", dxdt_1, dydt_1, dzdt_1);

    //standard Euler
    x_predict = x + dxdt_1*dt;
    y_predict = y + dydt_1*dt;
    z_predict = z + dzdt_1*dt;
    printf("x_predict = %.5f\ny_predict = %.5f\nz_predict = %.5f", x_predict, y_predict, z_predict);

    dxdt_2 = a*(y_predict - x_predict);
    dydt_2 = x*(b - z) - (y_predict);
    dzdt_2 = (x_predict*y_predict) - (c*(z_predict));
    printf("dxdt_2 = %.5f\ndydt_2 = %.5f\ndzdt_2 = %.5f", dxdt_2, dydt_2, dzdt_2);

    x_grad = (dxdt_1 + dxdt_2)/2;
    y_grad = (dydt_1 + dydt_2)/2;
    z_grad = (dzdt_1 + dzdt_2)/2;
    printf("x_grad = %.5f\ny_grad = %.5f\nz_grad = %.5f", x_grad, y_grad, z_grad);

    x = x + x_grad*dt;
    y = y + y_grad*dt;
    z = z + z_grad*dt;

    The example is the Lorenz equations.

    Thanks
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted