Esempio n. 1
0
##: print final answers to screen
print('\nFinal time [s]:\t' + str(t[-1]))
print('Cost:\t\t' + str(cost))
print('Comp time [ms]:\t' + str(time * 1000))
print('Iterations:\t' + str(it))
print('Loss:\t\t' + str(np.max(L(xi, IC))))

## Plot solution: **********************************************************************************

# range vs crosstrack
p1 = MakePlot('Range [km]', 'Crosstrack [km]')
p1.ax[0].plot(R[:, 0] / 1000., R[:, 1] / 1000., 'k')
p1.ax[0].grid(True)
p1.PartScreen(8., 7.)
p1.show()

# 3d trajectoryAc
p2 = MakePlot(r'Range [km]', r'Crosstrack [km]', zlabs=r'Altitude [km]')
p2.ax[0].plot(R[:, 0] / 1000., R[:, 1] / 1000., R[:, 2] / 1000., 'k')
p2.ax[0].quiver(R[0::2,0]/1000.,R[0::2,1]/1000.,R[0::2,2]/1000., \
                Ac[0::2,0], Ac[0::2,1], Ac[0::2,2], \
                color='r', linewidth=1)
p2.ax[0].grid(True)

p2.ax[0].xaxis.labelpad = 10
p2.ax[0].yaxis.labelpad = 10
p2.ax[0].zaxis.labelpad = 10

p2.PartScreen(8., 7.)
p2.show()
Esempio n. 2
0
import tqdm
import pickle

from tfc.utils import MakePlot

## TEST PARAMETERS: ***************************************************
sol = pickle.load(open('data/timingLyap_CP_L1.pickle','rb'))

MS = 10
width = 0.0085      # the width of the bars: can also be len(x) sequence


p1 = MakePlot('Jacobi Constant','Computation Time [s]')

p1.ax[0].bar(sol['C'],sol['tLoss'],width, label='Loss function')
p1.ax[0].bar(sol['C'],sol['tJac'],width,bottom=sol['tLoss'],label='Jacobian')
p1.ax[0].bar(sol['C'],sol['tLS'],width,bottom=sol['tLoss']+sol['tJac'],label='Least-squares')



p1.ax[0].grid(True)
delta = 0.5*(sol['C'][0]-sol['C'][1])
p1.ax[0].set_xlim(sol['C'].min()-delta,sol['C'].max()+delta)

p1.ax[0].legend(loc='upper center', bbox_to_anchor=(0.5, 1.14),
          ncol=4, fancybox=True, shadow=True)
p1.fig.subplots_adjust(left=0.11, bottom=0.11, right=0.89, top=0.85)
p1.PartScreen(12.,7.)
p1.show()
# p1.save('figures/timeBreakdown')
Esempio n. 3
0
u = lambda t,g: g(t)+\
                (t-1.)*(t-2.)/2.*(0.-g(0.))+\
                -t*(t-2.)*(np.pi-g(1.))+\
                t*(t-1.)/2.*(np.exp(1.)-g(2.))

v = lambda t,g: g(t)+\
                (t-1.)*(t-2.)/2.*(0.-g(0.))+\
                -t*(t-2.)*(2.-g(1.))+\
                t*(t-1.)/2.*(-3.-g(2.))

# Create free functions:
gu1 = lambda t: np.sin(10. * t)
gv1 = lambda t: np.cos(7. * t)
gu2 = lambda t: t**2 + t + 5.
gv2 = lambda t: np.exp(t) / (1. + t)
gu3 = lambda t: t % 1
gv3 = lambda t: np.cos(3. * np.sqrt(t)) * t

# Create the plot:
p = MakePlot(r"u(t)", r"v(t)")
p.ax[0].plot(u(t, gu1), v(t, gv1), "r")
p.ax[0].plot(u(t, gu2), v(t, gv2), "g")
p.ax[0].plot(u(t, gu3), v(t, gv3), "b")
p.ax[0].plot([0., np.pi, np.exp(1.)], [0., 2., -3.],
             "k",
             linestyle="None",
             marker=".",
             markersize=10)
p.FullScreen()
p.show()
Esempio n. 4
0
MS = 10
p1 = MakePlot('Jacobi Constant', 'Computation Time [s]')
p1.ax[0].plot(tfc['C'], tfc['time'], 'ro', label='scaled', markersize=MS)
p1.ax[0].plot(nsc['C'], nsc['time'], 'ko', label='non-scaled', markersize=MS)
p1.ax[0].axvline(x=Jc(L1), color='b', label='E(L1)', linestyle='--')
p1.ax[0].axvline(x=Jc(L2), color='g', label='E(L2)', linestyle='--')
p1.ax[0].grid(True)

p1.ax[0].legend(loc='upper center',
                bbox_to_anchor=(0.5, 1.14),
                ncol=4,
                fancybox=True,
                shadow=True)
p1.fig.subplots_adjust(left=0.11, bottom=0.11, right=0.89, top=0.85)
p1.PartScreen(9., 6.)
p1.show()
# p1.save('figures/compTime' + file1)

# p2 = MakePlot('Jacobi Constant','Iterations')
# p2.ax[0].plot(tfc['C'],tfc['iter'],'rx', label='scaled', markersize = MS)
# p2.ax[0].axvline(x=Jc(L1), color='b', label='E(L1)', linestyle = '--')
# p2.ax[0].axvline(x=Jc(L2), color='g', label='E(L2)', linestyle = '--')
# p2.ax[0].legend(loc='upper center', bbox_to_anchor=(0.5, 1.14),
#           ncol=3, fancybox=True, shadow=True)
# p2.fig.subplots_adjust(left=0.11, bottom=0.11, right=0.89, top=0.85)
# p2.ax[0].grid(True)
# p2.PartScreen(9.,6.)
# p2.show()
# p2.save('figures/iterations'+ file1)

tfcRes = np.zeros(len(tfc['C']))
Esempio n. 5
0
d2r = egrad(dr)
L = lambda xi: -r(th,xi)**2*(dr(th,xi)*np.tan(th)+2.*d2r(th,xi))+\
               -np.tan(th)*dr(th,xi)**3+3.*r(th,xi)*dr(th,xi)**2+r(th,xi)**3

# Solve the problem:
xi = np.zeros(H(th).shape[1])
xi, _, time = NLLS(xi, L, timer=True)

# Print out statistics:
print("Solution time: {0} seconds".format(time))

# Plot the solution and residual
p = MakePlot([r"$y$"], [r"$x$"])
p.ax[0].plot(r(th, xi) * np.sin(th), r(th, xi) * np.cos(th), "k")
p.ax[0].axis("equal")
p.ax[0].grid(True)
p.ax[0].invert_yaxis()
p.PartScreen(8, 7)
p.show()

p2 = MakePlot([r"$\theta$"], [r"$L$"])
p2.ax[0].plot(th,
              np.abs(L(xi)),
              "k",
              linestyle="None",
              marker=".",
              markersize=10)
p2.ax[0].set_yscale("log")
p2.PartScreen(8, 7)
p2.show()
Esempio n. 6
0
              dif['time'],
              'ko',
              label='Differential Corrector',
              markersize=MS)
p1.ax[0].axvline(x=Jc(L1), color='b', label='E(L1)', linestyle='--')
p1.ax[0].axvline(x=Jc(L2), color='g', label='E(L2)', linestyle='--')
p1.ax[0].grid(True)

p1.ax[0].legend(loc='upper center',
                bbox_to_anchor=(0.5, 1.14),
                ncol=4,
                fancybox=True,
                shadow=True)
p1.fig.subplots_adjust(left=0.11, bottom=0.11, right=0.89, top=0.85)
p1.PartScreen(9., 6.)
p1.show()
# p1.save('figures/compTime' + file1)

p2 = MakePlot('Jacobi Constant', 'Iterations')
p2.ax[0].plot(tfc['C'], tfc['iter'], 'rx', label='TFC', markersize=MS)
p2.ax[0].axvline(x=Jc(L1), color='b', label='E(L1)', linestyle='--')
p2.ax[0].axvline(x=Jc(L2), color='g', label='E(L2)', linestyle='--')
p2.ax[0].legend(loc='upper center',
                bbox_to_anchor=(0.5, 1.14),
                ncol=3,
                fancybox=True,
                shadow=True)
p2.fig.subplots_adjust(left=0.11, bottom=0.11, right=0.89, top=0.85)
p2.ax[0].grid(True)
p2.PartScreen(9., 6.)
p2.show()