Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that solves the equations for our projectile. Equations are f(v) = b v 3/2 , m~a = m~g f(v)v, , ,

Write a C++ program that solves the equations for our projectile. Equations are f(v) = b v 3/2 , m~a = m~g f(v)v, image text in transcribed, image text in transcribed, vx = dx/dt, vy = dy/dt. The update functions are x(t + t) = x(t) + t vx(t) , vx(t + t) = vx(t)(1 (t/m)(f(v)/v) ) , y(t + t) = y(t) + t vy(t) , vy(t + t) = vy(t) t (g + (f(v)/mv) vy(t)).

a) Define global variables for the acceleration of gravity g = 9.8 m/s2 , mass m = 5.4 kg, and drag strength b. The first two should have their values assigned when the variables are declared

b) Define a function v(vx, vy) that returns the speed of the projectile, based on the velocity components vx and vy

c) Define a function drag(vx, vy) that returns the magnitude of the drag force divided by the mass and speed, i.e. f(v)/(mv). note: you should simplify the formula before coding it to avoid possible divisions by zero

d) Define an update function that performs one step dt. The function should modify the variables t, x, y, vx, vy in place and also take the step size dt as argument. This function should not return any value

e) Define a function solve(t0, x0, y0, vx0, vy0, Nsteps, dt, file) that takes initial conditions t0, x0, y0, vx0, vy0, maximum number of steps Nsteps, step size dt, and file name file as parameters, performs Nsteps updates of the variables, printing the results into file file. The output file should contain 5 columns: t x y vx vy, and the function should return 0 for success or 1 for failure

f) Add a test in the loop of the solve function so the loop is terminated if y becomes negative

g) Have the main program do the following:

Ask the user to enter the values of y0, v0x, v0y, b, as well as the time step, the number of steps to perform, and an output file name;

If no file name is given, use a default value of your choice;

Set the initial time and horizontal position value to t0=0, x0 = 0;

Write a message giving the values of all parameters in an understandable way;

Call the solve function with the parameters entered;

Write a message when the execution is finished letting the user know if the program was successful and where the data was written

h) Test your program by running it for the case with no drag (b = 0) where we know the trajectory is image text in transcribed , Create a python plot showing the analytic solution together with your numerical solution for 3 values of t, showing that the numerical solution converges toward the analytic solution (use y0 = 10 m, v0x = 8.3 m/s and v0y = 5.9 m/s). Make sure that your solution is good enough to get the landing point within 1 cm of the analytic solution (show that it is the case in a subplot or inset zooming on the landing point)

i) Run your program with the same parameters as in the previous item with increasing values of the drag strength b = 0.1, 0.2, 0.5, 1.0. Create a plot showing these trajectories, together with the one without drag

j) Finally, run your program with v0x = v0y = 0, y0 = 500 m, and b = 0.5. Create a plot that shows that the projectile reaches a terminal speed. Determine the terminal speed graphically and show it on the plot

d- f(v) va dt

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Under what conditions can perspective taking have negative effects?

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago