Write a matlab function that solves a quadratic equation

Assignment Help Engineering Mathematics
Reference no: EM131372219

Part 1: Solving a quadratic equation

This exercise is similar to what you should have already completed for one of the exercises in Chapter 3 of the MATLAB course notes. Note however, that it is not exactly the same as the format of inputting and outputting values differs from the example in the notes.

Write a MATLAB function that solves a quadratic equation of the form

ax2 + bx + c = 0

The syntax of your function should take the form

>> [quadRoots] = Q1 STNO(coeff);

where STNO should be replaced by your student number.

The function should accept one input argument, coeff, a three element vector of the quadratic coefficients in the order a, b, c.

Your function should return one output argument, quadRoots. For the case where two roots are present, this should be a two-element vector of them. For the case where one root is present, the output should be a scalar of that value. For the case where no roots are present, the output should be a scalar set to NaN (not a number, see Section 1.3.3 of the course notes).

It is permissible for coeff and quadRoots to take the form of either row or column vectors.

Code format and error-free execution

Output when two roots are present

Output when one root is present

Output when no roots are present

Part 2: Factorials

The factorial of a positive integer is defined as:

n! = n × (n - 1) × (n - 2) × (n - 3) × . . . × 1

where n! = 1 when n = 0. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120.

The double factorial of a positive odd integer is defined as:

n!! = n × (n - 2) × (n - 4) × . . . × 1

where n!! = 1 when n = 0. For example, 9!! = 9 × 7 × 5 × 3 × 1 = 945.

Write a MATLAB function that computes both the factorial and double factorial for a positive odd integer.

The syntax of your function should take the form

>> [fact,DblFact] = Q2 STNO(n);

where n is the number your wish to find the factorials of, and fact and DblFact are the factorial and double factorial respectively.

Add a few error checks to the input to check that is sensible. (You might need to do a small amount of background research to find a way to verify the input is a odd integer).

Code format and error-free execution

Factorial

Double factorial

Error checking

Part 3: A vertically falling ball

The drag force D(t) as a function of time t acting on an object falling at velocity v(t) is given by

D(t) = cd1/2ρv(t)2 A

where cd is a dimensionless constant known as the drag coefficient that depends on the geometry of the object (use cd = 0.47 for a sphere), ρ is the density of air (use ρ = 1.2 kg/m3) and A is the cross-sectional area, which is circular for a ball.

The total force on a falling ball is thus the difference between drag and gravity:

F(t) = cd1/2ρv(t)2A - mg

where g is the acceleration due to gravity = 9.81 m/s2.

The acceleration a(t) is therefore (using Newton's Second Law):

a(t) = (cdρA/2m)v(t)2 - g      (1)

Note that all the terms here are constant except for a(t) and v(t).

Because the acceleration is not constant, we cannot use "suvat" equations but can ap- proximate velocities sequentially using:

vn = vn-1 + anδt       (2)

where vn and an approximate the velocity and acceleration at time tn (= nδt) respectively, and δt is the time step between values (see Annex 1 for derivation). Please use δt = 0.1s for this assignment.

Write a MATLAB function to calculate the time taken tThresh (in seconds) for a vertically falling ball of mass m (in kg) and diameter d (in m) to reach a velocity of vThresh in the presence of drag assuming the initial velocity is zero. Your function should also return the terminal velocity vTerm and the fraction of the terminal velocity reached at this time (e.g. if vTerm = 50 m/s and vThresh = 25 m/s, then the fraction is 0.5).

The syntax for your code should take the form

>> [tThresh,vTerm,vFrac] = Q3.STNO(m,d,vThresh)

where m and d are the mass and diameter of the ball respectively and vThresh is the velocity at the required time.

[Hint: You may download Q3 TEMPLATE.m to use as a starting point. Assume that the mass of the ball falls in the range 5 kg to 20 kg and that the diameter is in the range 5 cm to 50 cm.]

Error free execution

Calculated time

Terminal velocity

Fraction of terminal velocity

Part 4: Bouncing ball

N.B. This part of the assignment is designed to be challenging with very limited help available!

In an ultra-exciting physics experiment, some students plan to launch a bouncy ball from a toy cannon. Assuming that the ball is launched at velocity v (in m/s) and elevation angle θ (in radians measured from the horizontal ground to direction of cannon), write a MATLAB function that plots the trajectory of the ball for the first two bounces on a well-labelled graph. Unlike for Part 3, assume no drag.

Your code should take the form:

>> [d] = Q4 STNO(v,theta,c)

where d is a two-element vector indicating the distances of the first two points of contact with the ground from the cannon, v and theta are the launch velocity and angle as stated above, and c is defined below. An example output is shown in Figure 1 for clarity.

1911_figure.jpg

Figure 1: Sample result. In this case, d would be approximately [10.2 17.8].

Assumptions:

- No drag/wind.

- The ball is launched from the ground.

- The ground is perfectly flat and level with no obstacles.

- There is no spin on the ball and no friction between the ball and the surface: hence no change in horizontal velocity after each bounce.

- Vertical velocity changes by a multiplicative factor of -c at the instant of each bounce.

Distance to bounces

Graph (trajectory)

Graph (style, clarity, labelling)

For a final challenge, add two additional inputs to specify the distance from the origin and the height of a thin wall. Your function should then plot the new trajectory including a rebound from the wall. Assume that the bounce between the ball and wall does not affect the magnitude of the velocity (unlike the bounce with the ground).

If you attempt this final part then please submit two functions for Part 4: one without this final calculation as previously ([d] = Q4 STNO(v,theta,c)) and one of the form:

>> [d] = Q4e STNO(v,theta,c,D,H)

where D and H refer to the distance and height of the wall respectively. You should plot the wall on the graph using the MATLAB line function (type help line into the MATLAB command window for more details).

Reference no: EM131372219

Questions Cloud

Design a four-dwell cam to move a follower of mass : Calculate and plot the dynamic force and torque. Assume damping of 0.18 times critical. Repeat for a form-closed cam. Compare the dynamic force, torque, and natural frequency for the form-closed design and the force-closed design.
Iatrogenic and nosocomial diseases to be medical errors : 1. Would you consider iatrogenic and nosocomial diseases to be medical errors? 2. Write one paragraph indicating how biology, anatomy, physiology, and chemistry relate to pathophysiology.
What should be initial bargaining position of school board : The annual contract negotiations between the Pleasant Ridge Board of Education and the Pleasant Ridge Classroom Teachers Association (PRCTA) are due to begin July 1, one week from now. What should be the initial bargaining position of the school boar..
How many degrees of freedom are associated with the ssd : If you are told that the deviations are to be taken with respect to 50, what is the SSD? How many degrees of freedom are associated with this SSD? Calculate MSD.
Write a matlab function that solves a quadratic equation : Write a MATLAB function that computes both the factorial and double factorial for a positive odd integer - Write a MATLAB function that solves a quadratic equation.
Dealing with medical professionals : Prevailing wisdom reinforces the fact that working in U.S. health care administration in the 21st Century requires knowledge of the various aspects of health laws as they apply to dealing with medical professionals.
Find the undamped and damped natural frequencies : Find the undamped and damped natural frequencies and the value of critical damping for the system(s) assigned.
Figure out the amounts of the two missing checks : Your bank sends you a summary statement, giving the average amount of all checks you wrote during the month.- Using this and the information provided by the bank, can you figure out the amounts of the two missing checks?
Which part of the procurement life cycle process is critical : In your opinion, which part of the procurement life cycle process is most critical to the success of the contract? Explain your rationale.

Reviews

len1372219

1/27/2017 12:10:48 AM

Q You have tested your code on a range of input parameters and, where possible, verified your answers with pen and paper or a calculator. This may not always be possible, but at least check that your function outputs are sensible – if your code returns a velocity of one billion m/s then something is probably wrong! Q MATLAB is case-sensitive. Make sure you are consistent with which case you use. For example, if you define velocity in the x-direction as vx initially, and then start using Vx, you will most likely get an error. Q After submission to Blackboard, you have re-downloaded all your files to verify that the correct versions are uploaded and are not corrupted.

len1372219

1/27/2017 12:10:38 AM

Q Functions work correctly when called from the command window. In Part 1 for example, the code will be marked by typing something similar to “roots = Q1 01234567([1 2 -3])” into the command window (as opposed to pressing F5 or the “run” button from the MATLAB editor). Q Submitted codes are function files requiring inputs and outputs (as opposed to script files – see Section 3.2 of the course notes). Q P-code files will not be marked. All submissions should have a .m extension. Q Each function is entirely self-contained – i.e. does not require any non-built-in func- tions to work correctly.

len1372219

1/27/2017 12:10:28 AM

If necessary, refer to the Blackboard help page of the UWE website for generic Blackboard submission instructions1 and verify that your upload was successful by downloading an electronic receipt2. It is recommended that you download and re-open your submitted files to make sure the correct versions are uploaded. General assessment guidelines can also be found online3. This includes information on assessment offences. All submitted functions will be tested against undisclosed input parameters. There may be slight discrepancies between any two correct answers due to rounding errors (for example) but full marks will be awarded where answers are within a reasonable tolerance of the exact values and a sound methodology is adopted.

len1372219

1/27/2017 12:09:56 AM

You are required to complete the following tasks for the Engineering Mathematics MAT- LAB assignment. The assignment is divided into four parts, each worth 25 marks. Please submit code for any part that you have attempted, even if you are unable to complete the entire assignment. Completed MATLAB functions should be submitted via Blackboard before the deadline of 14:00. For each of the four parts, you should prepare a .m file in the given format. Please ensure that your functions exactly follow the format given in the questions (remember, in particular, that MATLAB is case sensitive). Furthermore, each function must be entirely self-contained, i.e. it should not call other functions apart from built-in ones. You can submit your solutions at any time leading up to the deadline. If you resubmit your work, then any earlier versions will be overwritten, but note that all files must be resubmitted if you do this (i.e. not just the files that you have changed since the last attempt). It is recommended that you familiarise yourself with the submission procedure well before the submission date to make sure you understand the system.

Write a Review

Engineering Mathematics Questions & Answers

  Additive noise channel with the ternary valued noise

Problem: A Bernoulli( 2/1 ) distributed signal X is transmitted over an additive noise channel with the ternary valued noise W:

  Test the claim against the alternative

A manufacturer claims that in a process of producing drill bits, only 2.5% of the bits are dull. Test the claim against the alternative that more than 2.5% of the bits are dull, using a sample of 400 bits containing 17 dull ones. Use a = 5%.

  Problem of grafting an artery

A surgeon is faced with the problem of grafting an artery. She wishes to minimize the resistance to the resulting flow.

  Find an equation for the speed of the liquid

Find an equation for the speed of the liquid as a function of the distance y it has fallen. Combining this with the equation of continuity, find an expression for the radius of the stream as a function of y.

  Determine the characteristics and the corresponding odes

Consider the hyperbolic system ut + uv= = u√v, and u, v > 0. Determine the characteristics and the corresponding ODEs

  Dual prices and the range of feasibility

Explain the connection between reduced costs and the range of optimality, and between dual prices and the range of feasibility.

  Piece of unpainted porous wood

A piece of unpainted porous wood barely floats in a container partly filled with water. If the container is sealed and pressurized above atmospheric pressure, does the wood rise, fall, or remain at the same level?

  Asuming that both mobile and galveston have infinite

a sunco oil produces oil at two wells. well 1 can produce as many as 150000 barrels per day and well 2 can produce as

  How realistic is alternative power source for your community

How realistic is this alternative power source for your community? How will people in your community respond to energy conversion? Will they support it or be against it? Give reasons.

  Derive newtons method for finding the zeros

Derive Newtons method for finding the zeros of a twice continuously differentiable function - find a Lipschitz constant for some interval containing and solve the ODE and compare your estimated interval of existence to the actual one.

  Find the curve connecting two points

Find the curve connecting two points A(0,0) and B(2,0) such that the length of the line is a minimum and the area under the curve is π/2.

  Improper integral to evaluate the integral

Problem 1: Use the definition of an improper integral to evaluate the integral below:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd