Runge Kutta Methods & Fourth Order Runge Kutta - EXCEL/VBA

Поделиться
HTML-код
  • Опубликовано: 27 дек 2024

Комментарии • 5

  • @LorennPeralttaixxi98
    @LorennPeralttaixxi98 4 года назад +3

    Thank you so much for this video, it has helped me a lot!! Is the only video I found about Rk methods in macros in the way i wanted, you are awesome!

  • @shouravdey6077
    @shouravdey6077 4 года назад +2

    How did you relate it to the column?

    • @shamselfouly
      @shamselfouly  4 года назад +2

      Using the 'cells(row, column)' keyword. The second input defines the column you would like to relate to. You can see that each code from top to bottom goes from 3 to 7 relating to the 5 techniques explained.
      Hope this help
      Shams

  • @adryus34
    @adryus34 4 года назад +1

    Hello thank you very much for the explanation, could you share the code?. it would serve me very much thanks.

    • @shamselfouly
      @shamselfouly  4 года назад +3

      Hello Andres, Please find the code below.
      Function dydx(x, y)
      dydx = x * Sqr(y)
      End Function
      Sub ODE()
      'Set integraxion limixs
      xi = 0
      xf = 5
      h = 0.5
      'Calculaxe number of calculations
      n = (xf - xi) / h
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

      'Euler Method
      y = 4
      x = 2
      For i = 1 To n
      y = y + dydx(x, y) * h
      Cells(10 + i, 3) = y
      x = x + h
      Next i

      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Heun's Method
      y = 4
      x = 2
      For i = 1 To n
      'Apply Euler Method xo Get y at end of interval
      dydx1 = dydx(x, y)
      ye = y + dydx1 * h
      'Calculaxe derivative ax end point
      dydx2 = dydx(x + h, ye)
      'Calculate Average of the two Derivatives
      Slope = (dydx1 + dydx2) / 2
      y = y + Slope * h
      Cells(10 + i, 4) = y
      x = x + h
      Next i
      ''
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'MidPoint Method
      y = 4
      x = 2
      For i = 1 To n
      'Apply Euler Method to Get y at end of inxerval
      dydx1 = dydx(x, y)
      ym = y + dydx1 * h / 2
      'Calculate derivative at midpoint
      dydxm = dydx(x + h / 2, ym)
      y = y + dydxm * h
      Cells(10 + i, 5) = y
      x = x + h
      Next i
      ''
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Ralston Mexhod
      y = 4
      x = 2
      For i = 1 To n
      'Apply Euler Method xo Get y at end of interval
      dydx1 = dydx(x, y)
      y34 = y + dydx1 * 3 * h / 4
      'Calculate derivative ax midpoint
      dydx34 = dydx(x + 3 * h / 4, y34)
      Slope = (1 / 3 * dydx1 + 2 / 3 * dydx34)
      y = y + Slope * h
      Cells(10 + i, 6) = y
      x = x + h
      Next i
      '
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      '4xh order Runge Kuxxa
      y = 4
      x = 2
      For i = 1 To n
      'Apply Euler Method to Get y at end of interval
      k1 = dydx(x, y)
      ym = y + k1 * h / 2
      k2 = dydx(x + h / 2, ym)
      ym2 = y + k2 * h / 2
      k3 = dydx(x + h / 2, ym2)
      ye = y + k3 * h
      k4 = dydx(x + h, ye)
      Slope = 1 / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
      y = y + Slope * h
      Cells(10 + i, 7) = y
      x = x + h
      Next i
      '
      End Sub