Chapter 4: Problem 10
How can a numerical array be made to behave as a logical mask for vector operations? How can the logical attribute be removed from a numeric array?
Chapter 4: Problem 10
How can a numerical array be made to behave as a logical mask for vector operations? How can the logical attribute be removed from a numeric array?
All the tools & learning materials you need for study success - in one app.
Get started for freeFibonacei Numbers. The nth Fibonacci number is defined by the following recursive equations: $$ \begin{aligned} &f(1)=1 \\ &f(2)=2 \\ &f(\mathrm{n})=f(\mathrm{n}-1)+f(\mathrm{n}-2) \end{aligned} $$ Therefore, \(f(3)=f(2)+f(1)=2+1=3\), and so forth for higher numbers, Write an M-file to calculate and write out the nth Fibonacci number for \(n>2\), where \(n\) is input by the user. Use a while loop to perform the calculation.
Program 1sgfit from Example \(4.7\) required the user to specify the number of input data points before entering the values. Modify the program so that it reads an arbitrary number of data values using a while loop and stops reading input values when the user presses the Enter key without typing any values. Test your program using the same two data sets that were used in Example 4,7. (Hint: The input function returns an empty array (1) if a user presses Enter without supplying any data. You can use function isempty to test for an empty array and stop reading data when one is detected.)
Write the MATLAB statements required to calculate \(y(t)\) from the equation $$ y(t)= \begin{cases}-3 t^{2}+5 & t \geq 0 \\ 3 t^{2}+5 & t<0\end{cases} $$ for values of \(t\) between \(-9\) and 9 in steps of \(0.5\). Use loops and branches to perform this calculation.
Geometric Mean. The geometric mean of a set of numbers \(x_{1}\) through \(x_{n}\) is defined as the \(n\)th root of the product of the numbers $$ \text { geometric mean }=\sqrt[4]{x_{1} x_{2} x_{3} \ldots x_{n}} $$ Write a MATLAB program that will accept an arbitrary number of positive input values and calculate both the arithmetic mean (i.e., the average) and the geometric mean of the numbers. Use a while loop to get the input values and terminate the inputs when a user enters a negative number. Test your program by calculating the average and geometric mean of the four numbers \(10,5,2\), and 5 .
Bacterial Growth. Suppose that a biologist performs an experiment in which he or she measures the rate at which a specific type of bacterium reproduces asexually in different culture media. The experiment shows that in Medium A the bacteria reproduce once every 60 minutes, and in Medium B the bacteria reproduce once every 90 minutes. Assume that a single bacterium is placed on each culture medium at the beginning of the experiment. Write a program that calculates and plots the number of bacteria present in cach culture at intervals of 3 hours from the beginning of the experiment antil 24 hours have elapsed. Make two plots, one a linear xy plot and the other a linear-log (semi logy) plot. How do the numbers of bacteria compare on the two media after 24 hours?
What do you think about this solution?
We value your feedback to improve our textbook solutions.