Engineering
Python 3Sum Positive FloatsWrite a program that reads in an arbitrary number of floating point values and then prints the sum of all the positive values entered, rounded to three decimal places. The value 0 will indicate the end of input. Note that negative input values should not be added to the sum.Input Format For Custom TestingEach line of input will contain a floating point value, and the last line of input will contain the number 0.Sample Case 1Sample Input For Custom Testing3.52-17.92350Sample Output33.500Sample Case 2Sample Input For Custom Testing0-----------------------------------------------------------------------------------Collatz ConjectureThe Collatz Conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. Then, each term in the sequence is obtained from the previous term as follows: if the previous term is even, the next term is one-half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what the value of n is, the sequence will always reach 1. For example, the Collatz sequence starting from 3 is 3, 10, 5, 16, 8, 4, 2, 1 and it has a length of 8, since there are 8 terms in the sequence. Write a program that reads in the value of n and prints out how many terms are in the Collatz sequence starting with n.Input Format For Custom TestingThe only line of input contains the positive integer n.Sample Case 1Sample Input For Custom Testing3Sample Output8Sample Case 2Sample Input For Custom Testing1Sample Output1Sample Case 3Sample Input For Custom Testing6Sample Output9Sample Output0.000Sample Case 3Sample Input For Custom Testing3.14159-20-420-0.0040Sample Output3.142
Recall that Problem 2.19 in Chapter 2 presented a nonlinear model of "stick-slip" friction for mechanical systems. This problem will demonstrate how the dynamic response of a simple mechanical system is affected by the choice of the friction force model. The mathematical model of a simple 1-DOF mechanical system is where m is the mass, Fr is the friction force, k is the stiffness (spring) coefficient, is the displacement of mass m from static equilibrium (in m), and Fa() is the applied force. Obtain the dynamic responses using Simulink for the two friction models: 1) Linear viscous friction: Ff -bi 2) Nonlinear stick-slip friction: Ff-UG + (Fst-Fc) exp(-/c)] sgn(x) + bt The system parameters are m-2kg, k800 N/m, b 25 N-s/m, Fst1.2N (stiction force), Fc IN (Coulomb friction force), c = 0.002 m/s (velocity coefficient). The external force Fa(t) is a 15-N step func- tion applied at time t = 0.2 s. The mass is initially at rest in static equilibrium. Plot the dynamic responses ( obtained using both friction models on the same plot. In addition, plot the friction force F) from both simulations on the same plot. Let the total simulation time be 1.8 s and use the fixed-step, fourth-order Runge-Kutta solver (ode4) with a step size of 0.001 s. On the basis of your simulation results describe the differences between the responses with the two friction models.