Run an example 'Solutions: Pegasus'.
()
| 158 | |
| 159 | @print_docstring |
| 160 | def example_solution_pegasus(): |
| 161 | """Run an example 'Solutions: Pegasus'.""" |
| 162 | |
| 163 | def f(x): |
| 164 | return 2 * x ** 3 - math.cos(x + 1) - 3 |
| 165 | |
| 166 | a = -1.0 |
| 167 | b = 2.0 |
| 168 | toler = 0.01 |
| 169 | iter_max = 100 |
| 170 | |
| 171 | print("Inputs:") |
| 172 | print(f"a = {a}") |
| 173 | print(f"b = {b}") |
| 174 | print(f"toler = {toler}") |
| 175 | print(f"iter_max = {iter_max}") |
| 176 | |
| 177 | print("Execution:") |
| 178 | root, i, converged = solutions.pegasus(f, a, b, toler, iter_max) |
| 179 | |
| 180 | print("Output:") |
| 181 | print(f"root = {root:.5f}") |
| 182 | print(f"i = {i}") |
| 183 | print(f"converged = {converged}") |
| 184 | |
| 185 | |
| 186 | @print_docstring |