Computer Science 1060
Scientific Programming
Assignment 01 - Scalars, Operators, and Precedence


Contents:


Overview

Topic: Use of scalars and operator precedence
Related Reading: Ch. 1 as well as lecture notes

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

You are to submit a single m-file that outputs the resulting assignments for each of the following problems, in the given order. Please make sure that your name is given in comments at the beginning of the m-file and ensure that no output is generated by your scripts other than the resulting answers.

Submit your m-file to the email address dferry_submit@slu.edu, and bring a printed copy to class.

Problem A)
Calculate and display the variable

\begin{displaymath}\mbox{answerA} = \frac{28.5 \cdot 3^3 - \sqrt{1500}}{11^2 + 37.3} \end{displaymath}

Problem B)
Calculate and display the variable

\begin{displaymath}\mbox{answerB} = \left(\frac{7}{3}\right)^2 \cdot 4^3 \cdot 18 -
\frac{6^7}{\left(9^3 - 652\right)}\end{displaymath}

Problem C)
Set the variable $x = 9.75$ and then calculate and display

\begin{displaymath}\mbox{answerC} = 4x^3 - 14x^2 - 6.32x + 7.3\end{displaymath}

Problem D)
The number of ways of choosing $r$ objects out of a set of $n$ objects can be computed as

\begin{displaymath}\frac{n!}{r!(n-r)!}\end{displaymath}

where $n!$ can be computed as factorial(n) in MATLAB. Set the variables $n = 12; r = 5;$ and then compute and display

\begin{displaymath}\mbox{answerD} = \,\, \parbox{4in}{number of ways in which a ...
...oster of
12 players can choose the 5 players who start a game.}\end{displaymath}

Problem E)
An earthquake with magnitude $M$ on the Richter scale releases energy (in Joules) according to the formula,

\begin{displaymath}10^{\left(4.4 + \frac{3M}{2}\right)}\end{displaymath}

Calculate and display the variable

\begin{displaymath}\mbox{answerE} = \frac{\mbox{Energy released by a 7.1 magnitude quake}}{\mbox{Energy released by a 6.9 magnitude quake}}\end{displaymath}

Problem F)
The formula for annually compounding interest is


where P is equal to the principal (original investment), r is the rate of interest, and t is the time of investment in years. Assign the variables to represent a 25 year old college graduate making a $10,000 investment that grows at a rate of 8% over 40 years (until retirement at the age of 65). Consider also the assignment that represents the same individual waiting ten years to make the same investment. Then compute and display


Problem G)
The distance $d$ from a point $(x_0, y_0)$ to a line $Ax + By +
C = 0$ is given by

\begin{displaymath}d = \frac{\left\vert Ax_0 + By_0 + C\right\vert}{\sqrt{A^2 + B^2}}.\end{displaymath}

Set the variables $x0 = 3; y0 = -4; A = 2; B = -7; C = -10;$ and then calculate and display


\begin{displaymath}\mbox{answerG} = \,\, \mbox{Distance between point $(3,-4)$ and line
$2x - 7y - 10 = 0$.}\end{displaymath}

Note: you may use built-in functions sqrt and abs.


Originally by
Michael Goldwasser