Question

In: Computer Science

Design and construct a computer program in one of the approved languages (C++) that will illustrate...

Design and construct a computer program in one of the approved languages (C++) that will illustrate the use of a fourth-order explicit Runge-Kutta method of your own design. In other words, you will first have to solve the Runge-Kutta equations of condition for the coefficients of a fourth-order Runge-Kutta method. See the Mathematica notebook on solving the equations for 4th order RK method. That notebook can be found at rk4Solution.nb . PLEASE DO NOT USE a[1] = 1/2 or a[2] = 1/2. In general, you should pick a[1] and a[2] to be distinct values greater than zero and less than one. Then, you will use these coefficients in a computer program to solve the ordinary differential equation below. Be sure to follow the documentation and programming style policies of the Computer Science Department.

The initial value problem to be solved is the following: x'(t) = 3 x2 cos(5 t) subject to the initial condition: x(0) = 1.0 Obtain a numerical solution to this problem over the range from t=0.0 to t=2.0 for seven different values of the stepsize, h=0.1, 0.05 , 0.025 , 0.0125 , 0.00625 , 0.003125 , and 0.0015625 . In other words, make seven runs with 20, 40, 80, 160, 320, 640, and 1280 steps, respectively. For each run, print out the value of h, then a table of t and x, and then the error at t=2. You may use the following very precise value for your "true answer" in order to compute the error at t=2: 0.753913186469598763502963347. The true solution of this differential equation resembles the following plot of x(t) as a function of t.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import math


def dxdt(t, x):
    return (3*(x**2)*math.cos(5*t))

# Finds value of x for a given t using step size h
# and initial value x0 at t0.


def rungeKutta(t0, x0, t, h):
    # Count number of iterations using step size or
    # step height h
    n = (int)((t - t0)/h)
    # Iterate for number of iterations
    x = x0
    for i in range(1, n + 1):
        "Applx Runge Kutta Formulas to find nett value of x"
        k1 = h * dxdt(t0, x)
        k2 = h * dxdt(t0 + 0.5 * h, x + 0.5 * k1)
        k3 = h * dxdt(t0 + 0.5 * h, x + 0.5 * k2)
        k4 = h * dxdt(t0 + h, x + k3)

        # Update nett value of x
        x = x + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4)

        # Update nett value of t
        t0 = t0 + h
    return x


# Driver method
t0 = 0.0
x = 1.0
t = 2.0
a = [0.1, 0.05, 0.025, 0.0125, 0.00625, 0.003125, 0.0015625]
i = 1
for i in range(len(a)):
    print("The value of x at with step-size %.7f is: %.27f" %
          (a[i], rungeKutta(t0, x, t, a[i])))

print("Error at t=2 is: ", 0.753913186469598763502963347 -
      rungeKutta(t0, x, 2, 0.0015625))

Related Solutions

Design and construct a computer program in one of the approved languages (C, C++, C#, Java,...
Design and construct a computer program in one of the approved languages (C, C++, C#, Java, Pascal, Python, etc.) that will illustrate the use of a fourth-order explicit Runge-Kutta method of your own design. In other words, you will first have to solve the Runge-Kutta equations of condition for the coefficients of a fourth-order Runge-Kutta method. Then, you will use these coefficients in a computer program to solve the ordinary differential equation below. Be sure to follow the documentation and...
Bank One just approved a loan for Dante Inc. to start a website design and maintenance...
Bank One just approved a loan for Dante Inc. to start a website design and maintenance business. Dante Inc. is ready to purchase needed equipment, hire administrative help, and begin designing websites. During June, Dante’s first month of business, the following transactions occurred: Dante Inc. signed a note at the bank and received $20,000 cash. Dante issued shares of capital stock to its shareholders in the amount of $3,000 cash. Dante purchased a new computer and additional equipment for $3,000...
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Newsoft is a computer software company that is setting up a new program design facility in...
Newsoft is a computer software company that is setting up a new program design facility in a nation that the company has not had any relationship with before. Yusuf is the Human Resource manager for the entire company. He is considering two different candidates to be the Operations manager of the new facility, Maria (who is a woman) and Raj (who is a man). Maria is better qualified than Raj for this new opportunity and is Jared’s preferred choice. Jared...
Construct NFA of following languages and convert it to equivalent DFA. The set of all binary...
Construct NFA of following languages and convert it to equivalent DFA. The set of all binary strings such that 3th symbol from right end is 0.
Code the FSM in C++, and show that the program works. Construct a Finite State Machine...
Code the FSM in C++, and show that the program works. Construct a Finite State Machine that models an old-fashioned soda machine that accepts nickels, dimes, and quarters. The soda machine accepts change until 35 cents have been put in. It gives change back for any amount greater than 35 cents. Then the customer can push buttons to receive either a cola, a root beer, or a ginger ale.
4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data,...
4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even. 5. Make the flowchart and the C ++ program that, when receiving N integers as...
what is the best code to construct a C++ program that finds a five digit number;...
what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT