Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help please with C++ Design and construct a computer program in one of the approved languages (C, C++, C#, Java, Pascal, Python, etc.)

I need help please with C++

image text in transcribed

image text in transcribed

image text in transcribed

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. 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. 3.0 2.5 2.0 1.5 1.0 0.5 0.0 0.5 1.0 1.5 2.0 Hint: It is often helpful to test your program on simple differential equations (such as x' = 1 or x'=t or x'=x) as a part of the debugging process. Once you have worked these simple cases, then try working the nonlinear differential equation given above for the assignment (with a small stepsize). Also, check your coefficients to make sure that they satisfy the equations of condition and that you have assigned these correct values to the variables or constants in your program properly. For example, a common error is to write something like: a2 = 1/2; when you meant to write a2 = 1.0/2.0; so please be careful. Write down (in your output file or in a separate text file) any conclusions that you can make from these experiments (e.g., what happens as h is decreased?). (* This notebook can be used to obtain the coefficients for your RK4 program) (* Just pick values for Q, and Q , then execute the notebook in order to print the coefficients +) (* For example, if you were to choose and the results would be those shown below) 3 (* place your own unique value of a, here ); 10 7 (* place your own value of here *); 10 1 - 202 + s (-2 + 6 ay) 12 a, a - 1+2 12 (-1+Q) as (as - Q3) 1 - 2 12 (4-02) (-1.) C = 3-42, + a, (-4.60) 12 (-14) (-1+0) Q = 1; Ba. (d, - 2); 24,(-1+20) Ba.. = (-1.2) (-2+2, +5Q, -40) 20: ((: - az) (3-42, + a, (-4+60z))* B2- (-1.2,) (-1.2Q) (-1.4) (Q. - az) (3 - 40+44 (-4+60z)) ay - 1; B1,0 = 0; Bea - 2.23 Be Q - Bau-Baas Print("The a coefficients are: ", Ag,", ,", a,,", a.-", ", ", ]; Print("The B coefficients are: ", " B.,e=", ,,", Be=", 12.0,", B2,", B2,22", Be=", 12,,", B2,=", B2,1, B2,=", 1,2]; Print("The c coefficients are: ", Com ", C-, ,,", CE", C]; Print("Now you know the coefficients you will need to complete the assignment: "); The a coefficients are: 3 7 ag=, 4.2=1 1e 10 The coefficients are: 3 7 7 70 15 15 39 39 13 The c coefficients are: 13 25 25 13 C CCC 126 63 63 126 Now you know the coefficients you will need to complete the assignment 1e 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. 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. 3.0 2.5 2.0 1.5 1.0 0.5 0.0 0.5 1.0 1.5 2.0 Hint: It is often helpful to test your program on simple differential equations (such as x' = 1 or x'=t or x'=x) as a part of the debugging process. Once you have worked these simple cases, then try working the nonlinear differential equation given above for the assignment (with a small stepsize). Also, check your coefficients to make sure that they satisfy the equations of condition and that you have assigned these correct values to the variables or constants in your program properly. For example, a common error is to write something like: a2 = 1/2; when you meant to write a2 = 1.0/2.0; so please be careful. Write down (in your output file or in a separate text file) any conclusions that you can make from these experiments (e.g., what happens as h is decreased?). (* This notebook can be used to obtain the coefficients for your RK4 program) (* Just pick values for Q, and Q , then execute the notebook in order to print the coefficients +) (* For example, if you were to choose and the results would be those shown below) 3 (* place your own unique value of a, here ); 10 7 (* place your own value of here *); 10 1 - 202 + s (-2 + 6 ay) 12 a, a - 1+2 12 (-1+Q) as (as - Q3) 1 - 2 12 (4-02) (-1.) C = 3-42, + a, (-4.60) 12 (-14) (-1+0) Q = 1; Ba. (d, - 2); 24,(-1+20) Ba.. = (-1.2) (-2+2, +5Q, -40) 20: ((: - az) (3-42, + a, (-4+60z))* B2- (-1.2,) (-1.2Q) (-1.4) (Q. - az) (3 - 40+44 (-4+60z)) ay - 1; B1,0 = 0; Bea - 2.23 Be Q - Bau-Baas Print("The a coefficients are: ", Ag,", ,", a,,", a.-", ", ", ]; Print("The B coefficients are: ", " B.,e=", ,,", Be=", 12.0,", B2,", B2,22", Be=", 12,,", B2,=", B2,1, B2,=", 1,2]; Print("The c coefficients are: ", Com ", C-, ,,", CE", C]; Print("Now you know the coefficients you will need to complete the assignment: "); The a coefficients are: 3 7 ag=, 4.2=1 1e 10 The coefficients are: 3 7 7 70 15 15 39 39 13 The c coefficients are: 13 25 25 13 C CCC 126 63 63 126 Now you know the coefficients you will need to complete the assignment 1e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago