// Kieran Brown | |
// Kieran's Components "Numerical ODE Solvers" | |
// https://kieranb662.github.io/blog/2020/04/22/Numerical-ODE-Methods | |
import Foundations | |
/// # Eulers Method | |
/// Uses simple finite difference with no trial steps | |
/// Each call to this function performs one step. This implies that the `simpleEuler` function is meant to be used as part of a larger solve. | |
/// - parameters: |
Most equations need to be solved numerically since no close-form expression representing their solutions can be obtained. For polynomial equations of order 1, 2, 3, 4 exact solutions can be obtained. I have created a series of solvers up to a cubic solver, that can be used to obtain most exact solutions. Of course with floating point errors, not everything is going to come out looking clean. To be able to handle complex numbers I made a simplified version of a complex number without all the mathematical operations.
If you call the cubicSolve
function with a = 0
then the solver falls back on the quadratic solver, the quadratic solver will fallback on the linear solver and linear solver will return an empty array(Thanks for catching that u\korbonix).
Example Usage
// | |
// ContentView.swift | |
// SwiftUIVarVsFunc | |
// | |
// Created by Kieran Brown on 11/1/19. | |
// Copyright © 2019 Kieran Brown. All rights reserved. | |
// | |
After adding the Extension target to a project
- Go to the menu bar -> Product -> Scheme -> Edit Scheme.
- Under the info tab change the executable dropdown menu to "Xcode.app".
- If you have a testing file add it to the "Arguments Passed On Launch" field under the Arguments tab.