Ejemplo n.º 1
0
    print(x)
    uquad = x[0] * time**2.0 + time * x[1] + x[2]
    #---------------------------------------------------------------------#
    # Constructing B linear  matrix                                       #
    #---------------------------------------------------------------------#
    B = zeros((len(time), 2))
    for i in range(0, len(time)):
        B[i, 0] = time[i]
        B[i, 1] = 1.0
    print_matrix(B, 'B=')
    xb = linalg.inv(transpose(B) @ B) @ (transpose(B) @ u)
    print(x)
    ulinear = xb[0] * time + xb[1]
    #---------------------------------------------------------------------#
    # Plotting data                                                       #
    #---------------------------------------------------------------------#
    plot_setting()
    plt.plot(time, u, 'ro', lw=1.5)
    plt.plot(time, ulinear, 'g--', lw=1.5, \
                label='$u=%3.2ft + %3.2f$' %(xb[0], xb[1])  )
    plt.plot(time, uquad, 'k--', lw=1.5,\
            label='$u=%3.2f t^{2}+%3.2f t+%3.2f$'  %(x[0], x[1], x[2]))
    plt.grid(True)
    plt.legend(loc=0)
    plt.xlabel('time')
    plt.ylabel('Velocity')
    plt.show()

    print('**** Successful run ****')
    sys.exit(0)
Ejemplo n.º 2
0
def plot_x_location(Locs,
                    T_steps,
                    T_vals,
                    direction,
                    name=False,
                    time_flag=False):
    """ Plotting different x locations """

    #---------------------------------------------------------------------#
    # Default is time steps                                               #
    #---------------------------------------------------------------------#
    if time_flag is True:
        x_vec = T_vals
        xlab = 'Time'
    else:
        x_vec = T_steps
        xlab = 'Time step'
    #---------------------------------------------------------------------#
    # Plotting location                                                   #
    #---------------------------------------------------------------------#
    plot_setting()
    syms = ['r', 'b', 'g', 'k', 'm', 'c', 'y']
    for q, T in enumerate(test):
        #-----------------------------------------------------------------#
        # Plot symbol                                                     #
        #-----------------------------------------------------------------#
        if q >= len(syms):
            diff = int(q - len(syms))
            symbol = syms[diff] + dash(diff, syms)
        else:
            symbol = syms[q]
        #-----------------------------------------------------------------#
        # Plot Label                                                      #
        #-----------------------------------------------------------------#
        lab = get_label(T, tzero)
        #-----------------------------------------------------------------#
        # Plot plot                                                       #
        #-----------------------------------------------------------------#
        plt.plot(x_vec[q], Locs[q], symbol, label=lab)
        #-----------------------------------------------------------------#
        # Plotting the location of BS and DS switch                       #
        #-----------------------------------------------------------------#
        plt.plot([0, 0], [7, -7], 'b--', lw=1.5)
    #---------------------------------------------------------------------#
    # Plot settings                                                       #
    #---------------------------------------------------------------------#
    plt.grid(True)
    plt.legend(loc=0)
    plt.ylabel('$x_{%i}$ location' % (int(direction)))
    plt.xlabel(xlab)
    #---------------------------------------------------------------------#
    # Plot limits                                                         #
    #---------------------------------------------------------------------#
    x_min = -int(T - tzero)
    x_max = int(max(test) - tzero)
    plt.xlim([x_min, x_max])
    plt.ylim([0., 2.0 * pi])
    plt.yticks([0, 0.5*pi, pi, 1.5*pi, 2.0*pi], \
                [0,\
                '$\\pi/2$',\
                '$\\pi$',\
                '$3\\pi/2$',\
                '$2\\pi$'])
    #---------------------------------------------------------------------#
    # Flip axis                                                           #
    #---------------------------------------------------------------------#
    ax1 = plt.gca()
    ax1.invert_xaxis()
    #---------------------------------------------------------------------#
    # Saving                                                              #
    #---------------------------------------------------------------------#
    if name is not False:
        plt.layout_tight()
        plt.savefig(media_path + name + '.png', bbox_inches='tight')
    plt.show()

    return