Guaranteed Higher Grade!

Free Quote
Computer Programming Assignment: Modeling an Experiment using C

Students will display their knowledge of building and using functions (and previous course topics) in programming using a real-world example.Problem: You are working on an undergraduate research project at Stirling Hall, which is studying the electromagnetic properties of some large particles using a modified mass spectrometer. This device works by firing a charged particle through a vacuum tube that has an area of potential difference, which accelerates the particle to high speeds. Then, the particle encounters a magnetic field which causes the particle to move in a circular path. Based on the radius of this curved path, you can determine the mass of the test particle. The following equations describe both the acceleration of the particle and its circular path:

qV = 1/2 mv^2 (1)

qvB = mv^2 / r (2)

where q is the electric charge of the particle, V = the potential difference in volts [V], m is the mass of the particle, v is the velocity of the particle, B is the magnetic field strength in tesla [T], and r is the deflection radius of the particle’s path.

While running some tests, you have encountered a serious problem – the mass spectrometer is not maintaining constant V or B during your trials! Every time a particle is fired through the device, both the electric potential and the magnetic field fluctuate to a random value.

The supervising professor of the project has requested you model this experiment using a computer simulation program which you will create. This program will simulate multiple trials, where a single particle will be fired through the mass spectrometer. Each trial will simulate a new particle with unique mass and charge values, compute its path velocity after accelerated through the potential difference, and compute the radius of path deflection when travelling through the magnetic field for each trial. The program must also find the largest deflection radius of all the trials. Random values can be generated in C using the rand function. For more information on using this function, see the rand function example code below.

Write a program in C to performing the following tasks:

Prompt the user to enter the number of trials, n, that will be analyzed. Declare an n x 3 array to hold the mass, charge, and radius for each particle for n trials.

Create a loop to run through each trial, which will perform the following tasks: Use the randomize function (see below) to get the mass of the particle in the range [0.001, 1.08] kg. Use the randomize function (see below) to get the charge of the particle in the range [1.00, 9.00] C. Output both the mass and charge of the particle using the format shown in the sample output below. Get the particle velocity by calling the accelerate function. Get the deflection radius by calling the deflect function (see below) and storing it in the array. Call the checkPath function (see below). Write a function called randomize that will return a random float value between a min value and a max value, inclusive.

-Calls the randomize function to get a new potential voltage value in the range [0.013, 2.827] V.

-Computes the particle’s velocity using Equation 1, and outputs that value using the format shown in the sample output below.

-Returns the velocity value.Write a function called deflect that performs the following:

-Calls the randomize function to get a new magnetic field value in the range [0.058, 1.603] T.

-Computes the particle’s deflection radius using Equation 2, and outputs that value using the format shown in the sample output below.

-Returns the radius value.

-Finds the largest radius of all previous trials.

-Checks whether the current trial has a larger path radius than the previous maximum. If it does, output a message declaring this using the format shown in the sample output below.

-Your program will need to take user input for the number of trials. Read this input with the scanf function, using the format shown in bold in the sample output.

Comments are mandatory for this assignment. Add comments as necessary for important parts of your code, such as function calls & definitions, conditions, and calculations to explain what the program is doing.

-Your output must match the sample output below as closely as possible; otherwise, the autograding software will not be able to grade your assignment, which may affect your mark.

Enter number of trials: 3

Trial 1: 0.002 kg, 8.133 C

Accelerated to 117.069 m/s

Deflection radius of 0.040 m

New largest deflection radius!

Trial 2: 0.972 kg, 5.798 C

Accelerated to 3.866 m/s

Deflection radius of 0.500 m

New largest deflection radius!

Trial 3: 0.354 kg, 5.472 C

Accelerated to 3.896 m/s

Deflection radius of 0.181 m

Enter number of trials: 3

Trial 1: 0.757 kg, 7.477 C

Accelerated to 2.278 m/s

Deflection radius of 0.939 m

New largest deflection radius!

Trial 2: 0.377 kg, 4.376 C

Accelerated to 6.785 m/s

Deflection radius of 3.639 m

New largest deflection radius!

Trial 3: 0.635 kg, 6.144 C

Accelerated to 7.362 m/s

Deflection radius of 1.478 m

The rand function requires the stdlib.h library. Before the rand function can be used, the function must first be “seeded” using the srand function. This seeding causes the numbers to take on specific values during the running process, which makes your program easier to grade. Typically, the rand function produces an integer between 0 and RAND_MAX, a constant also included in the stdlib.h library. To make sure we can return a random float value in a specific range, we can use the formula shown below. min is the smallest possible value, and max is the largest possible value. Note the use of casting to make sure the random value is not an integer!