File: Solver.rst_t

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (62 lines) | stat: -rw-r--r-- 1,591 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{{ objname }}
{{ underline }}

.. plot::
    :include-source: False

    import openturns as ot
    from matplotlib import pyplot as plt
    from openturns.viewer import View

    xMin = 0.0
    xMax= 3.0
    f = ot.MemoizeFunction(ot.SymbolicFunction("x", "x^3-2*x^2-1"))
    solver = ot.{{ objname }}()
    root = solver.solve(f, 0.0, xMin, xMax)
    x = f.getInputHistory()
    y = f.getOutputHistory()
    g = f.draw(xMin, xMax)
    c = ot.Cloud(x, y)
    c.setColor("red")
    c.setPointStyle("bullet")
    g.add(c)
    data = ot.Sample(0, 2)
    msg = ot.Description(0)
    for i in range(len(x)-1):
    	data.add([x[i, 0], y[i, 0]])
        data.add([x[i+1, 0], y[i, 0]])
        data.add([x[i+1, 0], y[i+1, 0]])
        if abs(x[i, 0] - x[i+1, 0]) + abs(y[i, 0] - y[i+1, 0]) > 0.4:
            msg.add(r"$x_"+str(i)+r"$")
        else:
            msg.add("")
    msg.add(r"$x_\infty$")
    c = ot.Curve(data)
    c.setColor("green")
    g.add(c)
    z = ot.Curve([[xMin, 0.0], [xMax, 0.0]])
    z.setColor("black")
    z.setLineStyle("dashed")
    g.add(z)
    t = ot.Text(x, y, msg)
    t.setColor("black")
    t.setLegend(r"$x_\infty$="+str(root))
    g.add(t)
    g.setTitle("Root finding using " + solver.getClassName())
    fig = plt.figure()
    ax = fig.add_subplot(111)
    View(g, figure=fig)
    plt.xlabel(r'$x$')
    plt.ylabel(r'$f(x)$')
    plt.grid()

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

   {% block methods %}
   .. automethod:: __init__
   {% endblock %}

.. minigallery:: {{module}}.{{objname}}
   :add-heading: Examples using the class