Example #1
0
def plot_geom(items):
    plots = []
    #create plots from implicit equations
    for item in items:
        if isinstance(item,Circle):
            cc = Circle(item.center.evalf(), item.radius)
            pl = plot_implicit(cc.equation(),show=False)
            plots.append(pl)
        elif isinstance(item,Segment):
            limits = item.plot_interval()
            var, a0,a1 = limits
            xeq,yeq = item.arbitrary_point().args

            #introduce numerical precision
            xeq = xeq.evalf()
            yeq = yeq.evalf()
            new_limits = (xeq.free_symbols.pop(),a0,a1)
            pl = plot_parametric(xeq,yeq,new_limits, show=False, line_color='r')
            plots.append(pl)
        elif isinstance(item,Line):
            pl = plot_implicit(item.equation().evalf(),show=False)
            plots.append(pl)
        elif isinstance(item,Point):
            pc = Circle(item.evalf(), .2)
            plots.append(plot_geom([pc]))
        else:
            raise TypeError("item does not have recognized geometry type")
    #combine plots
    p = plots.pop()
    for e in plots:
        p.extend(e)
    return p
Example #2
0
def func_gui():
    lh = sympify(lhs.get())
    rh = sympify(rhs.get())
    eq = var.get()
    if eq == '=':
        p1 = plot_implicit(
            Eq(lh, rh), (x, l_x.get(), u_x.get()), (y, l_y.get(), u_y.get()),
            show=false,
            title=tit.get())  #,xlabel=x_lab.get(),ylabel=y_lab.get())
        p1[0].line_color = result[1]
        p1.show()
    elif eq == '>':
        p1 = plot_implicit(
            (lh > rh), (x, l_x.get(), u_x.get()), (y, l_y.get(), u_y.get()),
            show=false,
            title=tit.get())  #,xlabel=x_lab.get(),ylabel=y_lab.get())
        p1[0].line_color = result[1]
        p1.show()
    else:
        p1 = plot_implicit(
            (lh < rh), (x, l_x.get(), u_x.get()), (y, l_y.get(), u_y.get()),
            show=false,
            title=tit.get())  #,xlabel=x_lab.get(),ylabel=y_lab.get())
        p1[0].line_color = result[1]
        p1.show()
Example #3
0
def newton():
    x1 = Symbol("x1")
    y1 = Symbol("y1")
    m = 0.2
    a = 0.7
    e = 0.0001
    f1 = tan(x1 * y1 + m) - x1
    f2 = a * x1 ** 2 + 2 * y1 ** 2 - 1
    y11 = diff(f1, x1)
    y12 = diff(f1, y1)
    y21 = diff(f2, x1)
    y22 = diff(f2, y1)
    j = Matrix([[y11, y12], [y21, y22]])
    j1 = j.inv()
    x0 = 0.75
    y0 = 0.4
    xn = x0 - j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
    yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
    count2 = 0
    while (abs(xn - x0) > e) or (abs(yn - y0) > e):
        x0 = xn
        y0 = yn
        calcul = j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
        xn = x0 - calcul
        yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)

        count2 += 1
    print("x = ", xn, " ", "y = ", yn, " - ", count2, " iterations")
    print("graph processing...")
    plot_implicit(Or(Eq(a * x1 ** 2 + 2 * y1 ** 2, 1), Eq(tan(x1 * y1 + m) - x1, 0)), (x1, -5, 5), (y1, -5, 5))
Example #4
0
def plot_geom(items):
    plots = []
    fig = plt.figure()
    ax = fig.add_subplot(111)
    #create plots from implicit equations
    for item in items:
        if isinstance(item, Circle):
            cc = Circle(item.center.evalf(), item.radius)
            pl = plot_implicit(cc.equation(), show=False)
            plots.append(pl)
        elif isinstance(item, Segment):
            limits = item.plot_interval()
            var, a0, a1 = limits
            xeq, yeq = item.arbitrary_point().args
            #introduce numerical precision
            xeq = xeq.evalf()
            yeq = yeq.evalf()
            new_limits = (xeq.free_symbols.pop(), a0, a1)
            pl = plot_parametric(xeq,
                                 yeq,
                                 new_limits,
                                 show=False,
                                 line_color='r')
            plots.append(pl)
        elif isinstance(item, Line):
            pl = plot_implicit(item.equation().evalf(), show=False)
            plots.append(pl)
        elif isinstance(item, Point):
            pc = Circle(item.evalf(), .2)
            plots.append(plot_geom([pc]))
        elif isinstance(item, list):
            print("item")
            print(item)
            mat_pts = [(p.x.evalf(), p.y.evalf()) for p in item]
            print("mat_pts")
            print(mat_pts)
            mat_pts += [mat_pts[0]]  #line has to end where it starts
            codes = [Path.MOVETO]
            for i in range(len(mat_pts) - 2):
                codes += [Path.LINETO]
            codes += [Path.CLOSEPOLY]

            path = Path(mat_pts, codes)
            patch = patches.PathPatch(path, facecolor='red', alpha=.5, lw=2)
            ax.add_patch(patch)
            ax.set_xlim(-200, 200)
            ax.set_ylim(-200, 200)
        else:
            raise TypeError("item does not have recognized geometry type")
    #combine plots
    plt.show()
    p = plots.pop()
    for e in plots:
        p.extend(e)
    return p
Example #5
0
def plot_geom(items):
    plots = []
    fig = plt.figure()
    ax = fig.add_subplot(111)
    #create plots from implicit equations
    for item in items:
        if isinstance(item,Circle):
            cc = Circle(item.center.evalf(), item.radius)
            pl = plot_implicit(cc.equation(),show=False)
            plots.append(pl)
        elif isinstance(item,Segment):
            limits = item.plot_interval()
            var, a0,a1 = limits
            xeq,yeq = item.arbitrary_point().args
            #introduce numerical precision
            xeq = xeq.evalf()
            yeq = yeq.evalf()
            new_limits = (xeq.free_symbols.pop(),a0,a1)
            pl = plot_parametric(xeq,yeq,new_limits, show=False, line_color='r')
            plots.append(pl)
        elif isinstance(item,Line):
            pl = plot_implicit(item.equation().evalf(),show=False)
            plots.append(pl)
        elif isinstance(item,Point):
            pc = Circle(item.evalf(), .2)
            plots.append(plot_geom([pc]))
        elif isinstance(item, list):
            print("item")
            print(item)
            mat_pts = [(p.x.evalf(),p.y.evalf()) for p in item]
            print("mat_pts")
            print(mat_pts)
            mat_pts += [mat_pts[0]] #line has to end where it starts
            codes = [Path.MOVETO]
            for i in range(len(mat_pts)-2):
                codes += [Path.LINETO]
            codes += [Path.CLOSEPOLY]

            path = Path(mat_pts, codes)
            patch = patches.PathPatch(path, facecolor = 'red', alpha= .5,lw=2)
            ax.add_patch(patch)
            ax.set_xlim(-200,200)
            ax.set_ylim(-200,200)
        else:
            raise TypeError("item does not have recognized geometry type")
    #combine plots
    plt.show()
    p = plots.pop()
    for e in plots:
        p.extend(e)
    return p
Example #6
0
def iv_data(V_oc=45.9, I_sc=9.25, R_s=0.32, R_sh=20044, N=0.1):
    #     R_s = 0.32
    #     R_sh = 20044
    #     V_oc = 45.9
    n = 0.9
    N_Cell = 72
    V_t = 25.7e-3
    I_sat = (I_sc - (V_oc - I_sc * R_s) / R_sh) * (np.exp(-V_oc /
                                                          (n * N_Cell * V_t)))
    I_ph = I_sat * np.exp(V_oc / (n * N_Cell * V_t)) + (V_oc / R_sh)

    ##print ("V_oc is {}, \n I_sat is {}, \n I_ph is {}".format(V_oc, I_sat, I_ph))
    ########## 5 parameters are here : n, R_s, R_sh, I_sat, I_ph #############

    I = sp.Symbol('I')
    V = sp.Symbol('V')

    expr = (I - I_ph + I_sat * (sp.exp(
        (V + I * R_s) / (n * N_Cell * V_t)) - 1) + ((V + I * R_s) / R_sh))
    p = plot_implicit(expr, (V, 0, 50), (I, 0, 10), show=False)
    data = p[0].get_points()
    data = np.array([(x_int.mid, y_int.mid) for x_int, y_int in data[0]])
    V = [i[0] for i in data]
    I = [i[1] for i in data]
    return dict(x=V, y=I)
Example #7
0
def plot2D(variety_i):
    if (variety_i.n_vars() > 2):
        raise Exception("Too many vars %d" % variety_i.n_vars())
    plots = [
        plot_implicit(pol_i.as_expr(), show=False)
        for pol_i in variety_i.polynomials
    ]
    final_plot = plots[0]
    for plot_i in plots[1:]:
        final_plot.extend(plot_i)
    final_plot.show()
Example #8
0
def plot_geom(items):
    plots = []
    #create plots from implicit equations
    for item in items:
        if isinstance(item, Circle):
            cc = Circle(item.center.evalf(), item.radius)
            pl = plot_implicit(cc.equation(), show=False)
            plots.append(pl)
        elif isinstance(item, Segment):
            limits = item.plot_interval()
            var, a0, a1 = limits
            xeq, yeq = item.arbitrary_point().args

            #introduce numerical precision
            xeq = xeq.evalf()
            yeq = yeq.evalf()
            new_limits = (xeq.free_symbols.pop(), a0, a1)
            pl = plot_parametric(xeq,
                                 yeq,
                                 new_limits,
                                 show=False,
                                 line_color='r')
            plots.append(pl)
        elif isinstance(item, Line):
            pl = plot_implicit(item.equation().evalf(), show=False)
            plots.append(pl)
        elif isinstance(item, Point):
            pc = Circle(item.evalf(), .2)
            plots.append(plot_geom([pc]))
        else:
            raise TypeError("item does not have recognized geometry type")
    #combine plots
    p = plots.pop()
    for e in plots:
        p.extend(e)
    return p
Example #9
0
# equ-solve.py -- solve math equations
#
# 1. x^2 + (y-5)^2 = 5^2
# 2. y = x
#

from sympy.plotting import plot_implicit
from sympy.abc import x, y
from sympy import Eq, solve

# solve it directly
result = solve([Eq(x**2 + (y - 5)**2, 5**2), Eq(y, x)])
print("result: ", result)

# solve it with plotting
p1 = plot_implicit(Eq(x**2 + (y - 5)**2, 5**2), (x, -15, 15), (y, -15, 15),
                   line_color='red',
                   depth=1,
                   show=False,
                   margin=10)
p2 = plot_implicit(Eq(y, x), (x, -10, 10), (y, -10, 10),
                   depth=1,
                   line_color='blue',
                   show=False)
p1.extend(p2)

p1.title = "\n\nEquations: 1. x^2 + (y-5)^2 = 5^2; 2. y = x\n\n"
p1.size = (12, 12)
p1.show()
p1.save("equ-solve.jpg")
Example #10
0
    a_array = np.linspace(-2, 0, 1000)
    b_array = np.linspace(-1.8, 1.8, 10000)

    #fig1,ax1 = plt.subplots(1,1,figsize=(16,12))
    """
    for each_a in a_array:
        for each_b in b_array:
            isappend,vals = calc_contour(each_a,each_b)
            if isappend:
                ax1.plot(vals[0],vals[1],'or')
    """

    x, y = Symbol('x'), Symbol('y')  # Treat 'x' and 'y' as algebraic symbols
    p1 = plot_implicit(Eq(
        sqrt((1 + x + (x**2 - y**2) / 2)**2 + (y + x * y)**2), 1),
                       label='hello',
                       legend=True)
    fig1, ax1 = p1._backend.fig, p1._backend.ax
    fig1 = plt.gcf()
    fig1.set_size_inches(16, 12, forward=True)
    #fig1.figure(figsize=(16,12))
    ax1.set_xlabel(r'Re($\lambda \Delta t$)', fontsize=fs, fontweight=fw)
    ax1.set_ylabel(r'Im($\lambda \Delta t$)',
                   fontsize=fs,
                   fontweight=fw,
                   rotation=0,
                   position=(3, 0.95))
    ax1.set_title(
        "Eigenvalues of the 2nd-Order Upwind Scheme, Against the RK3 Stability Boundary",
        fontsize=fs,
        fontweight=fw)
Example #11
0
# %% markdown
# Some additional plotting functions can be imported from `sympy.plotting`.
# %%
from sympy.plotting import (plot_parametric,plot_implicit,
                            plot3d,plot3d_parametric_line,
                            plot3d_parametric_surface)
# %% markdown
# A parametric plot - a Lissajous curve.
# %%
t=Symbol('t')
plot_parametric(sin(2*t),cos(3*t),(t,0,2*pi),
                title='Lissajous',xlabel='x',ylabel='y')
# %% markdown
# An implicit plot - a circle.
# %%
plot_implicit(x**2+y**2-1,(x,-1,1),(y,-1,1))
# %% markdown
# A surface. If it is not inline but in a separaye window, you can rotate it with your mouse.
# %%
plot3d(x*y,(x,-2,2),(y,-2,2))
# %% markdown
# Several surfaces.
# %%
plot3d(x**2+y**2,x*y,(x,-2,2),(y,-2,2))
# %% markdown
# A parametric space curve - a spiral.
# %%
a=0.1
plot3d_parametric_line(cos(t),sin(t),a*t,(t,0,4*pi))
# %% markdown
# A parametric surface - a torus.
Example #12
0
def main():
    x1 = Symbol("x1")
    y1 = Symbol("y1")

    m = 0.1
    a = 0.7
    e = 0.0001

    count1 = 0
    x0 = 0.32
    y0 = 0.65

    x = tan(x0 * y0 + m)
    y = ((1 - a * x0 ** 2) / 2) ** 0.5

    while (abs(x - x0) > e) or (abs(y - y0) > e):
        x0 = x
        y0 = y
        x = tan(x0 * y0 + m)
        y = ((1 - a * x0 ** 2) / 2) ** 0.5
        count1 += 1

    print("Method of simple iterations:")
    print(x)
    print(y)
    print("iterations:")
    print(count1)

    f1 = tan(x1*y1 + m) - x1
    f2 = a*x1**2 + 2*y1**2 - 1
    y11 = diff(f1, x1)
    y12 = diff(f1, y1)
    y21 = diff(f2, x1)
    y22 = diff(f2, y1)
    J = Matrix([[y11, y12],
                [y21, y22]])
    J1 = J.inv()

    x0 = 0.32
    y0 = 0.65

    xn = x0 - J1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - J1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)

    yn = y0 - J1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - J1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)

    count2 = 0
    while (abs(xn - x0) > e) or (abs(yn - y0) > e):
        x0 = xn
        y0 = yn

        xn = (x0 - J1[0, 0].subs(x1, x0).subs(y1, y0) *
              f1.subs(x1, x0).subs(y1, y0) -
              J1[0, 1].subs(x1, x0).subs(y1, y0) *
              f2.subs(x1, x0).subs(y1, y0))

        yn = (y0 - J1[1, 0].subs(x1, x0).subs(y1, y0) *
              f1.subs(x1, x0).subs(y1, y0) -
              J1[1, 1].subs(x1, x0).subs(y1, y0) *
              f2.subs(x1, x0).subs(y1, y0))

        count2 += 1

    print("Newton's method:")
    print(xn)
    print(yn)
    print("iterations:")
    print(count2)

    plot_implicit(Or(Eq(a * x1 ** 2 + 2 * y1 ** 2, 1),
                     Eq(tan(x1 * y1 + m) - x1, 0)),
                  (x1, -5, 5), (y1, -5, 5))
Example #13
0
    a_array = np.linspace(-2, 0, 1000)
    b_array = np.linspace(-1.8, 1.8, 10000)

    #fig1,ax1 = plt.subplots(1,1,figsize=(16,12))
    """
    for each_a in a_array:
        for each_b in b_array:
            isappend,vals = calc_contour(each_a,each_b)
            if isappend:
                ax1.plot(vals[0],vals[1],'or')
    """

    x, y = Symbol('x'), Symbol('y')  # Treat 'x' and 'y' as algebraic symbols
    p1 = plot_implicit(Eq(
        sqrt((1 + x + (x**2 - y**2) / 2)**2 + (y + x * y)**2), 1),
                       color='g')
    fig1, ax1 = p1._backend.fig, p1._backend.ax
    fig1 = plt.gcf()
    fig1.set_size_inches(16, 12, forward=True)
    #fig1.figure(figsize=(16,12))
    ax1.set_xlabel(r'Re($\lambda \Delta t$)', fontsize=fs + 5, fontweight=fw)
    ax1.set_ylabel(r'Im($\lambda \Delta t$)',
                   fontsize=fs + 5,
                   fontweight=fw,
                   rotation=0,
                   position=(3, 0.95))
    ax1.set_title(
        "Eigenvalues of the 2nd-Order Upwind Scheme, Against the RK2 Stability Boundary",
        fontsize=fs,
        fontweight=fw)
Example #14
0
# 𝑃(𝑋|πœ”π‘–)=1/(2πœ‹)^2|𝛴𝑖|1/2𝑒π‘₯𝑝[βˆ’12{(π‘‹βˆ’ΞΌπ‘–)π‘‘π›΄π‘–βˆ’1(π‘‹βˆ’ΞΌπ‘–)}]

x, y = symbols('x y')
M = np.array([x, y])

values_x = np.arange(-5, 10.1, 0.1)
values_y = np.arange(-5, 10.1, 0.1)

boundaries = [
    p_w1_X(M) - p_w2_X(M),
    p_w2_X(M) - p_w3_X(M),
    p_w3_X(M) - p_w1_X(M)
]

p = plot_implicit(boundaries[0], (x, -10, 10), (y, -10, 10),
                  show=False,
                  line_color='yellow')
p.extend(
    plot_implicit(boundaries[1], (x, -10, 10), (y, -10, 10),
                  show=False,
                  line_color='pink'))
p.extend(
    plot_implicit(boundaries[2], (x, -10, 10), (y, -10, 10),
                  show=False,
                  line_color='blue'))

# equations=[]
# for boundary in boundaries:
# equations.extend(solve(boundary,(x,y)))
# p=plot_parametric(equations[0],label="decision boundary",line_color='black',show=False)
# for equation in equations:#[1:]:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

# 2018-04-10T17:48+08:00

from sympy import Rational as R
from sympy.abc import x, y
from sympy.plotting import plot_implicit

# x^2 + y^2 = (2*x^2 + 2*y^2 - x)^2
plot_implicit(x**2 + y**2 - (2 * x**2 + 2 * y**2 - x)**2, (x, -0.5, 1.5),
              (y, -0.75, 0.75),
              title='cardioid')

# x^(2/3) + y^(2/3) = 4
plot_implicit(x**R(2, 3) + y**R(2, 3) - 4, (x, -10, 10), (y, -10, 10),
              title='astroid')

# 2*(x^2 + y^2)^2 = 25*(x^2 - y^2)
plot_implicit(2 * (x**2 + y**2)**2 - 25 * (x**2 - y**2), title='lemniscate')

# y^2*(y^2 - 4) = x^2*(x^2 - 5)
plot_implicit(y**2 * (y**2 - 4) - x**2 * (x**2 - 5), title='devil\'s curve')

# References:
# Calculus, 7ed, James.Stewart, P157
Example #16
0
      frameon=None)
  
  a_array = np.linspace(-2,0,1000)
  b_array = np.linspace(-1.8,1.8,10000)
  
  #fig1,ax1 = plt.subplots(1,1,figsize=(16,12)) 
  """
  for each_a in a_array:
      for each_b in b_array:
          isappend,vals = calc_contour(each_a,each_b)
          if isappend:
              ax1.plot(vals[0],vals[1],'or')
  """
 
  x,y = Symbol('x'),Symbol('y') # Treat 'x' and 'y' as algebraic symbols
  p1= plot_implicit(Eq(sqrt((1+x+(x**2-y**2)/2)**2 + (y + x*y)**2), 1),color='g')
  fig1, ax1 = p1._backend.fig, p1._backend.ax
  fig1 = plt.gcf()
  fig1.set_size_inches(16, 12, forward=True)
  #fig1.figure(figsize=(16,12))    
  ax1.set_xlabel(r'Re($\lambda \Delta t$)', fontsize=fs+5, fontweight=fw)
  ax1.set_ylabel(r'Im($\lambda \Delta t$)', fontsize=fs+5, fontweight=fw, rotation=0, position=(3,0.95))
  ax1.set_title("Eigenvalues of the 2nd-Order Upwind Scheme, Against the RK2 Stability Boundary", fontsize=fs, fontweight=fw)    
  ax1.tick_params(axis='both',which='major',labelsize=20)
  
  ax1.set_xlim([-2.1,0])
  ax1.set_ylim([-2,2])
  phis = np.linspace(0, 2*np.pi, 1000)
  
  
  cfl_list = np.array(cfl_list)
Example #17
0
def ezplot(s):
    #Parse doesn't parse = sign so split
    lhs, rhs = s.replace("^", "**").split("=")
    eqn_lhs = parse_expr(lhs)
    eqn_rhs = parse_expr(rhs)
    plot_implicit(eqn_lhs)
Example #18
0
def max_interval(A, B, C, D, y, eps, show=False):
    x = Symbol('x', real=True)
    fx = A * x**3 + B * x**2 + C * x + D
    intervals = solve(abs(fx - y) < eps)

    xranges = []
    diffs = []
    for interval in intervals.args if type(intervals) is Or else [intervals]:
        lhs, rhs = interval.args
        lb = lhs.lts
        ub = rhs.gts
        xranges.append((lb, ub))
        diffs.append((ub - lb))
    maxdiff = max(diffs)

    if show:
        min_x = min(b[0] for b in xranges)
        max_x = max(b[1] for b in xranges)
        adj = 0.1 * (max_x - min_x)
        min_x = min_x - adj
        max_x = max_x + adj

        dfx = diff(fx, x)
        extrema = solve(dfx)
        x_candidates = [min_x, max_x] + list(
            filter(lambda x: min_x < x < max_x, extrema))
        y_candidates = list(map(lambdify(x, fx), x_candidates))
        min_y = min(y_candidates)
        max_y = max(y_candidates)
        adj = 0.1 * (max_y - min_y)
        min_y = min_y - adj
        max_y = max_y + adj
        xlim = (min_x, max_x)
        ylim = (min_y, max_y)

        p = plot(fx,
                 show=False,
                 xlim=xlim,
                 ylim=ylim,
                 adaptive=False,
                 nb_of_points=1000)
        p.append(plot(y, show=False, xlim=xlim, ylim=ylim, line_color='r')[0])
        p.append(
            plot(y - eps,
                 show=False,
                 xlim=xlim,
                 ylim=ylim,
                 line_color='lightsalmon',
                 markers=['.'])[0])
        p.append(
            plot(y + eps,
                 show=False,
                 xlim=xlim,
                 ylim=ylim,
                 line_color='lightsalmon',
                 markers=['.'])[0])
        for d, (lb, ub) in zip(diffs, xranges):
            p.append(
                plot_implicit(Eq(x, lb), show=False, xlim=xlim, ylim=ylim)[0])
            p.append(
                plot_implicit(Eq(x, ub), show=False, xlim=xlim, ylim=ylim)[0])
        print("  ".join(str(x) for x in diffs))
        p.show()

    return maxdiff
Example #19
0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

# 2018-04-10T17:48+08:00

from sympy import Rational as R
from sympy.abc import x, y
from sympy.plotting import plot_implicit

# x^2 + y^2 = (2*x^2 + 2*y^2 - x)^2
plot_implicit(x**2 + y**2 - (2*x**2 + 2*y**2 - x) ** 2, (x, -0.5, 1.5), (y, -0.75, 0.75), title='cardioid')

# x^(2/3) + y^(2/3) = 4
plot_implicit(x**R(2, 3) + y**R(2, 3) - 4, (x, -10, 10), (y, -10, 10), title='astroid')

# 2*(x^2 + y^2)^2 = 25*(x^2 - y^2)
plot_implicit(2 * (x**2 + y**2) ** 2 - 25 * (x**2 - y**2), title='lemniscate')

# y^2*(y^2 - 4) = x^2*(x^2 - 5)
plot_implicit(y ** 2 * (y**2 - 4) - x ** 2 * (x**2 - 5), title='devil\'s curve')

# References:
# Calculus, 7ed, James.Stewart, P157
Example #20
0
def plot_implicit(*args, **kwargs):
    if "show" in kwargs:
        kwargs.pop("show")
    return plotter.plot_implicit(*plotArgs(args), show=False, **kwargs)
Example #21
0
File: math.py Project: Iisting/Miza
def plot_implicit(*args, **kwargs):
    kwargs.pop("show", None)
    return plotter.plot_implicit(*plotArgs(args), show=False, **kwargs)
def findQ0(phi,myu0,myu1,sig,sig0,sig1):
    x1 , x2 = symbols('x1 x2')
    # p2 = plot_implicit(Eq(x1**2+x2**2,2))
    p1 =plot_implicit( Eq(-0.5*(([[x1, x2]]-myu0)*inv(sig)*(np.transpose([[x1 ,x2]]-myu0)))[0][0]+0.5*(([[x1, x2]]-myu1)*inv(sig)*(np.transpose([[x1 ,x2]]-myu1)))[0][0] + math.log(float(1-phi)/phi) ,0),(x1, 60, 200), (x2, 60, 200))

    ezplot('-0.5*((np.transpose([[x1],[x2]]-mu0))*inv(cov_mat1)*([[x1],[x2]]-mu0)- (np.transpose([[x1],[x2]]-mu1))*inv(cov_mat1)*([[x1],[x2]]-mu1) + math.log(float(1-phi)/phi)) = [[0]]')
Example #23
0
def plot_implicit_equal(*args, **kwargs):
    p = plot_implicit(*args, **kwargs)
    p._backend.ax.set_aspect("equal")
    return p._backend.fig
Example #24
0
      frameon=None)
  
  a_array = np.linspace(-2,0,1000)
  b_array = np.linspace(-1.8,1.8,10000)
  
  #fig1,ax1 = plt.subplots(1,1,figsize=(16,12)) 
  """
  for each_a in a_array:
      for each_b in b_array:
          isappend,vals = calc_contour(each_a,each_b)
          if isappend:
              ax1.plot(vals[0],vals[1],'or')
  """
 
  x,y = Symbol('x'),Symbol('y') # Treat 'x' and 'y' as algebraic symbols
  p1= plot_implicit(Eq(sqrt((1+x+(x**2-y**2)/2)**2 + (y + x*y)**2), 1),label='hello',legend=True)
  fig1, ax1 = p1._backend.fig, p1._backend.ax
  fig1 = plt.gcf()
  fig1.set_size_inches(16, 12, forward=True)
  #fig1.figure(figsize=(16,12))    
  ax1.set_xlabel(r'Re($\lambda \Delta t$)', fontsize=fs, fontweight=fw)
  ax1.set_ylabel(r'Im($\lambda \Delta t$)', fontsize=fs, fontweight=fw, rotation=0, position=(3,0.95))
  ax1.set_title("Eigenvalues of the 2nd-Order Upwind Scheme, Against the RK3 Stability Boundary", fontsize=fs, fontweight=fw)    
  
  ax1.set_xlim([-2.1,1])
  ax1.set_ylim([-2,2])
  phis = np.linspace(0, 2*np.pi, 1000)
  
  
  cfl_list = np.array(cfl_list)
  delta_x = xmax/meshsize