You are on page 1of 3

# Computer Programing Practices Questions 1.

Write a MATLAB Add all the terms in the series, 1 

1 1 1    .......... .......... ..........until the 2 4 8

sum exceeds 1.995. Print out the sum and the number of terms needed to just exceed the sum of 1.995. 2. The Fibonacci sequence is given as, 1 1 2 3 5 8 13 21 34 ………………………….. Write a MATLAB program to generate the Fibonacci sequence up to the twelfth term. 3. Use MATLAB to find V1 , V2 and V3 in the following circuit.

4. Figure below shows a cylindrical tank with a conical base. If the liquid level is quite low, in the conical part, the volume is simply the conical volume of liquid. If the liquid level is midrange in the cylindrical part, the total volume of liquid includes the filled conical part and the partially filled cylindrical part. Use decisional structures to write an M-file to compute the tank’s volume as a function of given values of Rand d. Design the function so that it returns the volume for all cases

Where the depth is less than 3R, Return an error message (“Overtop”) if you overtop the tank—that is, d>3R. Test it with the following data. R 0.9 1.5 1.3 1.3 d 1 1.25 3.8 4.0 MRU Department of Engineering Page 1

6. Develop a function to produce an animation of a particle moving in a circle in Cartesian coordinates based on radial coordinates. 7. and allow the angle ( θ ) to increase from zero to 2 in equal increments. develop a script that uses this function to generate a plot of v versus t for t=−5 to 50. Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequately represented by a single equation.000. The output should consist of a table with headings and columns for n and F. the interest rate i(as a decimal). The input to the function should include the initial investment P. Run the program for P=\$100. 45 and 120.9999. the velocity of a rocket might be described by Develop an M-file function to compute vas a function of t. Test your function with 89. i=0. and n=10 years. and the number of years n for which the future worth is to be calculated. The future worth F yielded at an interest rate i after n periods may be determined from the following formula: F  P(1  i) n Write an M-file that will calculate the future worth of an investment for each year from 1 through n. Assume a constant radius. r. For example. 90. Develop an M-file function that is passed a numeric grade from 0 to 100 and returns a letter grade according to the scheme: Design the function so that it displays an error message and terminates in the event that the user enters a value of score that is less than zero or greater than 100. 8.05. MRU Department of Engineering Page 2 .Note that the tank’s radius is R 5. Then. An amount of money P is invested in an account where interest is compounded at the end of the period.

n=roughness coefficient. Include headings on the table to label the columns.9. and H=depth (m). Enter these values into a matrix where each column represents a parameter and each row represents a channel. Manning’s equation can be used to compute the velocity of water in a rectangular open channel: Where U=velocity (m/s). S=channel slope. MRU Department of Engineering Page 3 . Have the M-file display the input data along with the computed velocity in tabular form where velocity is the fifth column. B=width (m). The following data are available for five channels: Write an M-file that computes the velocity for each of these channels.