Beispiel #1
0
def prob3():
    def bvp(epsilon, subintervals):
        # for figure3.pdf
        X, Y = fd_order2_ode(
            func=lambda x: np.cos(x),
            a1=lambda x: epsilon,
            a2=lambda x: 0.0,
            a3=lambda x: -4.0 * (np.pi - x ** 2.0),
            a=0.0,
            b=np.pi / 2.0,
            alpha=0.0,
            beta=1.0,
            N=subintervals,
        )
        return X, Y

    eps, subintervals = 0.1, 10
    X, Y = bvp(eps, subintervals)
    plt.plot(X, Y, "-k", mfc="None", linewidth=2.0)
    plt.ylabel("$y$", fontsize=16)
    plt.xlabel("$x$", fontsize=16)
    # plt.axis([-.1,np.pi/2.+.1,-.1,1.5])
    # plt.savefig('figure3.pdf')
    plt.show()
    plt.clf()
    raise SystemError
    num_approx = 6  # Number of Approximations
    N = 2560 * np.array([2 ** j for j in range(num_approx)])
    approx_order(num_approx, N, bvp, eps)
    return
Beispiel #2
0
def prob2():
    def bvp(epsilon, subintervals):
        # for figure2.pdf
        X, Y = fd_order2_ode(
            func=lambda x: -1.0,
            a1=lambda x: epsilon,
            a2=lambda x: -1.0,
            a3=lambda x: 0.0,
            a=0.0,
            b=1.0,
            alpha=1.0,
            beta=3.0,
            N=subintervals,
        )

        return X, Y

    def AnalyticSolution(x, alpha, beta, epsilon):
        out = alpha + x + (beta - alpha - 1.0) * (np.exp(x / epsilon) - 1.0) / (np.exp(1.0 / epsilon) - 1.0)
        return out

    eps, subintervals = 0.1, 20
    X, Y = bvp(eps, subintervals)
    plt.plot(X, Y, "-k", mfc="None", linewidth=2.0)
    plt.ylabel("$y$", fontsize=16)
    plt.xlabel("$x$", fontsize=16)
    # plt.axis([-.1,1.1,1-.1,3+.1])
    # plt.savefig('figure2.pdf')
    plt.show()
    plt.clf()
    num_approx = 6  # Number of Approximations
    N = 2560 * np.array([2 ** j for j in range(num_approx)])
    approx_order(num_approx, N, bvp, eps)
    return
Beispiel #3
0
def prob3():
    def bvp(epsilon, subintervals):
        # for figure3.pdf
        X, Y = fd_order2_ode(func=lambda x: np.cos(x),
                             a1=lambda x: epsilon,
                             a2=lambda x: 0.,
                             a3=lambda x: -4. * (np.pi - x**2.),
                             a=0.,
                             b=np.pi / 2.,
                             alpha=0.,
                             beta=1.,
                             N=subintervals)
        return X, Y

    eps, subintervals = 0.1, 10
    X, Y = bvp(eps, subintervals)
    plt.plot(X, Y, '-k', mfc="None", linewidth=2.0)
    plt.ylabel('$y$', fontsize=16)
    plt.xlabel('$x$', fontsize=16)
    # plt.axis([-.1,np.pi/2.+.1,-.1,1.5])
    # plt.savefig('figure3.pdf')
    plt.show()
    plt.clf()
    raise SystemError
    num_approx = 6  # Number of Approximations
    N = 2560 * np.array([2**j for j in range(num_approx)])
    approx_order(num_approx, N, bvp, eps)
    return
Beispiel #4
0
def prob2():
    def bvp(epsilon, subintervals):
        # for figure2.pdf
        X, Y = fd_order2_ode(func=lambda x: -1.,
                             a1=lambda x: epsilon,
                             a2=lambda x: -1.,
                             a3=lambda x: 0.,
                             a=0.,
                             b=1.,
                             alpha=1.,
                             beta=3.,
                             N=subintervals)

        return X, Y

    def AnalyticSolution(x, alpha, beta, epsilon):
        out = alpha + x + (beta - alpha - 1.) * (np.exp(x / epsilon) - 1.) / (
            np.exp(1. / epsilon) - 1.)
        return out

    eps, subintervals = 0.1, 20
    X, Y = bvp(eps, subintervals)
    plt.plot(X, Y, '-k', mfc="None", linewidth=2.0)
    plt.ylabel('$y$', fontsize=16)
    plt.xlabel('$x$', fontsize=16)
    # plt.axis([-.1,1.1,1-.1,3+.1])
    # plt.savefig('figure2.pdf')
    plt.show()
    plt.clf()
    num_approx = 6  # Number of Approximations
    N = 2560 * np.array([2**j for j in range(num_approx)])
    approx_order(num_approx, N, bvp, eps)
    return
def prob5():
	def bvp(epsilon, subintervals):
		# X,Y = fd_order2_ode(func=lambda x: 0.,a1=lambda x:1.,
		# 								  a2=lambda x: 4.*x/(epsilon+x**2.),a3=lambda x:2./(epsilon+x**2.),
		# 								  a=-1.,b=1., alpha=1./(1.+epsilon),
		# 								  beta=1./(1.+epsilon),N=subintervals)
		
		X,Y = fd_order2_ode(func=lambda x: 0.,a1=lambda x:(epsilon+x**2.),
										  a2=lambda x: 4.*x,a3=lambda x:2.,
										  a=-1.,b=1., alpha=1./(1.+epsilon),
										  beta=1./(1.+epsilon),N=subintervals)
		return X,Y
	
	eps, subintervals = 0.01, 100
	X,Y = bvp(eps, subintervals)
	plt.plot(X,Y,'-k',mfc="None",linewidth=2.0)
	
	# eps, subintervals = 0.02, 200
	# X,Y = bvp(eps, subintervals)
	# plt.plot(X,Y,'-k',mfc="None",linewidth=2.0)
	
	plt.ylabel('$y$',fontsize=16)
	plt.xlabel('$x$',fontsize=16)
	# plt.savefig('figure5.pdf')
	plt.show()
	plt.clf()
	# import sys; sys.exit()
	
	num_approx = 5 # Number of Approximations
	N = 2560*np.array([2**j for j in range(num_approx)])
	approx_order(num_approx,N,bvp,eps)
	return 
def prob4():
	def bvp(epsilon, subintervals):
		def g(x):
			out = -epsilon*pi**2.*cos(pi*x) - pi*x*sin(pi*x)
			return out
		
		X,Y = fd_order2_ode(func=g,a1=lambda x:epsilon,
										  a2=lambda x: x,a3=lambda x:0.,
										  a=-1.,b=1., alpha=-2.,beta=0.,N=subintervals)
		return X,Y
	
	eps, subintervals = 0.1, 20
	X,Y = bvp(eps, subintervals)
	plt.plot(X,Y,'-k',mfc="None",linewidth=2.0)
	
	import sys; sys.exit()
	eps, subintervals = 0.01, 400
	X,Y = bvp(eps, subintervals)
	plt.plot(X,Y,'-k',mfc="None",linewidth=2.0)
	
	eps, subintervals = 0.001, 400
	X,Y = bvp(eps, subintervals)
	plt.plot(X,Y,'-k',mfc="None",linewidth=2.0)
	
	plt.ylabel('$y$',fontsize=16)
	plt.xlabel('$x$',fontsize=16)
	# plt.savefig('figure4.pdf')
	plt.show()
	plt.clf()
	num_approx = 6 # Number of Approximations
	N = 2560*np.array([2**j for j in range(num_approx)])
	approx_order(num_approx,N,bvp,eps)
	return