PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102Jekyll2019-08-22T13:31:22-05:00http:/MAPCP2019U/Amir Shahmoradihttp:/MAPCP2019U/shahmoradi@utexas.edu<![CDATA[Quiz 4: Converting Comma-Separated-Values (CSV) input to formatted output]]>http:/MAPCP2019U/quiz/4-io2019-08-08T00:00:00-05:002019-08-08T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>Don’t forget to push your answers to your remote repository by the end of quiz time. Push all your answers to <strong>quiz/4/</strong> folder in your Github project.</p>
<hr />
<hr />
<p><br /></p>
<p>Consider this comma-separated data file: <a href="4/data.in" target="_blank">data.in</a>. Write a simple script named <code>csv2formatted</code> that takes two input arguments representing the input and output file names. Then, the script writes the same input float data to the output file <code>data.out</code> <strong>in a formatted style</strong>, like this example output file: <a href="4/data.out" target="_blank">example output file</a>. Note that every numer in the output file has only three significant digits after the decimal point.</p>
<p>Write your Python script in such a way that it takes the input and output file names from the Bash command line arguments, like the following,</p>
<pre><code class="language-bash">python csv2formatted.py data.in dataPython.out
</code></pre>
<p>Write your MATLAB script as a function that takes the input and output file names as input arguments to a function named <code>csv2formatted</code>, so that it can be called like the following from the MATLAB command line.</p>
<pre><code class="language-matlab">csv2formatted('data.in','dataMATLAB.out')
</code></pre>
<p><a href="http:/MAPCP2019U/quiz/4-io">Quiz 4: Converting Comma-Separated-Values (CSV) input to formatted output</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on August 08, 2019.</p><![CDATA[Quiz 3: Branching, loops, functions]]>http:/MAPCP2019U/quiz/3-branching-loops-functions2019-07-23T00:00:00-05:002019-07-23T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<!--
This is the solution to [Quiz 1: Problems - Version control system](1-problems-version-control-system.html){:target="_blank"}.
The following figure illustrates the grade distribution for this quiz.
<figure>
<img src="http:/MAPCP2019U/quiz/gradeDist/gradeHistQuiz1.png" width="700">
<figcaption style="text-align:center">
Maximum possible points is 1.
</figcaption>
</figure>
-->
<p>Don’t forget to push your answers to your remote repository by the end of quiz time. Push all your answers to <strong>quiz/3/</strong> folder in your Github project.</p>
<hr />
<hr />
<p><br /></p>
<p><strong>1. </strong> A Geometric Series is defined by the following mathematical sequence,</p>
<script type="math/tex; mode=display">1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \ldots = \sum^{\infty}_{n=0} \frac{1}{2^n} ~,</script>
<p>A finite version of this sequence can be defined as the following,</p>
<script type="math/tex; mode=display">1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \ldots + \frac{1}{2^m} = \sum^{m}_{n=0} \frac{1}{2^n} ~,</script>
<p>a) Write a recursive function that takes an input integer <code>m</code> and computes the finite Geometric sum as defined above.</p>
<p>b) Write a non-recursive function, using loops, that takes an input integer <code>m</code> and computes the finite Geometric sum as defined above.</p>
<p>c) Write a third script, for example, named <code>benchmark</code>, that measures the speed of the above two function implementations for some input test value of <code>m</code>, and displays a message like the following,</p>
<pre><code>Recursive implementation is 0.76 as fast as the loop-based implementation of the function.
</code></pre>
<p><a href="http:/MAPCP2019U/quiz/3-branching-loops-functions">Quiz 3: Branching, loops, functions</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on July 23, 2019.</p><![CDATA[Homework 4: Exceptions, Errors, Vectorization, Visualization]]>http:/MAPCP2019U/homework/4-exceptions-errors-vectorization-visualization2019-07-23T00:00:00-05:002019-07-23T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>♣ <strong>Due Date: Two weeks from the posting date @ 10:30 AM</strong>. This homework aims at giving you some experience with data transfer, exceptions and errors, vectorization, and visualization methods in Python and MATLAB. Write your scripts with the corresponding <code>*.py</code> or <code>*.m</code> file names, and add a readme.md file in HW 4 folder of your project if you need to add any additional explanation (Don’t forget to use markdown syntax highlight in your readme file, if needed).</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>1. Python.</strong> Write a simple program named <code>sum.py</code>, that takes in an arbitrary-size list of input floats from the command-line, and prints out the sum of them on the terminal with the following message,</p>
<pre><code class="language-bash">$ python sum.py 1 2 1 23
The sum of 1 2 1 23 is 27.0
</code></pre>
<p>Note that you will need to use the Python’s builtin function <code>sum()</code>.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>2. Python.</strong> Similar to the previous problem, write a simple program named <code>sum_via_eval.py</code>, that takes in an arbitrary-size list of input numbers from the command-line, and prints out the sum of them on the terminal, this time using Python’s <code>eval</code> function. The program output should look like the following,</p>
<pre><code class="language-bash">$ python sum.py 1 2 1 23
The sum of 1 2 1 23 is 27
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>3. Python.</strong> Consider <a href="http:/MAPCP2019U/homework/4-problems/1A2T_A.dssp" target="_blank">this data file</a>. It contains information about the amino-acids in <a href="http://www.rcsb.org/pdb/explore.do?structureId=1a2t" target="_blank">a protein</a> called <code>1A2T</code>. Each amino-acid in protein is labeled by a single letter. There are 20 amino-acid molecules in nature, and each has a total surface area (in units of Angstroms squared) that is given by the following table,</p>
<pre><code>'A': 129.0
'R': 274.0
'N': 195.0
'D': 193.0
'C': 167.0
'Q': 225.0
'E': 223.0
'G': 104.0
'H': 224.0
'I': 197.0
'L': 201.0
'K': 236.0
'M': 224.0
'F': 240.0
'P': 159.0
'S': 155.0
'T': 172.0
'W': 285.0
'Y': 263.0
'V': 174.0
</code></pre>
<p>However, when these amino acids sit next to each other to form a chain protein, they cover parts of each other, such that only parts of their surfaces is exposed, while the rest is hidden from the outside world by other neighboring amino acids. Therefore, one would expect an amino acid that is at the core of a spherical protein would have almost zero exposed surface area.</p>
<p>Now given the above information, write a Python program that takes in two command-line input arguments, one of which is a string containing the path to the above <a href="http:/MAPCP2019U/homework/4-problems/1A2T_A.dssp" target="_blank">input file</a> <code>1A2T_A.dssp</code> which contains the partially exposed surface areas of amino acids in protein <code>1A2T</code> for each of its amino acids, and a second command-line argument which is the path to the file containing output of the code (e.g., it could be <code>./readDSSP.out</code>). Then,</p>
<ol>
<li>the code reads the content of this file, and<br />
<br /></li>
<li>extracts the names of the amino acids in this protein from the data column inside the file which has the header <code>AA</code> (look at the line number 25 inside the input data file, below <code>AA</code> is the column containing the one-letter names of amino acids in this protein), and<br />
<br /></li>
<li>also extracts the partially exposed surface area information for each of these amino acids which appear in the column with header <code>ACC</code>, and<br />
<br /></li>
<li>then uses the above table of maximum surface area values to calculate the fractional exposed surface area of each amino acid in this protein (i.e., for each amino acid, fraction_of_exposed_surface = ACC / maximum_surface_area_from_table), and<br />
<br /></li>
<li>finally for each amino acid in this protein, it prints the one-letter name of the amino acid, its corresponding partially exposed surface area (ACC from the input file), and its corresponding fractional exposed surface area (name it RSA) to the output file given by the user on the command line.<br />
<br /></li>
<li>On the first column of the output file, the code should also write the name of the protein (which is basically the name of the input file <code>1A2T_A</code>) on each line of the output file. <strong>Note that your code should extract the protein name from the input filename</strong> (by removing the file extension and other unnecessary information from the input command line string). <a href="http:/MAPCP2019U/homework/4-problems/readDSSP.out" target="_blank">Here</a> is an example output of the code.<br />
<br /></li>
<li>Your code should also be able to handle an error resulting from less or more than 2 input command line arguments. That is, if the number of input arguments is 3 or 1, then it should input the following message on screen and stop.</li>
</ol>
<pre><code class="language-bash">$ ./readDSSP.py ./1A2T_A.dssp
Usage:
./readDSSP.py <input dssp file> <output summary file>
Program aborted.
</code></pre>
<p>or,</p>
<pre><code class="language-bash">$ ./readDSSP.py ./1A2T_A.dssp ./readDSSP.out amir
Usage:
./readDSSP.py <input dssp file> <output summary file>
Program aborted.
</code></pre>
<p>To achieve the above goal, you will have to create a dictionary from the above table, with amino acid names as the keys, and the maximum surface areas as the corresponding values. Name your code <code>readDSSP.py</code> and submit it to your repository.</p>
<p><strong>Write your code in such a way that it checks for the existence of the output file</strong>. If it already exists, then it does not remove the content of the file, whereas, it appends new data to the existing file. therwise, if the file does not exist, then it creates a new output file as requested by the user. To do so, you will need to use <code>os.path.isfile</code> function from module <code>os</code>.</p>
<p><strong>ATTENTION</strong>: Note that in some rows instead of a one-letter amino acid name, there is <code>!</code>. In such cases, your code should be able to detect the abnormality and skip that row, because that row does not contain amino acid information.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>4. MATLAB.</strong> Solve the same problem as in 3, except that you don’t need to read the arguments (i.e., filenames) from the command line. Instead, implement your script as a MATLAB function.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>5. Python.</strong> Consider the simplest program for evaluating the formula $y(t) = v_0t-\frac{1}{2}gt^2$,</p>
<pre><code class="language-python">v0 = 3; g = 9.81; t = 0.6
y = v0*t - 0.5*g*t**2
print(y)
</code></pre>
<p>(A) Write a program that takes in the above necessary input data ($t$,$v_0$) as command line arguments.<br />
<br />
(B) Extend your program from part (A) with exception handling such that missing command-line arguments are detected. For example, if the user has entered enough input arguments, then the code should raise <code>IndexError</code> exception. In the <code>except IndexError</code> block, the code should use the <code>input</code> function to ask the user for the missing input data.<br />
<br />
(C) Add another exception handling block that tests if the $t$ value read from the command line, lies between $0$ and $2v_0/g$. If not, then it raises a <code>ValueError</code> exception in the if block on the legal values of $t$, and notifes the user about the legal interval for $t$ in the exception message.</p>
<p>Here are some example runs of the code,</p>
<pre><code class="language-bash">$ ./projectile.py
Both v0 and t must be supplied on the command line
v0 = ?
5
t = ?
4
Traceback (most recent call last):
File "./projectile.py", line 17, in <module>
'must be between 0 and 2v0/g = {}'.format(t,2.0*v0/g))
ValueError: t = 4.0 is a non-physical value.
must be between 0 and 2v0/g = 1.019367991845056
</code></pre>
<pre><code class="language-bash">$ ./projectile.py
Both v0 and t must be supplied on the command line
v0 = ?
5
t = ?
0.5
y = 1.27375
</code></pre>
<pre><code class="language-bash">$ ./projectile.py 5 0.4
y = 1.2151999999999998
</code></pre>
<pre><code class="language-bash">$ ./projectile.py 5 0.4 3
y = 1.2151999999999998
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>6. Python.</strong> Consider the function <code>Newton</code>,</p>
<pre><code class="language-python">def Newton(f, dfdx, x, eps=1E-7, maxit=100):
if not callable(f): raise TypeError( 'f is %s, should be function or class with __call__' % type(f) )
if not callable(dfdx): raise TypeError( 'dfdx is %s, should be function or class with __call__' % type(dfdx) )
if not isinstance(maxit, int): raise TypeError( 'maxit is %s, must be int' % type(maxit) )
if maxit <= 0: raise ValueError( 'maxit=%d <= 0, must be > 0' % maxit )
n = 0 # iteration counter
while abs(f(x)) > eps and n < maxit:
try:
x = x - f(x)/float(dfdx(x))
except ZeroDivisionError:
raise ZeroDivisionError( 'dfdx(%g)=%g - cannot divide by zero' % (x, dfdx(x)) )
n += 1
return x, f(x), n
</code></pre>
<p>This function is supposed to be able to handle exceptions such as divergent iterations, and division-by-zero. The latter error happens when <code>dfdx(x)=0</code> in the above code. Write a test code that ensures the above code is able to correctly identify a division-by-zero exception and raise the correct assertionError. <br />
(<em>Hint: To do so, you need to consider a test mathematical function as input to <code>Newton</code>. One example could be $f(x)=\cos(x)$ with a starting search value $x=0$. This would result in derivative value $f’(x=0)=-\sin(x=0)=0$, which should lead to a <code>ZeroDivisionError</code> exception. Now, write a test function <code>test_Newton_div_by_zero</code> that can explicitly handle this exception by introducing a boolean variable <code>success</code> that is <code>True</code> if the exception is raised and otherwise <code>False</code></em>.)</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>7. </strong> <strong>Reading scientific data from web using Python/MATLAB</strong>. Consider the following webpage address <a href="https://www.cdslab.org/ICP2017F/homework/5-problems/swift/bat_time_table.html" target="_blank">https://www.cdslab.org/ICP2017F/homework/5-problems/swift/bat_time_table.html</a>. This is an data table (in HTML language) containing data from <a href="https://www.nasa.gov/mission_pages/swift/main" target="_blank">NASA’s Swift satellite</a>. Each row in this table represents information about a <a href="https://en.wikipedia.org/wiki/Gamma-ray_burst" target="_blank">Gamma-Ray Burst (GRB)</a> detection that Swift has made in the past years. Now, corresponding to each of event IDs, there (might) exist files that contain some attributes of these events which we wish to plot and understand their behavior. For example, for the first event in this table, contains a data file which is hidden in a directory on this website <a href="https://www.cdslab.org/ICP2017F/homework/5-problems/swift/GRB00745966_ep_flu.txt" target="_blank">here</a>. For each event in this table, there is likely one such table hidden in this web directory.</p>
<p>Our goal in this question is to fetch all these files from the website and save them locally in our own computer. Then read their contents one by one and plot the two columns of data in all of them together.</p>
<p><strong>(A)</strong> Write a script named <code>fetchDataFromWeb.*</code> (with the star <code>*</code> indicating the arbitrary choice of your own language) that uses this web address: <a href="https://www.cdslab.org/ICP2017F/homework/5-problems/triggers.txt" target="_blank">https://www.cdslab.org/ICP2017F/homework/5-problems/triggers.txt</a> to read a list of all GRB events and then writes the entire table of <code>triggers.txt</code> to a local file with the same name on your device. For this purpose, you will need some built-in or library functionality to read the contents of a web page, such as <code>webread()</code> in MATLAB or the package <code>urllib.request</code> in Python (or some other libraries).</p>
<p><strong>(B)</strong> Now, add to your script another set of commands that uses the event IDs stored in this file, to generate the corresponding web addresses like: <a href="https://www.cdslab.org/ICP2017F/homework/5-problems/swift/GRB00745966_ep_flu.txt" target="_blank">https://www.cdslab.org/ICP2017F/homework/5-problems/swift/GRB00745966_ep_flu.txt</a>. Then it uses the generated web address to read the content of the page and store it in a local file on your device with the same name as it is stored on the webpage (for example, for the given webpage, the filename would be <code>GRB00745966_ep_flu.txt</code>). <strong>Note:</strong> Some of the web addresses for the given event IDs do not exist. Therefore, you should use an exception-handling construct such as MATLAB’s <code>try-catch</code> or Python’s <code>try-except</code> construct to avoid runtime errors in your code.</p>
<p><strong>(C)</strong> Now write another script named <code>plotDatafromFile.m</code>, that reads all of these files in your directory, one by one, and plots the content of all of them together, on a single scatter plot like the following,</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/SwiftDataPlot.png" />
</figure>
<p><strong>Note</strong> again that some the data files stored on your computer are empty and some others have useless data if data in the second column of the file is larger than 0. So you will have to write your script in such a way that it checks for non-emptiness of the file (that is, the file does indeed contain some numerical data) as well as the negativity of the values in the column of data in each file. For example, you could check for the negativity of the values in MATLAB using function <code>all(data[:,1]<0.0)</code> assuming that data is the variable containing the information read from the file.</p>
<p>Once you have done all these checks, you have to do one final manipulation of data, that is, the data in these files on the second column is actually the log of data, so have to get the <code>exp()</code> value to plot it (because the plot in the figure above is a log-log plot and we want to exactly regenerate it). To do so in MATLAB, for example, you could simply use the following,</p>
<pre><code class="language-matlab">data[:,2] = exp(data[:,2]);
</code></pre>
<p><br />
as soon as you read from the file, and then finally you make a scatter plot of all data using MATLAB scatter plot. At the end, you will have to set a title for your plot as well and label the axes of the plot, and save your plot using MATLAB’s built-in function <code>saveas()</code>. In order to find out how many files you have plotted in the figure, you will have to define a variable counter which increases by one unit, each time a new non-empty negative-second-column data file is read and plotted.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>8. </strong> <strong>Simulating a fun Monte Carlo game.</strong> Suppose you’re on a game show, and you’re given the choice of three doors:</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/Monty_1.png" />
</figure>
<p><br /></p>
<p>Behind one door is a car; behind the two others, goats. You pick a door, say No. 1, and the host of the show opens another door, say No. 3, which has a goat.</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/Monty_open_door.png" />
</figure>
<p><br /></p>
<p>He then says to you, “Do you want to pick door No. 2?”.</p>
<p><strong>Question: What would you do?</strong> Is it to your advantage to switch your choice from door 1 to door 2? Is it to your advantage, <strong>in the long run, for a large number of game tries</strong>, to switch to the other door?</p>
<p>Now whatever your answer is, I want you to check/prove your answer by a Monte Carlo simulation of this problem. Make a plot of your simulation for <code>nExperiments=100000</code> repeat of this game, that shows, in the long run, on average, what is the probability of winning this game if you switch your choice, and what is the probability of winning, if you do not switch to the other door.</p>
<p><strong>Hint:</strong> I strongly urge you to attend the lectures this week in order to get help for this question.</p>
<p><br /></p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>9. </strong> <strong>Monte Carlo approximation of the number $\pi$</strong>. Suppose we did not know the value of $\pi$ and we wanted to estimate its value using Monte Carlo methods. One practical approach is to draw a square of unit side, with its diagonal opposite corners extending from the coordinates origin $(0,0)$ to $(1,1)$. Now we try to simulate uniform random points from inside of this square by generating uniform random points along the $X$ and $Y$ axes, i.e., by generating two random uniform numbers (x,y) from the range $[0,1]$.</p>
<p>Now the generated random point $P$ has the coordinate $(x,y)$, so we can calculate its distance from the coordinate origin. Now suppose we also draw a quarter-circle inside of this square whose radius is unit and is centered at the origin $(0,0)$. The ratio of the area of this quarter-circle, $S_C$ to the area of the area of the square enclosing it, $S_S$ is,</p>
<script type="math/tex; mode=display">\frac{S_C}{S_S} = \frac{\frac{1}{4}\pi r^2}{r^2} = \frac{1}{4}\pi</script>
<p>This is because the area of the square of unit sides, is just 1. Therefore, if we can somehow measure the area of the quarter $S_C$, then we can use the following equation, to get an estimate of $\pi$,</p>
<script type="math/tex; mode=display">\pi = 4S_C</script>
<p>In order to obtain, $S_C$, we are going to throw random points in the square, just as described above, and then find the fraction of points, $f=n_C/n_{\rm total}$, that fall inside this quarter-circle. This fraction is related to the area of the circle and square by the following equation,</p>
<script type="math/tex; mode=display">f=\frac{n_C}{n_{\rm total}} = \frac{S_C}{S_S}</script>
<p>Therefore, one can obtain an estimate of $\pi$ using this fraction,</p>
<script type="math/tex; mode=display">\pi \approx 4\frac{n_C}{n_{\rm total}}</script>
<p>Now, write a MATLAB script, that takes in the number of points to be simulated, and then calculates an approximate value for $\pi$ based on the Monte Carlo algorithm described above. Write a second function that plot the estimate of $\pi$ versus the number of points simulated, like the following,</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-solutions/approximatePI.png" />
</figure>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>10. </strong> <strong>Subplots in MATLAB.</strong> Consider this MATLAB data file <a href="http:/MAPCP2019U/homework/4-problems/data3D.mat" target="_blank">data3D.mat</a> which contains a 3-dimensional $41\times 61\times 16$ matrix of the brain of a rat. Write a MATLAB script that creates and saves a graph of all $X-Y$ information for the 16 slices along the z axis like the following.</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/subplots.png" width="900" />
</figure>
<p><br /></p>
<p><strong>Hint:</strong> Start from this <a href="http:/MAPCP2019U/homework/4-problems/hw6prob1.m" target="_blank">MATLAB script</a> that I have written for you. Play with all the options to understand what they do and see their effects on the resulting plot. This script should generate the following figure for you.</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/currentPlot.png" width="900" />
</figure>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>11. MATLAB.</strong> <strong>Getting the boundary of objects in images.</strong>. Consider the same dataset as in the previous problem. Write a MATLAB script that delineates the boundary of the tumor in all of the subplots and generates a figure with the tumor boundary highlighted, like the following graph.</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/subplotsWithTumorBoundaries.png" width="900" />
</figure>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>12. MATLAB.</strong> <strong>Regression: obtaining the most likely mean and standard deviation of a set of Standard Normally Distributed Random Variables.</strong> Consider this dataset, <a href="http:/MAPCP2019U/homework/4-problems/Drand.mat" target="_blank">Drand.mat</a>, which contains a set of random numbers. Let’s make a hypothesis with regards to this dataset: We assume that this dataset is well fit by a <a href="https://en.wikipedia.org/wiki/Normal_distribution" target="_blank">Gaussian distribution</a>. But, we don’t know the values of the two parameters (mean and standard deviation) of this Normal (Gaussian) distribution. Therefore, write a MATLAB script that constructs an objective function (similar to what we are planning to do for the mathematical modeling section of the project) and then uses MATLAB’s built-in function, <code>fminsearch()</code>, to find the most likely values of the mean and standard deviation of this Gaussian distribution. Here is a best-fit Gaussian distribution using the most likely parameters to the histogram of this dataset.</p>
<figure>
<img src="http:/MAPCP2019U/homework/4-problems/histfit.png" width="700" />
</figure>
<p><strong>Hints:</strong> Our hypothesis is that the data in this histogram comes from a standard Normal distribution with a fixed mean ($\mu$) and standard deviation ($\sigma$). For the moment, let’s assume that we know the values of these two parameters. Then if all of these points, $D$, come from the normal distribution with the given $(\mu,\sigma)$, then the probability of all them coming from the normal distribution with these parameter values can be computed as,</p>
<script type="math/tex; mode=display">\pi\big(\boldsymbol D\big|\mu,\sigma\big) = \prod^{N=100}_{i=1} \frac{1}{2\pi\sigma^2}\exp\bigg( -\bigg[ \frac{\boldsymbol D(i)-\mu}{\sqrt{2}\sigma} \bigg]^2 \bigg) ~~,</script>
<p>where the symbol $\pi$ to the left of equality means <strong>probability</strong> (but note that $\pi$ on the right hand side of the euqation stands for the number $\pi=3.14\ldots$, and $D(i)$ refers to the $i$th point in the sample of points. Since probabilities are always extremely small numbers, it is always good to work with their <code>log()</code> values instead of their raw values (can you guess why?). Therefore, we could take the log of the above equation to write it as,</p>
<script type="math/tex; mode=display">\log\pi\big(\boldsymbol D\big|\mu,\sigma\big) = \sum^{N=100}_{i=1} - \log\big(2\pi\sigma^2\big) - \bigg[ \frac{\boldsymbol D(i)-\mu}{\sqrt{2}\sigma} \bigg]^2 ~~,</script>
<p>Now our goad is to construct this function (let’s name it <code>getLogProbNorm()</code>) and pass it to MATLAB’s built-in function <code>fminsearch()</code> in order to find the most likely $(\mu,\sigma)$ that leads to the highest likelihood value (the maximum of the above equation). Here is one last tip: Note that <code>fminsearch()</code> minimizes functions, but we want to maximize <code>getLogProbNorm()</code>, instead of minimizing it. What change could you make to this function to make it work with <code>fminsearch()</code>? Name your main script <code>findBestFitParameters.m</code>. Now when you run your script it should call <code>fminsearch()</code> and then output the best-fit parameters like the following,</p>
<pre><code class="language-matlab">>> findBestFitParameters
mu: -0.082001 , sigma: 1.0043
</code></pre>
<p><br />
Start your parameter search via <code>fminsearch()</code> with the following values: $[\mu,\sigma] = [1,10]$.</p>
<p><a href="http:/MAPCP2019U/homework/4-exceptions-errors-vectorization-visualization">Homework 4: Exceptions, Errors, Vectorization, Visualization</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on July 23, 2019.</p><![CDATA[Homework 3: Branching, looping, and functions]]>http:/MAPCP2019U/homework/3-branching-looping-functions2019-07-11T00:00:00-05:002019-07-11T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>♣ <strong>Due Date: One week from the posting date @ 10:30 AM</strong>. This homework aims at giving you some experience with branching, looping, and functions in both MATLAB and Python. Write your scripts with the corresponding <code>*.py</code> or <code>*.m</code> file names, and add a readme.md file in HW 3 folder of your project if you need to add any additional explanation (Don’t forget to use markdown syntax highlight in your readme file, if needed).</p>
<!--
The following figure illustrates the grade distribution for this homework.
<figure>
<img src="http:/MAPCP2019U/homework/gradeDist/gradeHistHomework5.png" width="700">
<figcaption style="text-align:center">
Maximum possible points is 100.
</figcaption>
</figure>
-->
<hr />
<hr />
<p><br /></p>
<p><strong>1. </strong> In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, that are characterized by the fact that every number after the first two is the sum of the two preceding ones:</p>
<script type="math/tex; mode=display">0,~1,~1,~2,~3,~5,~8,~13,~21,~34,~55,~89,~144,~\dots</script>
<p>with the following sequence equation,</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{eqnarray}
Fib(n) &=& Fib(n-1) + Fib(n-2) ~, \\
Fib(0) &=& 0 ~, \\
Fib(1) &=& 1 ~.
\end{eqnarray} %]]></script>
<p>Write a Python function named <code>fib</code> that takes in an input argument which should be integer number <code>n</code>, and then calculates the $n^{th}$ number in the Fibonacci sequence and outputs it on the screen. Also, if the input argument is not a non-negative integer, it prints an error message on the screen and asks the user to re-enter a non-negative integer number. Also, when it is done with finding the requested Fibonacci number, it asks again the user to either input a new non-negative integer, or enter ‘stop’ to end the function, like the following,</p>
<pre><code class="language-python">>>> fib('amir')
</code></pre>
<pre><code>The input argument amir is not a non-negative integer!
Please enter a non-negative integer: -123
The input argument -123 is not a non-negative integer!
Please enter a non-negative integer: 12.4
The input argument 12.4 is not a non-negative integer!
Please enter a non-negative integer: 0
Fib(0) = 0
Please enter another non-negative integer or type stop: 1
Fib(1) = 1
Please enter another non-negative integer or type stop: 2
Fib(2) = 1
Please enter another non-negative integer or type stop: 3
Fib(3) = 2
Please enter another non-negative integer or type stop: 4
Fib(4) = 3
Please enter another non-negative integer or type stop: 5
Fib(5) = 5
Please enter another non-negative integer or type stop: 6
Fib(6) = 8
Please enter another non-negative integer or type stop: 7
Fib(7) = 13
Please enter another non-negative integer or type stop: 8
Fib(8) = 21
Please enter another non-negative integer or type stop: 9
Fib(9) = 34
Please enter another non-negative integer or type stop: 10
Fib(10) = 55
Please enter another non-negative integer or type stop: 11
Fib(11) = 89
Please enter another non-negative integer or type stop: 12
Fib(12) = 144
Please enter another non-negative integer or type stop: stop
</code></pre>
<p><strong>Hint:</strong></p>
<ol>
<li>First write a function <code>fibo(n_int)</code> that finds the requested Fibonacci number for you, given a non-negative integer input (for example, name it <code>n_int</code>).</li>
<li>Then put this function <strong>inside another Python function <code>fib(n)</code></strong> that checks the type of the input argument <code>n</code> and prints the appropriate error message as in the above and then asks the user to enter another number (and then again checks for its type to be integer).</li>
<li>Then if this number is an integer, this function <code>fib(n)</code> passes the integer number <code>n</code> to the function <code>fibo(n_int)</code> which is inside of itself (it is a <strong>nested function</strong>), in order to get the requested Fibonacci number.</li>
<li>Finally, once the requested Fibonaccy number is obtained, it prints the number value with the requested format as in the above example, AND then asks again the user to input a new non-negative integer, or simply type <code>stop</code> to stop the function.</li>
</ol>
<p>Note that, if you call the function as <code>fib('stop')</code> in the Python interpreter, it should return nothing to you, just like the following example,</p>
<pre><code class="language-python">fib('stop')
</code></pre>
<p>I highly recommend you to write your function in Jupyter notebook, test it there, and then get the results for the same input arguments as in the above example (a string, negative integer, float, and n=1,…,12, and also ‘stop’) and download all of the notebook as a Markdown file, and put it in your repository folder for this homework. Name the notebook, <code>fib.md</code>.</p>
<p>Also note that, you don’t need to know or use anything beyond Python function syntax, Python built-in functions and methods (like <code>input</code>, <code>isdigit()</code>, <code>print</code>, <code>str()</code>, <code>int()</code>, …), and Python if-blocks.</p>
<blockquote>
I recommend you to use Jupyter notebook on your device, since the online version of notebook, can be interrupted repeatedly because of internet connection.
</blockquote>
<p><br /></p>
<p><strong>Answer:</strong></p>
<p>Here is an implementation in Python:</p>
<pre><code class="language-python">def fib(n):
def fibo(n_int):
if n_int==0: return 0
elif n_int==1: return 1
else:
return fibo(n_int-1) + fibo(n_int-2)
if n=='stop':
return None
elif str(n).isdigit(): # Make sure n is integer. Here is a bug: all positive numbers are assumed to not precede with + sign.
n=int(n)
print('Fib({}) = {}'.format(n,fibo(n)))
n = input("Please enter another integer or type stop: ") # Note that n is read as string!
return fib(n)
else: # the input is not an integer
print( 'The input argument {} is not a non-negative integer!'.format(n) )
n = input("Please enter an integer: ") # Note that n is read as string!
return fib(n)
</code></pre>
<p>Here is an implementation in MATLAB:</p>
<pre><code class="language-matlab">function fib()
% get the input
n = input('Please enter a non-negative integer or type stop: ','s');
if strcmp(n,'stop')
return
else
n = str2double(n);
if isreal(n) && n>=0 && round(n)==n
disp( [ 'fib(' , num2str(n) , ') = ' , num2str(getFib(n)) ] );
fib()
return
end
disp('The input argument is not a non-negative integer!');
fib()
end
function fib = getFib(n_int)
if n_int == 0
fib = 0;
elseif n_int == 1
fib = 1;
else
fib = getFib(n_int-1) + getFib(n_int-2);
end
end
end
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>2. </strong> <strong>Python.</strong> Branching…, the Pythonic way.</p>
<p><strong>(A)</strong> Change the <strong>first</strong> if statement in the following script to an equivalent <strong>one-line</strong> if-expression. Test the resulting new script, and make sure it behaves as the original,</p>
<pre><code class="language-python">#!/usr/bin/env python
abbr = input ("What is the four-letter abbreviation for the National Aeronautics and Space Administration? ")
answer_status = 'wrong'
if abbr == 'NASA':
answer_status = 'correct'
if answer_status=='correct':
print('Your answer is correct!')
else:
print("wrong buddy...try again")
</code></pre>
<p><strong>(B)</strong> Can you acheive the same goal as in <strong>(A)</strong> without if-expression or block, but instead using only tuple notation? Explain why your solution works.</p>
<p>Modify the if block and the print statements that are only in the last part of the code,</p>
<pre><code class="language-python">if answer_status=='correct':
print('Your answer is correct!')
else:
print("wrong buddy...try again")
</code></pre>
<p>to write a single-line Python statement that only uses <code>print</code> and tuple or list notations, to perform the exact same task as the original print and if-block statement.</p>
<p><strong>Answer:</strong></p>
<p><strong>(A)</strong></p>
<pre><code class="language-python">#!/usr/bin/env python
abbr = input ("What is the four-letter abbreviation for the National Aeronautics and Space Administration? ")
answer_status = 'correct' if abbr == 'NASA' else 'wrong'
if answer_status=='correct':
print('Your answer is correct!')
else:
print("wrong buddy...try again")
</code></pre>
<p><strong>(B)</strong></p>
<pre><code class="language-python">#!/usr/bin/env python
abbr = input ("What is the four-letter abbreviation for the National Aeronautics and Space Administration? ")
answer_status = ('wrong','correct')[abbr=='NASA']
if answer_status=='correct':
print('Your answer is correct!')
else:
print("wrong buddy...try again")
</code></pre>
<p><strong>(C)</strong></p>
<pre><code class="language-python">#!/usr/bin/env python
abbr = input ("What is the four-letter abbreviation for the National Aeronautics and Space Administration? ")
answer_status = ('wrong','correct')[abbr=='NASA']
print( ('wrong buddy...try again','Your answer is correct!')[answer_status=='correct'] )
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>3. Python.</strong></p>
<p><strong>(A)</strong> Write a <strong>single-line</strong> Python code that reads a string containing comma-separated first-name, last-name, and the city in which a person lives from the Python interpreter command line, and simultaneouly, in the same line of Python code, removes all white-space characters from the input string, and converts all letters of the input variables to lower-case, and converts the string to a tuple and saves in a tuple <code>(first,last,city)</code>, such that, for example,</p>
<pre><code class="language-text">Enter the first name, last name, and the city of the person (comma-separated): Amir, Shahmoradi , Austin
</code></pre>
<p>would give,</p>
<pre><code class="language-python">(first,last,city)
</code></pre>
<pre><code>('amir', 'shahmoradi', 'austin')
</code></pre>
<p><strong>Hint:</strong> Use <code>input</code> function for this purpose. The output of <code>input</code> is a string, which can be manipulated repeatedly on the same line, using multiple string methods that you learned about in the previous lectures.</p>
<p><strong>(B)</strong> As discussed in our lecture notes, the one-line if-expression syntax does not provide a functionality like <code>elif</code> keyword as in the if-statement syntax. Our goal here is to learn how to convert a Python if-statement containing <code>elif</code> to a one-line Python expression. Convert the following if-block to a single line if-expression. Modify the if-block inside the following function to one-line if-expression:</p>
<pre><code class="language-python">def dummy(i):
if i==0:
j=0
elif i==1:
j=1
elif i==2:
j=2
else: j = 'j is not in [0,1,2]'
return j
</code></pre>
<p><strong>Answer:</strong></p>
<p><strong>(A)</strong></p>
<pre><code class="language-python">(first,last,univ) = ((input('Enter the first name, last name, and the city of the person (comma-separated): ').replace(' ','')).lower()).split(',')
</code></pre>
<p><strong>(B)</strong></p>
<pre><code class="language-python">def dummy(i):
j = 0 if i==0 else (1 if i==1 else (2 if i==2 else 'j is not in [0,1,2]') )
return j
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>4. </strong>
An arbitrary triangle can be described by the coordinates of its three vertices: $(x1,y1),(x2,y2),(x3,y3)$, numbered in a counterclockwise direction. The area of the triangle is given by the formula,</p>
<script type="math/tex; mode=display">A = \frac{1}{2} \bigg| x2y3 - x3y2 - x1y3 + x3y1 + x1y2 - x2y1 \bigg|</script>
<p>Write a function <code>get_triangle_area(vertices)</code> that returns the area of a triangle whose vertices are specified by the argument vertices, which is a nested list of the vertex coordinates. Test your implementation with the following test function, which also illustrates how the <code>get_triangle_area</code> function works.</p>
<pre><code class="language-python">def test_get_triangle_area():
"""
Verify the area of a triangle with vertex coordinates
(0,0), (1,0), and (0,2).
"""
v1 = (0,0); v2 = (1,0); v3 = (0,2)
vertices = [v1, v2, v3]
expected = 1
computed = get_triangle_area(vertices)
tol = 1E-14
success = abs(expected - computed) < tol
msg = 'computed area=%g != %g (expected)' % (computed, expected)
assert success, msg
</code></pre>
<p><strong>Answer:</strong></p>
<p>Here is a Python implementation of the solution:</p>
<pre><code class="language-python"># getTriangleArea.py
def get_triangle_area(vert):
area = 0.5 * abs(vert[1][0] * vert[2][1] - vert[2][0] * vert[1][1] -
vert[0][0] * vert[2][1] + vert[2][0] * vert[0][1] +
vert[0][0] * vert[1][1] - vert[1][0] * vert[0][1])
return area
</code></pre>
<p>Here is a MATLAB implementation of the solution:</p>
<pre><code class="language-matlab">% getTriangleArea.m
function area = getTriangleArea(vertices)
area = 0.5 * abs( vertices{2}(1) * vertices{3}(2) ...
- vertices{3}(1) * vertices{2}(2) ...
- vertices{1}(1) * vertices{3}(2) ...
+ vertices{3}(1) * vertices{1}(2) ...
+ vertices{1}(1) * vertices{2}(2) ...
+ vertices{2}(1) * vertices{1}(2) ...
)
end
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>5. </strong> Write a logical (boolean) function named <code>is_prime(n)</code> that takes in an integer number <code>n</code>, and finds whether it is a Prime number or not. Example output is the following,</p>
<pre><code class="language-python">is_prime(n=23)
</code></pre>
<pre><code>True
</code></pre>
<pre><code class="language-python">is_prime(12)
</code></pre>
<pre><code>False
</code></pre>
<p>Note that you do not need and don’t have to use <code>for-loop</code> for this problem (we have not yet discussed loops in our class!). All of it can be done using recursive function concept.</p>
<p><strong>Answer:</strong></p>
<p>Here is an implementation in Python:</p>
<pre><code class="language-python">def is_prime(n):
is_prime = True
def is_divisible(n,divisor):
if n<(divisor-1)*divisor: return False
if n%divisor==0: return True
else:
divisor += 1
return is_divisible(n,divisor)
if is_divisible(n,divisor=2): is_prime=False
return is_prime
</code></pre>
<p>Here is an implementation in MATLAB:</p>
<pre><code class="language-matlab">function outLogical = isPrime(n)
divisor = 2;
outLogical = true;
sqrt_n = round(sqrt(n));
outLogical = isDivisible(n,sqrt_n,divisor);
function output = isDivisible(n,sqrt_n,divisor)
if mod(n,divisor) == 0
output = false;
elseif sqrt_n<divisor
output = true;
return
else
divisor = divisor + 1;
output = isDivisible(n,sqrt_n,divisor);
end
end
end
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>6. </strong> <strong>MATLAB Function generators.</strong> Write a nested function that evaluates a polynomial of the form $y = ax^2+bx+c$. The host function <code>genFunc()</code> should be able to take varying number of arguments using <code>varargin</code> with maximum of 3 arguments (<code>a,b,c</code>) to initialize the coefficients of the polynomial. If there is only one argument, then <code>b</code> and <code>c</code> must be set to zero. If there are two input arguments, then <code>c</code> is set to zero. If none are given on input, then the returned function should be zero. If more than 3 arguments exist, then the function should display an error and stop. Also, if the input arguments are not real numbers, then the function should return an error and stop.</p>
<p>On output, the host function should create and return a function handle for the nested function <code>evalFunc()</code>. The nested function should calculate a value of $y$ for a given value of $x$, using the values of $a$, $b$, and $c$ stored in the host function. This is called a <strong>function generator</strong>, since the host function generates and outputs another function that can be called and used later on in the program. Once you create your function generator, test it in the following way: Call <code>genFunc(1,2,0)</code> and save the output function handle in a variable, say <code>h1</code>. Call <code>genFunc(1,2)</code> and save the output function handle in a variable, say <code>h2</code>. Then these two function handles, should give the same result, given the same input <code>x</code> values.</p>
<p><strong>Answer:</strong></p>
<p>Here is an example implementation of the function:</p>
<pre><code class="language-matlab">function [outputQuadraticFuncHandle] = genFunc(varargin)
switch nargin
case 0
a=0;
b=0;
c=0;
case 1
a=varargin{1};
b=0;
c=0;
case 2
a=varargin{1};
b=varargin{2};
c=0;
case 3
a=varargin{1};
b=varargin{2};
c=varargin{3};
otherwise
error('Too many arguments')
end
function y = evalQuadFunc(x)
y = a*x.^2 + b*x + c;
end
outputQuadFuncHandle = @evalQuadFunc;
end
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>7. </strong> Consider the following nested list in Python,</p>
<pre><code class="language-python">q = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h']]
</code></pre>
<p>or its equivalent in MATLAB,</p>
<pre><code class="language-matlab">q = {{'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h'}}
</code></pre>
<p>Write a for-loop that extracts all the letters in the list and finally prints them all as a single string,</p>
<pre><code class="language-text">abcdefgh
</code></pre>
<p><strong>Answer:</strong><br />
Here is a solution in Python:</p>
<pre><code class="language-python">q = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h']]
s = ''
for i in q:
for j in range(len(i)):
s += i[j]
print(s)
</code></pre>
<pre><code>abcdefgh
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>8. </strong> <strong>The significant impact of round-off errors in numerical computation.</strong> Consider the following program in Python,</p>
<pre><code class="language-python">from math import sqrt
for n in range(1, 60):
r_org = 2.0
r = r_org
for i in range(n):
r = sqrt(r)
for i in range(n):
r = r ** 2
print ('With {} times sqrt and then {} times **2, the number {} becomes: {:.16f}'.format(n,n,r_org,r))
</code></pre>
<p>or its equivalent in MATLAB,</p>
<pre><code class="language-matlab">formatSpec = 'With %d sqrt, then %d times ^2 operations, the number %.16f becomes: %.16f \n'; % the string format for fprintf function
for n = 1:60
r_original = 2.0;
r = r_original;
for i = 1:n
r = sqrt(r);
end
for i = 1:n
r = r^2;
end
fprintf(formatSpec,n,n,r_original,r);
end
</code></pre>
<p>Explain what this code does. Then run the code, and explain why do you the behavior observed. In particular, why do you not recover the original value $2$ after many repetitions of the same forward and reverse task?</p>
<p><strong>Answer:</strong><br />
This code will yield the following output in Python:</p>
<pre><code class="language-python">from math import sqrt
for n in range(1, 60):
r_org = 2.0
r = r_org
for i in range(n):
r = sqrt(r)
for i in range(n):
r = r ** 2
print ('With {} times sqrt and then {} times **2, the number {} becomes: {:.16f}'.format(n,n,r_org,r))
</code></pre>
<pre><code class="language-text">With 1 times sqrt and then 1 times **2, the number 2.0 becomes: 2.0000000000000004
With 2 times sqrt and then 2 times **2, the number 2.0 becomes: 1.9999999999999996
With 3 times sqrt and then 3 times **2, the number 2.0 becomes: 1.9999999999999996
With 4 times sqrt and then 4 times **2, the number 2.0 becomes: 1.9999999999999964
With 5 times sqrt and then 5 times **2, the number 2.0 becomes: 1.9999999999999964
With 6 times sqrt and then 6 times **2, the number 2.0 becomes: 1.9999999999999964
With 7 times sqrt and then 7 times **2, the number 2.0 becomes: 1.9999999999999714
With 8 times sqrt and then 8 times **2, the number 2.0 becomes: 2.0000000000000235
With 9 times sqrt and then 9 times **2, the number 2.0 becomes: 2.0000000000000235
With 10 times sqrt and then 10 times **2, the number 2.0 becomes: 2.0000000000000235
With 11 times sqrt and then 11 times **2, the number 2.0 becomes: 2.0000000000000235
With 12 times sqrt and then 12 times **2, the number 2.0 becomes: 1.9999999999991336
With 13 times sqrt and then 13 times **2, the number 2.0 becomes: 1.9999999999973292
With 14 times sqrt and then 14 times **2, the number 2.0 becomes: 1.9999999999973292
With 15 times sqrt and then 15 times **2, the number 2.0 becomes: 1.9999999999973292
With 16 times sqrt and then 16 times **2, the number 2.0 becomes: 2.0000000000117746
With 17 times sqrt and then 17 times **2, the number 2.0 becomes: 2.0000000000408580
With 18 times sqrt and then 18 times **2, the number 2.0 becomes: 2.0000000000408580
With 19 times sqrt and then 19 times **2, the number 2.0 becomes: 2.0000000001573586
With 20 times sqrt and then 20 times **2, the number 2.0 becomes: 2.0000000001573586
With 21 times sqrt and then 21 times **2, the number 2.0 becomes: 2.0000000001573586
With 22 times sqrt and then 22 times **2, the number 2.0 becomes: 2.0000000010885857
With 23 times sqrt and then 23 times **2, the number 2.0 becomes: 2.0000000029511749
With 24 times sqrt and then 24 times **2, the number 2.0 becomes: 2.0000000066771721
With 25 times sqrt and then 25 times **2, the number 2.0 becomes: 2.0000000066771721
With 26 times sqrt and then 26 times **2, the number 2.0 becomes: 1.9999999917775542
With 27 times sqrt and then 27 times **2, the number 2.0 becomes: 1.9999999917775542
With 28 times sqrt and then 28 times **2, the number 2.0 becomes: 1.9999999917775542
With 29 times sqrt and then 29 times **2, the number 2.0 becomes: 1.9999999917775542
With 30 times sqrt and then 30 times **2, the number 2.0 becomes: 1.9999999917775542
With 31 times sqrt and then 31 times **2, the number 2.0 becomes: 1.9999999917775542
With 32 times sqrt and then 32 times **2, the number 2.0 becomes: 1.9999990380770896
With 33 times sqrt and then 33 times **2, the number 2.0 becomes: 1.9999971307544144
With 34 times sqrt and then 34 times **2, the number 2.0 becomes: 1.9999971307544144
With 35 times sqrt and then 35 times **2, the number 2.0 becomes: 1.9999971307544144
With 36 times sqrt and then 36 times **2, the number 2.0 becomes: 1.9999971307544144
With 37 times sqrt and then 37 times **2, the number 2.0 becomes: 1.9999971307544144
With 38 times sqrt and then 38 times **2, the number 2.0 becomes: 1.9999360966436217
With 39 times sqrt and then 39 times **2, the number 2.0 becomes: 1.9999360966436217
With 40 times sqrt and then 40 times **2, the number 2.0 becomes: 1.9999360966436217
With 41 times sqrt and then 41 times **2, the number 2.0 becomes: 1.9994478907329654
With 42 times sqrt and then 42 times **2, the number 2.0 becomes: 1.9984718365144798
With 43 times sqrt and then 43 times **2, the number 2.0 becomes: 1.9965211562778555
With 44 times sqrt and then 44 times **2, the number 2.0 becomes: 1.9965211562778555
With 45 times sqrt and then 45 times **2, the number 2.0 becomes: 1.9887374575497223
With 46 times sqrt and then 46 times **2, the number 2.0 becomes: 1.9887374575497223
With 47 times sqrt and then 47 times **2, the number 2.0 becomes: 1.9887374575497223
With 48 times sqrt and then 48 times **2, the number 2.0 becomes: 1.9887374575497223
With 49 times sqrt and then 49 times **2, the number 2.0 becomes: 1.8682459487159784
With 50 times sqrt and then 50 times **2, the number 2.0 becomes: 1.6487212645509468
With 51 times sqrt and then 51 times **2, the number 2.0 becomes: 1.6487212645509468
With 52 times sqrt and then 52 times **2, the number 2.0 becomes: 1.0000000000000000
With 53 times sqrt and then 53 times **2, the number 2.0 becomes: 1.0000000000000000
With 54 times sqrt and then 54 times **2, the number 2.0 becomes: 1.0000000000000000
With 55 times sqrt and then 55 times **2, the number 2.0 becomes: 1.0000000000000000
With 56 times sqrt and then 56 times **2, the number 2.0 becomes: 1.0000000000000000
With 57 times sqrt and then 57 times **2, the number 2.0 becomes: 1.0000000000000000
With 58 times sqrt and then 58 times **2, the number 2.0 becomes: 1.0000000000000000
With 59 times sqrt and then 59 times **2, the number 2.0 becomes: 1.0000000000000000
</code></pre>
<p>and this code will yield the following output in MATLAB,</p>
<pre><code class="language-matlab">formatSpec = 'With %d sqrt, then %d times ^2 operations, the number %.16f becomes: %.16f \n'; % the string format for fprintf function
for n = 1:60
r_original = 2.0;
r = r_original;
for i = 1:n
r = sqrt(r);
end
for i = 1:n
r = r^2;
end
fprintf(formatSpec,n,n,r_original,r);
end
</code></pre>
<pre><code class="language-text">>> roundoff
With 1 sqrt, then 1 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000000004
With 2 sqrt, then 2 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999996
With 3 sqrt, then 3 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999996
With 4 sqrt, then 4 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999964
With 5 sqrt, then 5 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999964
With 6 sqrt, then 6 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999964
With 7 sqrt, then 7 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999999714
With 8 sqrt, then 8 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000000235
With 9 sqrt, then 9 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000000235
With 10 sqrt, then 10 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000000235
With 11 sqrt, then 11 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000000235
With 12 sqrt, then 12 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999991336
With 13 sqrt, then 13 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999973292
With 14 sqrt, then 14 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999973292
With 15 sqrt, then 15 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999999973292
With 16 sqrt, then 16 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000117746
With 17 sqrt, then 17 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000408580
With 18 sqrt, then 18 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000000408580
With 19 sqrt, then 19 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000001573586
With 20 sqrt, then 20 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000001573586
With 21 sqrt, then 21 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000001573586
With 22 sqrt, then 22 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000010885857
With 23 sqrt, then 23 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000029511749
With 24 sqrt, then 24 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000066771721
With 25 sqrt, then 25 times ^2 operations, the number 2.0000000000000000 becomes: 2.0000000066771721
With 26 sqrt, then 26 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 27 sqrt, then 27 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 28 sqrt, then 28 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 29 sqrt, then 29 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 30 sqrt, then 30 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 31 sqrt, then 31 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999999917775542
With 32 sqrt, then 32 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999990380770896
With 33 sqrt, then 33 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999971307544144
With 34 sqrt, then 34 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999971307544144
With 35 sqrt, then 35 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999971307544144
With 36 sqrt, then 36 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999971307544144
With 37 sqrt, then 37 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999971307544144
With 38 sqrt, then 38 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999360966436217
With 39 sqrt, then 39 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999360966436217
With 40 sqrt, then 40 times ^2 operations, the number 2.0000000000000000 becomes: 1.9999360966436217
With 41 sqrt, then 41 times ^2 operations, the number 2.0000000000000000 becomes: 1.9994478907329654
With 42 sqrt, then 42 times ^2 operations, the number 2.0000000000000000 becomes: 1.9984718365144798
With 43 sqrt, then 43 times ^2 operations, the number 2.0000000000000000 becomes: 1.9965211562778555
With 44 sqrt, then 44 times ^2 operations, the number 2.0000000000000000 becomes: 1.9965211562778555
With 45 sqrt, then 45 times ^2 operations, the number 2.0000000000000000 becomes: 1.9887374575497223
With 46 sqrt, then 46 times ^2 operations, the number 2.0000000000000000 becomes: 1.9887374575497223
With 47 sqrt, then 47 times ^2 operations, the number 2.0000000000000000 becomes: 1.9887374575497223
With 48 sqrt, then 48 times ^2 operations, the number 2.0000000000000000 becomes: 1.9887374575497223
With 49 sqrt, then 49 times ^2 operations, the number 2.0000000000000000 becomes: 1.8682459487159784
With 50 sqrt, then 50 times ^2 operations, the number 2.0000000000000000 becomes: 1.6487212645509468
With 51 sqrt, then 51 times ^2 operations, the number 2.0000000000000000 becomes: 1.6487212645509468
With 52 sqrt, then 52 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 53 sqrt, then 53 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 54 sqrt, then 54 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 55 sqrt, then 55 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 56 sqrt, then 56 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 57 sqrt, then 57 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 58 sqrt, then 58 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 59 sqrt, then 59 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
With 60 sqrt, then 60 times ^2 operations, the number 2.0000000000000000 becomes: 1.0000000000000000
</code></pre>
<p>What is happening is that, 1 is returned for n >= 52 as square root of 2, that is, after 52 times square-root operation, the degree of accuracy required for representing the result goes beyond the degree of accuracy available in a MATLAB double precision number. Consequently, the later squaring operation on 1.00000000000000 will leave the number unchanged and therefore, 2 is not recovered.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>9. </strong> Consider the following code,</p>
<pre><code class="language-python">eps = 1.0
while 1.0 != 1.0 + eps:
print ('...............', eps)
eps /= 2.0
print ('final eps:', eps)
</code></pre>
<p>or its equivalent in MATLAB,</p>
<pre><code class="language-matlab">eps = 1.0;
while 1.0 ~= 1.0 + eps
disp(num2str(eps));
eps = eps / 2.0;
end
disp(['final eps:', num2str(eps)]);
</code></pre>
<p>Explain what the code is doing. Run the code and observe the output. How could <code>1.0 != 1.0 + eps</code> be False?</p>
<p><strong>Answer:</strong><br />
Here is the output of the code,</p>
<pre><code class="language-text">............... 1.0
............... 0.5
............... 0.25
............... 0.125
............... 0.0625
............... 0.03125
............... 0.015625
............... 0.0078125
............... 0.00390625
............... 0.001953125
............... 0.0009765625
............... 0.00048828125
............... 0.000244140625
............... 0.0001220703125
............... 6.103515625e-05
............... 3.0517578125e-05
............... 1.52587890625e-05
............... 7.62939453125e-06
............... 3.814697265625e-06
............... 1.9073486328125e-06
............... 9.5367431640625e-07
............... 4.76837158203125e-07
............... 2.384185791015625e-07
............... 1.1920928955078125e-07
............... 5.960464477539063e-08
............... 2.9802322387695312e-08
............... 1.4901161193847656e-08
............... 7.450580596923828e-09
............... 3.725290298461914e-09
............... 1.862645149230957e-09
............... 9.313225746154785e-10
............... 4.656612873077393e-10
............... 2.3283064365386963e-10
............... 1.1641532182693481e-10
............... 5.820766091346741e-11
............... 2.9103830456733704e-11
............... 1.4551915228366852e-11
............... 7.275957614183426e-12
............... 3.637978807091713e-12
............... 1.8189894035458565e-12
............... 9.094947017729282e-13
............... 4.547473508864641e-13
............... 2.2737367544323206e-13
............... 1.1368683772161603e-13
............... 5.684341886080802e-14
............... 2.842170943040401e-14
............... 1.4210854715202004e-14
............... 7.105427357601002e-15
............... 3.552713678800501e-15
............... 1.7763568394002505e-15
............... 8.881784197001252e-16
............... 4.440892098500626e-16
............... 2.220446049250313e-16
final eps: 1.1102230246251565e-16
</code></pre>
<p>What is happening is that after a certain number of divisions performed on the value of <code>eps</code>, the value goes beyond the highest float precision representable by Python standard ($0.0000000000000001$), and therefore the value of <code>eps</code> is eventually rounded to exact zero. The nonzero <code>eps</code> value computed above is called <strong>machine epsilon</strong> or <strong>machine zero</strong> and is an important parameter to know, since it can lead to disasters in your very important complex calculations.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>10. MATLAB.</strong> Suppose you want to find the largest prime number that is smaller than a given input value by the user. Write a function named <code>getLargestPrime</code> that does so, using for-loop, break, and MATLAB’s intrinsic function isprime(). Here is a test,</p>
<pre><code class="language-matlab">>> getLargestPrime(123)
ans =
113
</code></pre>
<p><strong>Answer:</strong></p>
<pre><code class="language-matlab">function integer = getLargestPrime(upper)
if (upper<1)
disp('input value cannot be less than 1. Goodbye!')
return
end
for integer = upper:-1:1
if isprime(integer)
break
end
end
end
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>11. Python</strong> Consider the following list,</p>
<pre><code class="language-python">numbers = list(range(10))
print(numbers)
</code></pre>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>
<p>Now run the following code, given the above list. Explain the weird behavior that you observe.</p>
<pre><code class="language-python">for n in numbers:
i = len(numbers)//2
del numbers[i]
print ('n={}, del {}'.format(n,i), numbers)
</code></pre>
<p><strong>Answer:</strong></p>
<pre><code class="language-python">numbers = list(range(10))
for n in numbers:
i = len(numbers)//2
del numbers[i]
print ('n={}, del {}'.format(n,i), numbers)
</code></pre>
<pre><code>n=0, del 5 [0, 1, 2, 3, 4, 6, 7, 8, 9]
n=1, del 4 [0, 1, 2, 3, 6, 7, 8, 9]
n=2, del 4 [0, 1, 2, 3, 7, 8, 9]
n=3, del 3 [0, 1, 2, 7, 8, 9]
n=8, del 3 [0, 1, 2, 8, 9]
</code></pre>
<p>What is really happening is that the list over which we are looping changes its content because of the modifications during on the list in the for-loop. The message in this exercise is to <strong>never modify a list that you are looping over</strong>. Modification is indeed technically possible, as shown above, but you really need to know what you are doing. Otherwise you will experience very strange program behavior.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>12. Python</strong> Write a Python function that when executed, asks the user to enter an integer number, then the function count and outputs the number of prime numbers that are smaller than the given input integer number. Here is the answer to this question using only the knowledge of recursive functions and if-blocks,</p>
<pre><code class="language-python">def is_prime(n):
is_prime = True
def is_divisible(n,divisor):
if n<(divisor-1)*divisor: return False
if n%divisor==0: return True
else:
divisor += 1
return is_divisible(n,divisor)
if is_divisible(n,divisor=2): is_prime=False
return is_prime
def get_primes(n):
count = 0
if n == 1:
return count
else:
if is_prime(n):
count = 1
n -= 1
return count + get_primes(n)
</code></pre>
<pre><code class="language-python">get_primes(13)
</code></pre>
<pre><code>5
</code></pre>
<p>(A) Now rewrite <code>get_primes(n)</code> and the other functions in the above code using for-loop this time. Name the new functions <code>get_prime_for(n)</code> and <code>is_prime_for(n)</code>, with <em>for</em> in the names indicating that the functions now use for-loops.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-python">def is_prime_for(x):
if x > 1:
n = x // 2
for i in range(2, n + 1):
if x % i == 0:
return False
return True
else:
return False
def get_primes_for(n):
count = 0
for i in range(2,n):
if is_prime(i):
count += 1
return count
</code></pre>
<p>Here is a test,</p>
<pre><code class="language-python">get_primes_for(13)
</code></pre>
<pre><code>5
</code></pre>
<p>(B) Now compare the performance of the two functions <code>get_primes(n=500)</code> and <code>get_primes_for(n500)</code> using Jupyter’s or IPython’s <code>%timeit</code> magic function. Which one is faster?</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-python">%timeit get_primes(500)
</code></pre>
<pre><code>1000 loops, best of 3: 1.32 ms per loop
</code></pre>
<pre><code class="language-python">%timeit get_primes_for(500)
</code></pre>
<pre><code>1000 loops, best of 3: 1.69 ms per loop
</code></pre>
<p>Interesting, recursive functions seem to be faster than Python for-loops!</p>
<p><a href="http:/MAPCP2019U/homework/3-branching-looping-functions">Homework 3: Branching, looping, and functions</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on July 11, 2019.</p><![CDATA[Final exam: semester project]]>http:/MAPCP2019U/exam/1-semester-project2019-07-11T00:00:00-05:002019-07-11T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>This is page describes the final semester project that will serve as the final exam for this course. Please submit all your efforts for this project (all files, data and results) in <code>MAPCP2019U/exams/final/</code> directory in your private repository for this course. Don’t forget to push your answers to your remote Github repository by <strong>10:30 AM, August 8, 2019</strong>. <strong>Note: I strongly urge you to attend the future lectures until the end of the semester and seek help from the instructor (Amir) to tackle this project.</strong></p>
<p>Inside the directory for the project (<code>MAPCP2019U/exams/final/</code>) create three other folders: <code>data</code>, <code>src</code>, <code>results</code>. The <code>data</code> folder contains the <a href="http:/MAPCP2019U/exam/1-problems/cells.mat" target="_blank">input data</a> for this project. The <code>src</code> folder should contain all your codes that you write for this project, and the <code>results</code> folder should contain all the results generated by your code.</p>
<div class="post_toc"></div>
<h2 id="data-reduction-and-visualization">Data reduction and visualization</h2>
<p>Our goal in this project is to fit a mathematical model of the growth of living cells to real experimental data for the growth of a cancer tumor in the brain of a rat. You can download the data in the form of a MATLAB data file for this project from <a href="http:/MAPCP2019U/exam/1-problems/cells.mat" target="_blank">here</a>. Write a set of separate MATLAB/Python codes that perform the following tasks one after the other, and output all the results to the <code>results</code> folder described above. Since you have multiple MATLAB/Python codes each in a separate file for different purposes, you should also write a <code>main</code> MATLAB/Python code, such that when the user of your codes runs on MATLAB command line,</p>
<pre><code class="language-bash">>> main
</code></pre>
<p><br />
then all the necessary MATLAB/Python codes to generate all the results will be called by this <code>main</code> script.</p>
<p>Initially at time $t=0 ~\mathrm{[days]}$, $100,000\pm10,000$ brain tumor cells are injected to the brain of the rat. These cells are then allowed to grow for 10 days. Then starting at day 10, the brain of the rat is imaged using an <a href="https://en.wikipedia.org/wiki/Magnetic_resonance_imaging" target="_blank">MRI machine</a>.</p>
<p>Each image results in a 4-dimensional double-precision MATLAB matrix <code>cells(:,:,:,:)</code>, corresponding to dimensions <code>cells(y,x,z,time)</code>. This data is collected from MRI imaging of the rat’s brain almost every other day for a period of two weeks. For example, <code>cells(:,:,:,1)</code> contains the number of cells at each point in space (y,x,z) at the first time point, or, <code>cells(:,:,10,1)</code> represents a (XY) slice of MRI at $z=1$ and $t=1 [days]$.</p>
<p>Therefore, the vector of times at which we have the number of tumor cells measured would be,</p>
<script type="math/tex; mode=display">Time = [ 0, 10, 12, 14, 16, 18, 20, 22 ] ~,</script>
<p>in units of days. Given this data set,</p>
<p><strong>1. </strong> First write a MATLAB/Python script that reads the input MATLAB binary file containing cell numbers at different positions in the rat’s brain measured by MRI, on different days.</p>
<p><strong>2. </strong> Write MATLAB/Python codes that generate a set of figures as similar as possible to the following figures (specific color-codes of the curves and figures do not matter, focus more on the format of the plots and its parts). For this part of the project you will MATLAB plotting functions such as <code>plot()</code>, <code>imagesc()</code> and the concept subplots in MATLAB/Python.</p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_1_t10.0.png" width="900" />
</figure>
<p><br /></p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_2_t12.0.png" width="900" />
</figure>
<p><br /></p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_3_t14.0.png" width="900" />
</figure>
<p><br /></p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_5_t16.0.png" width="900" />
</figure>
<p><br /></p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_6_t18.0.png" width="900" />
</figure>
<p><br /></p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/tvccZSliceSubplotWithXYlab_rad_00gy_7_t20.0.png" width="900" />
</figure>
<p><br /></p>
<h2 id="obtaining-the-error-in-tumor-cell-count">Obtaining the error in tumor cell count</h2>
<p><strong>3. </strong> Our assumption here is that the uncertainty in the total number of tumor cells at each time point is given by the number of tumor cells at the boundary of tumor. Therefore, you will have to write a MATLAB code that identifies the boundary of tumor at each time point and then sums over the count cells in all boundary points and uses that as the error in number of tumor cell counts. For this part, you will need MATLAB/Python functions such as <code>bwboundaries()</code> and <code>errorbar()</code>. In the end, you should get and save a figure in your project’s figure folder like the following figure,</p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/growthCurve.png" width="900" />
</figure>
<p><br /></p>
<p>Note that this part of the project is completely independent of the modeling part described in the following section.</p>
<h2 id="the-mathematical-model-of-tumor-growth">The mathematical model of tumor growth</h2>
<p><strong>4. </strong> Now our goal is to fit the time evolution of the growth of this tumor, using a mathematical model. To do so, we need to find the best-fit parameters of the model. The mathematical model we will use here is called the <a href="https://en.wikipedia.org/wiki/Gompertz_function" target="_blank">Gompertzian growth model</a>. Here, we will use a slightly modified for of the Gompertzian function of the following form,</p>
<script type="math/tex; mode=display">N(t,\lambda,c) = N_0 \times \exp\bigg( \lambda~\bigg[ 1-\exp(-ct) \bigg] \bigg) ~,</script>
<p>where $N(t,\lambda,c)$ is the <strong>predicted number</strong> of tumor cells at time $t$, $N_0$ is the initial number of tumor cells at time $t=0$ days, $\lambda$ is the growth rate parameter of the model, and $c$ is just another parameter of the model. We already know the initial value of the number of tumor cells, $N_0=100,000\pm10,000$. Therefore, we can fix $N_0$ to $100,000$ in the equation of the model given above.</p>
<p>However, we don’t know the values of the parameters $\lambda$ and $c$. Thus, we would like to find their best values given the input tumor cell data using some MATLAB/Python optimization algorithm.</p>
<p>This Gompertzian growth model is called our <strong>physical model</strong> for this problem, because it describes the physics of our problem (The physics/biology of the tumor growth).</p>
<h3 id="combining-the-physical-model-with-a-regression-model">Combining the physical model with a regression model</h3>
<p>Now, if our physical model was ideally perfect in describing the data, the curve of the model prediction would pass through all the points in the growth curve plot of the above figure, thus providing a prefect description of data. This is however, never the case, as it is famously said <strong>all models are wrong, but some are useful</strong>. In other words, the model prediction never matches observation perfectly.</p>
<p>Therefore, we have to seek for the parameter values that can bring the model prediction us as close as possible to data. To do so, we define a <strong>statistical model</strong> in addition to the <strong>physical model</strong> described above. In other words, we have to define a statistical regression model (the renowned <strong>least-squares method</strong>) that gives us the probability $\pi(\log N_{obs}|\log N(t))$ of observing individual data points at each of the given times,</p>
<script type="math/tex; mode=display">\pi(\log N_{obs} | \log N(t,\lambda,c),\sigma) = \frac{1}{\sigma\sqrt{2\pi}} \exp\bigg( - \frac{ \big[ \log N_{obs}(t)-\log N(t,\lambda,c) \big]^2}{2\sigma^2} \bigg) ~,</script>
<p>Note that our statistical model given above is a Normal probability density function, with its mean parameter represented by <strong>the log</strong> of the output of our physical model, $\log N(t,\lambda,c)$, and its standard deviation represented by $\sigma$, which is unknown, and we seek to find it. The symbol $\pi$, whenever it appears with parentheses, like $\pi()$, it means probability of the entity inside the parentheses. However, whenever it appears alone, it means the famous number PI, $\pi\approx 3.1415$.</p>
<p><strong>Why do we use the logarithm of the number of cells instead of using the number of cells directly?</strong> The reason behind it is slightly complicated. A simple (but not entirely correct argument) is the following: We do so, because the tumor cell counts at later times become extremely large numbers, on the order of several million cells (For example, look at the number of cells in the late stages of the tumor growth, around $t=20$ days). Therefore, to make sure that we don’t hit any numerical precision limits of the computer when dealing with such huge numbers, we work with the logarithm of the number of tumor cells instead of their true non-logarithmic values.</p>
<p>We have seven data points, so the overall probability of observing all of data $\mathcal{D}$ together (the time vector and the logarithm of the number of cells at different times) given the parameters of the model, $\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)$, is the product of their individual probabilities of observations given by the above equation,</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align*}
\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)
&= \prod_{i=1}^{n=8} \pi(\log N_{obs}(t_i) | \log N(t_i,\lambda,c),\sigma) \\\\
&= \prod_{i=1}^{n=8} \frac{1}{\sigma\sqrt{2\pi}} \exp\bigg( - \frac{ \big[ \log N_{obs}(t_i)-\log N(t_i,\lambda,c) \big]^2}{2\sigma^2} \bigg) ~.
\end{align*} %]]></script>
<p>Frequently however, you would want to work with $\log\mathcal{L}$ instead of $\mathcal{L}$. This is again because the numbers involved are extremely small often below the precision limits of the computer. So, by taking the logarithm of the numbers, we work instead with number’s exponent, which looks just like a normal number (not so big, not so small). So, by taking the log, the above equation becomes,</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align*}
\log\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)
&= \sum_{i=1}^{n=8} \log \pi( \log N_{obs}(t_i) | \log N(t_i,\lambda,c),\sigma) \\\\
&= \sum_{i=1}^{n=8} \log \bigg[ \frac{1}{\sigma\sqrt{2\pi}} \exp\bigg( - \frac{ \big[ \log N_{obs}(t_i) - \log N(t_i,\lambda,c) \big]^2}{2\sigma^2} \bigg) \bigg] ~.
\end{align*} %]]></script>
<p><br /></p>
<p><strong>5. </strong>
Now the goal is to use an optimization algorithm in MATLAB/Python, such as <code>fminsearch()</code>, to find the most likely set of the parameters of the model $\lambda,c,\sigma$ that give the highest likelihood of obtaining the available data, which is given by the number $\log\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)$ from the above equation. So we want to find the set of parameters for which this number given by the above equation is maximized. You can also use any MATLAB/Python optimization function or method that you wish, to obtain the best parameters.</p>
<p>However, if you use <code>fminsearch()</code>, then note that this function finds the minimum of an input function, not the maximum. What we want is to find the maximum of $\log\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)$.
What is the solution then? Very simple.
We can multiply the value of $\log\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)$ by a negative, so that the maximum value is converted to minimum. But, note that the position (the set of parameter values) at which this minimum occurs, will remain the same as the maximum position for $\log\mathcal{L}(\mathcal{D}|\lambda,c,\sigma)$.</p>
<p>So, now rewrite your likelihood function above by multiplying its final result (which is just number) by a negative sign. Then you pass this modified function to <code>fminsearch()</code> and you find the optimal parameters. Note that <code>fminsearch()</code> takes as input also a set of initial staring parameter values to initiate the search for the optimal parameters. You can use $(\lambda,c,\sigma) = [10,0.1,1]$ as your starting point given to <code>fminsearch()</code> to search for the optimal values of the parameters.</p>
<p>Then redraw the above tumor evolution curve and show the result from the model prediction as well, like the following,</p>
<figure>
<img src="http:/MAPCP2019U/exam/1-problems/figures/growthCurveFit.png" width="900" />
</figure>
<p><br /></p>
<p>Report also your best fit parameters in a file and submit them with all the figures and your codes to your exam folder repository.</p>
<p><br /><br /></p>
<p><a href="http:/MAPCP2019U/exam/1-semester-project">Final exam: semester project</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on July 11, 2019.</p><![CDATA[Quiz 2: Value, variables, types]]>http:/MAPCP2019U/quiz/2-values-variables-types2019-06-26T00:00:00-05:002019-06-26T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<!--
This is the solution to [Quiz 1: Problems - Version control system](1-problems-version-control-system.html){:target="_blank"}.
The following figure illustrates the grade distribution for this quiz.
<figure>
<img src="http:/MAPCP2019U/quiz/gradeDist/gradeHistQuiz1.png" width="700">
<figcaption style="text-align:center">
Maximum possible points is 1.
</figcaption>
</figure>
-->
<p>This quiz aims at testing your basic knowledge of values and variables. Don’t forget to push your answers to your remote repository by the end of quiz time. Push all your answers to <strong>quiz/2/</strong> folder in your Github project.</p>
<hr />
<hr />
<p><br /></p>
<ol>
<li>
<p>Name three different levels of the computer memory.</p>
<p><strong>Answer:</strong> Register (L1 Cache), L2 Cache, L3 Cache, RAM (Random-Access Memory), HDD (Hard Drive Disk).</p>
</li>
<li>
<p>Suppose that you have a matrix of rank 2 to store in the computer memory. How would each one of the following languages store this matrix (column-wise vs. row-wise):<br />
b) C<br />
a) Fortran<br />
c) MATLAB<br />
d) Python</p>
<p><strong>Answer:</strong> <br />
a) row-wise<br />
b) column-wise<br />
c) column-wise<br />
d) row-wise</p>
</li>
<li>
<p>What are the three fundamental components of a Turing-complete language?</p>
<p><strong>Answer:</strong></p>
<ol>
<li>a way for accessing the memory</li>
<li>a way for iteration</li>
<li>a way for branching</li>
</ol>
</li>
<li>
<p>What are the three common types of errors in computer programs?</p>
<p><strong>Answer:</strong></p>
<ol>
<li>syntax errors</li>
<li>runtime errors</li>
<li>semantic errors</li>
</ol>
</li>
<li>
<p>Suppose you write a program that has memory leak. What type of programming error you dealing with?</p>
<p><strong>Answer:</strong> runtime error</p>
</li>
<li>
<p>What is the biggest integer (in base 10) that you could store in an <code>int32</code> type?</p>
<p><strong>Answer:</strong> 2,147,483,647</p>
</li>
<li>
<p>What is the difference between <code>int16</code> and <code>uint64</code> types (two major differences is enough)?</p>
<p><strong>Answer:</strong><br />
1) <code>int16</code> is only 16 bits storage, whereas <code>uint64</code> is 64 bits storage.<br />
2) <code>int16</code> is a signed integer storage meaning that one bit is reserved for the integer’s sign representation, whereas <code>uint64</code> can only represent positive integers.</p>
</li>
</ol>
<p><a href="http:/MAPCP2019U/quiz/2-values-variables-types">Quiz 2: Value, variables, types</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 26, 2019.</p><![CDATA[Quiz 1: Version control system]]>http:/MAPCP2019U/quiz/1-version-control-system2019-06-18T00:00:00-05:002019-06-18T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<!--
This is the solution to [Quiz 1: Problems - Version control system](1-problems-version-control-system.html){:target="_blank"}.
The following figure illustrates the grade distribution for this quiz.
<figure>
<img src="http:/MAPCP2019U/quiz/gradeDist/gradeHistQuiz1.png" width="700">
<figcaption style="text-align:center">
Maximum possible points is 1.
</figcaption>
</figure>
-->
<p>This quiz aims at testing your basic knowledge of Version Control System. Don’t forget to push your answers to your remote repository by the end of quiz time. Push all your answers to <strong>quiz/1/</strong> folder in your Github project.</p>
<hr />
<hr />
<p><br /></p>
<ol>
<li>
<p>Which of the following Git commands can add all the <strong>new</strong> and <strong>modified-existing</strong> files to the staging area? choose all that apply.<br />
<br />
(A) <code>git add -A</code><br />
(B) <code>git add --A</code><br />
(C) <code>git add -all</code><br />
(D) <code>git add --all</code><br />
(E) <code>git add -u</code><br />
(F) <code>git add .</code><br />
(G) <code>git add .; git add -u</code><br />
(H) <code>git add .; git add --u</code><br />
(I) <code>git add -u; git add .</code><br />
(J) <code>git add --u; git add .</code></p>
<p><strong>Answer: A, D, G, F, I</strong></p>
</li>
<li>
<p>Which of the following Git commands <strong>both</strong> stages and commits <strong>only modified and deleted files</strong> but <strong>NOT</strong> the <em>new files</em> added to the repository since the last commit. Choose all that apply.<br />
<br />
(A) <code>git commit</code><br />
(B) <code>git commit -a</code><br />
(C) <code>git commit -am</code></p>
<p><strong>Answer: B, C</strong></p>
</li>
<li>
<p>Write down the Git command that lists all Git commands for you.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash"> $ git help -a
</code></pre>
</li>
<li>
<p>(A) What is the closest programming language to machine code (i.e., binary code)?</p>
<p><strong>Answer:</strong><br />
Assembly</p>
<p>(B) Does it need interpretation in order to become machine-comprehensible?</p>
<p><strong>Answer:</strong><br />
Yes. An <em>Assembler</em> interprets the program for the machine.</p>
</li>
<li>
<p>(A) Name the oldest high-level programming language that is still in active daily use.</p>
<p><strong>Answer:</strong><br />
Fortran</p>
<p>(B) Approximately how many decades is it old? ($\pm15$ years is acceptable answer. the decade it was created is also an acceptable answer)</p>
<p><strong>Answer:</strong><br />
in 1950s</p>
</li>
<li>
<p>(A) Name a second-generation programming language.</p>
<p><strong>Answer:</strong><br />
Assembly</p>
<p>(B) Which language-generation are Fortran, C, C++, MATLAB, Python, R?</p>
<p><strong>Answer:</strong><br />
third, third, third, fourth, fourth, fourth</p>
</li>
<li>
<p>In what decades C, C++, and MATLAB/Python were created, respectively?</p>
<p><strong>Answer:</strong><br />
1970s, 1980s, 1980s, 1990s</p>
</li>
<li>
<p>Name an ancestor programming language of C.</p>
<p><strong>Answer:</strong><br />
B</p>
</li>
<li>
<p>Name a programming language ancestor of C++.</p>
<p><strong>Answer:</strong><br />
C, Simula</p>
</li>
<li>
<p>Name a programming language ancestor of MATLAB/Python.</p>
<p><strong>Answer:</strong><br />
Fortran/C</p>
</li>
<li>
<p>How would you distinguish exponential behavior vs. power-law behavior (relationship) in a 2-dimensional plot?</p>
<p><strong>Answer:</strong><br />
An exponential curve looks like a line only when the X-axis is plotted on log-scale.<br />
A power-law curve looks like a line only when both the X- and Y- axes are plotted on log-scale.</p>
</li>
</ol>
<p><a href="http:/MAPCP2019U/quiz/1-version-control-system">Quiz 1: Version control system</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 18, 2019.</p><![CDATA[Homework 2: Variables, Values, and Types]]>http:/MAPCP2019U/homework/2-variables-values-types2019-06-18T00:00:00-05:002019-06-18T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>♣ <strong>Due Date: Thursday 27 @ 10:30 AM</strong>. This homework aims at giving you some experience with values, variables, types, and assignments in programming.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>1. </strong> Type the following in the command window and submit the results. Briefly explain what each assignment does.<br />
<br /></p>
<pre><code class="language-matlab">a = 1
b = 'x'
c = true
whos a b c
a == c
a + c
d = [1 2 3 4]
e = ['a' 'b' 'c' 'd']
f = ['a','b','c','d']
g = ['abcd']
h = {‘a’ ‘b’ ‘c’ ‘d’}
i = { a b c d}
whos d e f g h i
class(a)
type(a)
True
true
False
false
</code></pre>
<p><br /></p>
<p><strong>Answer:</strong><br />
In MATLAB:</p>
<pre><code class="language-matlab">a = 1 % assigns value 1 to a
b = 'x' % assigns character 'x' to b
c = true % assigns logical value true to variable c
whos a b c % prints a description of the variables a b c
a == c % evaluates whether a euqals b
a + c % returns sum of a and c
d = [1 2 3 4] % creates a real array
e = ['a' 'b' 'c' 'd'] % creates a string 'abcd'
f = {'a','b','c','d'} % creates a cell array of the input 4 characters
g = ['abcd'] % creates a string 'abcd'
h = {‘a’ ‘b’ ‘c’ ‘d’} % syntax error due to use of undefined characters ‘ and ’
i = { a b c d} % creates a cell array from the four input variables
whos d e f g h i % prints a description of the variables d e f g h i
class(a) % returns the type of the variable a
type(a) % syntax error: input arguments to type() must be character vectors or strings
True % syntax error: undefined variable
true % logical value true in MATLAB
False % syntax error: undefined variable
false % logical value false in MATLAB
</code></pre>
<p>In Python, a lot of the above commands would yield syntax errors, however, many of them can be easily fixed with minor tweaks.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>2. </strong> <strong><a href="https://en.wikipedia.org/wiki/Integer_overflow" target="blank">Overflow</a>.</strong> What would happen if you went beyond the range for a particular type? For example, the largest integer that can be stored in <strong>int8</strong> is 127, and the smallest integer is -128, so what would happen if we type cast a larger integer to the type <strong>int8</strong>? Smaller integer? Use the MATLAB built-in functions <code>intmin</code> and <code>intmax</code> or Python’s numpy package command <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.iinfo.html" target="blank"><code>iinfo</code></a> to find the largest and smallest integers that can be stored in <strong>int16</strong> and <strong>int32</strong>.</p>
<p><strong>Answer:</strong><br />
The resulting behavior is language-dependent. In MATLAB, the overflow and underflow as of today freeze to the largest or smallest possible values that could be represented by that variable type. In python, it leads to rollover or perhaps random value assignments to the variable. Here is the results in MATLAB:</p>
<pre><code class="language-matlab">>> int8(200)
ans =
int8
127
>> int8(-150)
ans =
int8
-128
>> intmax('int16')
ans =
int16
32767
>> intmin('int16')
ans =
int16
-32768
>> intmax('int32')
ans =
int32
2147483647
>> intmin('int32')
ans =
int32
-2147483648
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>3. </strong> <strong><a href="https://en.wikipedia.org/wiki/Order_of_operations" target="blank">Operator Precedence</a>.</strong> Think about what the results would be for the following expressions, and then type them in to the terminal to verify your answers. Briefly explain the results for each one.</p>
<pre><code class="language-matlab">>> 1\2
>> 1/2
>> int8(1/2)
>> int8(1/3)
>> -5^2
>> -5**2
>> (-5) ^ 2
>> (-5) ** 2
>> 10-6/2
>> 5*4/2*3
</code></pre>
<p><br /></p>
<p><strong>Answer:</strong>
Here is the output in MATLAB:</p>
<pre><code class="language-matlab">>> 1\2
ans =
2
>> 1/2
ans =
0.5000
>> int8(1/2)
ans =
int8
1
>> int8(1/3)
ans =
int8
0
>> -5^2
ans =
-25
>> (-5)^2
ans =
25
>> 10-6/2
ans =
7
>> 5*4/2*3
ans =
30
</code></pre>
<p>However, note that the same results would not hold in Python.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>4. </strong> Provide three different methods of generating the matrix <strong>a</strong>, one method should use the <code>diag()</code> function, one should use the <strong>eye</strong> function, and one should use the <strong>zeros</strong> function.</p>
<pre><code class="language-matlab">>> a
a =
2 0 0
0 2 0
0 0 2
</code></pre>
<p><strong>Answer:</strong><br />
Here is the output in MATLAB. Similar results can be achieved in Python, by using the same function names as in MATLAB, but via Python’s <code>numpy</code> package.</p>
<pre><code class="language-matlab">>> a = eye(3,3) * 2
a =
2 0 0
0 2 0
0 0 2
</code></pre>
<pre><code class="language-matlab">>> d = [2 2 2]
d =
2 2 2
>> a = diag(d)
a =
2 0 0
0 2 0
0 0 2
</code></pre>
<p><br /></p>
<pre><code class="language-matlab">>> a = zeros(3,3);
>> a(1,1) = 2;
>> a(2,2) = 2;
>> a(3,3) = 2;
>> a
a =
2 0 0
0 2 0
0 0 2
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>5. </strong> <strong>MATLAB.</strong> Download this <a href="http:/MAPCP2019U/homework/2-problems/matlab_script_full_of_errors.m" target="_blank">code</a>. This code is full syntax errors. Fix the errors and submit the corrected code with name <code>script_full_of_errors_fixed.m</code> in your folder for this HW. Explain in front of each corrected MATLAB statement, why the error occurred. Modify the last two variables so that they display,</p>
<pre><code class="language-matlab">>> Persian
Persian =
Persian is a human language
>> Spanish
Spanish =
'Spanish ' 'is ' ' another' 'language'
</code></pre>
<p><br />
Modify the last line such that for the last line the code displays,</p>
<pre><code class="language-matlab">Persian is not the same as Spanish
</code></pre>
<p><br />
Explain these results.</p>
<p><strong>Answer:</strong><br />
The corrected script can be found <a href="http:/MAPCP2019U/homework/2-solutions/script_full_of_errors_fixed.m" target="_blank">here</a></p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>6. </strong> <strong>Python.</strong> Download <a href="http:/MAPCP2019U/homework/2-problems/python_script_full_of_errors.pi" target="_blank">this Python script</a>. This Python script is full of syntax, runtime, and semantic errors. Please identify and corrent these errors, such that code becomes fully executable and outputs the following message on the screen, when run from the Git Bash command line:</p>
<pre><code class="language-text">The life expectancy for the millennials is projected to be 120 years! (But don't believe it...)
A recent study published in the journal of Nature, discovered that over the past century,
although the life expectancy has significantly increased due to technological advances,
the maximum life span of the oldest people in the world has not changed much.
Cardano was the first to introduce complex numbers of the form a + sqrt(-b) into algebra, but he had misgivings about it.
In his solution to an algebra equation he encountered the solution 5 + sqrt(-15) for the unknown, which is now mathematically represented by
(5+3.872983346207417j)
in Python, which can also be obtained as an addition of real and imaginary numbers in Python like this
5 + sqrt(-15) = (5+3.872983346207417j),
which can also be manually stated as
(5+3.872983346207417j)
One final note:
In python the sqrt function from math and cmath modules are different.
The sqrt function that returns "float" results is sqrt from math module.
Therefore, if using math module, then,
sqrt(25) = 5.0000,
which is obviously a float (real number).
Also note that by convention, 0**0 = 1 in Python.
And division by 0, will give you a runtime exception: 1/0 = NaN
</code></pre>
<p><br />
Identify at least one example in the code for each of the error types.</p>
<p>Here are a few hints:</p>
<ul>
<li>You need to get familiar with string formatting in <code>print</code> function. See <a href="https://www.cdslab.org/ECL2017S/lecture/4-python-values-variables-types" target="_blank">Lecture 4</a>.<br />
<br /></li>
<li>Note that in Python, the interpreter is sensitive to <a href="https://www.python.org/dev/peps/pep-0008/#indentation" target="_blank">indentations</a> in your codes. All lines must be aligned at the beginning (except for looping and branching, … which we will get to them later on).<br />
<br /></li>
<li>Become familiar with <a href="https://python-reference.readthedocs.io/en/latest/docs/str/escapes.html" target="_blank">escape characters</a> in Python, such as <code>'\n'</code>, <code>'\t'</code>, and <code>'\t'</code>.</li>
</ul>
<p><strong>Answer:</strong><br />
The corrected file can be downloaded from <a href="http:/MAPCP2019U/homework/2-solutions/python_script_full_of_errors_corrected.py" target="_blank">here</a>. Examples of different types of programming errors:</p>
<ol>
<li>semantic error example: <br />
<br />
<ul>
<li>line 15, in the wrong script: The purpose is to print the complex number 5+sqrt(-15), but instead 5-15j is printed by the wrong script.<br />
<br /></li>
<li>line 35, in the wrong script: The purpose is to print float number, but since we used <code>sqrt</code> from <code>cmath</code> module, the output is in complex format, which is not what we intend to obtain and print.<br />
<br /></li>
</ul>
</li>
<li>runtime error example:<br />
<br />
<ul>
<li>in line 45, in the wrong script, division by zero, is a runtime exception.<br />
<br /></li>
</ul>
</li>
<li>syntax error example:<br />
Almost any other error in the code is a syntax error. For example, lines 11,12,13 should be aligned, but they are not.</li>
</ol>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>7. </strong> <strong>MATLAB.</strong> Use MATLAB help to find out how you can create a new directory named <code>mynewdir</code> from MATLAB command line. Then change the working directory the newly created directory. Then create a MATLAB script in this directory named <code>myscript.m</code> with the following code in it,</p>
<pre><code class="language-matlab">% First create an array from -2*pi to 2:pi
x = -2*pi:pi/20:2*pi;
% Calculate |sin(x)|
y = abs(sin(x));
plot(x,y);
</code></pre>
<p><br />
Now on MATLAB command line, run the script by calling its name. What do you get? Save the output as a figure and submit it with your homework.</p>
<p><strong>Answer:</strong></p>
<p>You can create a new directory and switch the current directory to it using the following commands,</p>
<pre><code class="language-bash">>> mkdir mynewdir
>> cd mynewdir
</code></pre>
<p><br />
The script <code>myscript</code> generates a plot of $y$ versus $x$ where $y = |sin(x)|$. In doing so, MATLAB opens a new window called <strong>plot window</strong> that contains the plot of y as a function of x. Here is the resulting figure:</p>
<figure>
<img src="http:/MAPCP2019U/homework/2-solutions/plot.png" width="900" />
</figure>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>8. </strong> <strong>MATLAB.</strong> Now change your working directory to the original directory before you created <code>mynewdir</code> directory. Try to run the script <code>myscript</code> you had created again, from MATLAB command line. What do you get? and why?</p>
<p><strong>Answer:</strong></p>
<p>You get an error message like the following,</p>
<pre><code class="language-matlab">>> cd mynewdir\
>> myscript
>> cd ..
>> myscript
Undefined function or variable 'myscript'.
</code></pre>
<p><br />
And this happens because the script we are trying to run is neither in MATLAB’s working directory, nor in any of MATLAB’s search paths. Therefore, MATLAB gives an error, as it cannot find the requested file.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>9. </strong> <strong>Python</strong> Write a Python script that is directly executable from the Git Bash command line, without any need to invoke <code>python</code> interpreter. The script should produce <strong>exactly</strong> the following output, including line breaks and separations. Each part of the output (separated by a line-break, or a new-line character <code>'\n'</code> from the rest) is generated by <strong>only and only one call</strong> to print function.</p>
<pre><code class="language-text">This is Python version 3.5.2
Python is the best language for String manipulation!
!noitalupinam gnirtS rof egaugnal tseb eht si nohtyP
!otlpnmgit o gunlte h inhy
pYTHON IS THE BEST LANGUAGE FOR sTRING MANIPULATION!
The sentence 'Python is the best language for String manipulation!' contains
4 'a' letters, and
0 'A' letters!
Python
is
the
best
language
for
String
manipulation!
PYTHON
IS
THE
BEST
LANGUAGE
FOR
STRING
MANIPULATION!
</code></pre>
<p><br /></p>
<p>Here are some hints (all the information you need to answer this question can be found in the lecture notes):</p>
<ul>
<li>To make the script executable, add the appropriate shebang to the script’s file.<br />
<br /></li>
<li>Import the appropriate module to get the python version command, as we did in class. Use <code>print</code> function to print the Python version.<br />
<br /></li>
<li>Define a String variable <code>my_string</code> which contains the string value “Python is the best language for String manipulation!” ( Of course, you can totally accomplish this question without defining a string variable, by only using the string value itself wherever needed… This is also totally fine at this point in our course, if your prefer this method).<br />
<br /></li>
<li>Then use the appropriate examples and external links provided in the lecture notes, to find the proper <strong>string methods</strong> that can manipulate this string variable/value in order to generate each of the outputs printed above.<br />
<br /></li>
<li>Again, note that for each output, the entire output must result from <strong>one single call</strong> to function <code>print</code>.<br />
<br /></li>
<li>Wherever needed, use the <a href="https://python-reference.readthedocs.io/en/latest/docs/str/escapes.html" target="_blank">escape character</a> value <code>'\n'</code> in <code>print</code> input arguments, in order to generate a line-break (or new line) in the output.</li>
</ul>
<p><strong>Answer:</strong><br />
A working Python script file can be downloaded from <a href="http:/MAPCP2019U/homework/2-solutions/bashExecutable.py" target="_blank">here</a>.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>10. </strong> The bell-shaped <a href="https://en.wikipedia.org/wiki/Normal_distribution" target="_blank">Gaussian probability density function</a>,</p>
<script type="math/tex; mode=display">f(x)=\frac{1}{\sqrt{2\pi}\sigma}\exp\bigg[ -\frac{1}{2}\bigg( \frac{x-\mu}{\sigma} \bigg)^2 \bigg]</script>
<p><br />
is one of the most widely used functions in science and technology. The parameters of the function (mu,sigma>0) are prescribed real numbers. Write a program for evaluating this function when $\mu=0$, $\sigma=2$, $x = 1$.</p>
<p><strong>Hint:</strong> The value <code>pi</code>, and <code>exp()</code> , <code>sqrt()</code> function are built-in in MATLAB, but are not so in Python. You will need to export them using the following command in Python,</p>
<pre><code class="language-python">from math import pi, exp, sqrt
</code></pre>
<p><br />
Verify your answer by getting the same result from <a href="https://www.wolframalpha.com/" target="_blank">Wolfram Alpha</a> mathematical search engine.</p>
<p><strong>Answer:</strong><br />
A version of the code in Python can be downloaded from <a href="http:/MAPCP2019U/homework/2-solutions/gaussian.py" target="_blank">here</a>.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>11. </strong> <strong>Python.</strong> Download <a href="http:/MAPCP2019U/homework/2-problems/script_full_of_errors.py" target="_blank">this code</a>. This code is full syntax errors. Fix the errors and submit the corrected code with name <code>script_full_of_errors_corrected.py</code> in your hw4 folder of your project. Explain in front of each corrected Python statement, why the error occurred. On the last line of the script,</p>
<pre><code class="language-python">true = fox is rev in Persian
</code></pre>
<p><br />
the statement runs without error. But can you explain what it does? (Hint: For this part you need to understand operation precedence. You can find more information <a href="https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html" target="_blank">here</a>.</p>
<p><strong>Answer:</strong><br />
The corrected file can be downloaded from <a href="http:/MAPCP2019U/homework/2-solutions/script_full_of_errors_corrected.py" target="_blank">here</a>.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>12. </strong> As an egg cooks, the proteins first denature and then coagulate. When the temperature exceeds a critical point, reactions begin and proceed faster as the temperature increases. In the egg white, the proteins start to coagulate for temperatures above $63^\circ\rm{C}$, while in the yolk the proteins start to coagulate for temperatures above $70^\circ\rm{C}$. For a soft boiled egg, the white needs to have been heated long enough to coagulate at a temperature above $63^\circ\rm{C}$, but the yolk should not be heated above $70^\circ\rm{C}$. For a hard boiled egg, the center of the yolk should be allowed to reach $70^\circ\rm{C}$.</p>
<p>The following formula expresses the time $t$ it takes (in seconds) for the center of the yolk to reach the temperature Ty (in Celsius degrees):</p>
<script type="math/tex; mode=display">t = \frac
{ M^{2/3} ~ c ~ \rho^{1/3} }
{ K\pi^2 ~ (4\pi/3)^{2/3} }
~\ln
\bigg[
0.76 \frac{T_0 - T_w}{T_y-T_w}
\bigg]</script>
<p><br />
where $M$ is the mass of egg, $\rho$ is the density, $c$ is the specific heat capacity, and $K$ is thermal conductivity. Relevant values are $M=47~[g]$ for a small egg and $M=67~[g]$ for a large egg, $\rho=1.038 ~[g~cm^{-3}]$, $c = 3.7 ~[J~g^{-1}~K^{-1}]$, and $K = 5.4\times10^{-3} ~[Wcm^{-1}K^{-1}]$. Furthermore, $T_w$ is the temperature
(in C degrees) of the boiling water, and $T_0$ is the original temperature (in C degrees) of the egg before being put in the water. Implement the formula in a Python/MATLAB program, set $T_w = 100^\circ C$ and $T_y = 70^\circ C$, and compute $t$ for a large egg taken from the fridge ($T_0 = 4^\circ C$) and from room temperature ($T_0 = 20^\circ C$). (<strong>Hint</strong>: Note that for this problem you will need to import <code>log, pi</code> from <code>math</code> module in Python, but these are intrinsic in MATLAB.)</p>
<p><strong>Answer:</strong><br />
A version of the code can be downloaded from <a href="http:/MAPCP2019U/homework/2-solutions/egg.py" target="_blank">here</a>.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>13. Python: Aliasing vs. Copying variables.</strong> Run the following python statements and briefly explain why you get the behavior printed by the <code>print</code> functions.</p>
<p>(A)</p>
<pre><code class="language-python">a = 5
b = a
print (id(a), id(b))
c = b
b = 3
print (a,b,c)
print (id(a),id(b),id(c))
b = a
b = 5
print (id(a), id(b))
</code></pre>
<p><br />
(B)</p>
<pre><code class="language-python">a = [5]
b = a
print (id(a), id(b))
b.append(1)
print a,b
print (id(a),id(b))
</code></pre>
<p><br />
(C)</p>
<pre><code class="language-python">a = [5]
b = list(a)
print (a,b)
print (id(a), id(b))
b = a[:]
print (a,b)
print (id(a), id(b))
</code></pre>
<p><br />
(D)</p>
<pre><code class="language-python">a = (5,)
b = tuple(a)
print (id(a), id(b))
b = a[:]
print (id(a), id(b))
</code></pre>
<p><strong>Answer:</strong></p>
<p>(A)</p>
<pre><code class="language-python"># Assign a value to a new variable
a = 5
# Create an alias identifier for this variable
b = a
# Observe how they refer to the same variable!
print (id(a), id(b))
# Create another alias
c = b
# Now assign a new value to b!
b = 3
# And observe how a and c are still the same variable
# But b is not
print (a,b,c)
print (id(a),id(b),id(c))
# Now for another quirk, suppose we do this:
b = a
b = 5
# We used an assignment, but the value didn't actually change
# So the alias remains unbroken
print (id(a), id(b))
</code></pre>
<p><br />
(B)</p>
<pre><code class="language-python"># Create a new <list>
a = [5]
# Create an alias identifier for this list
b = a
print (id(a), id(b))
# Now change the <list> b in-place
b.append(1)
# And observe how this also changes a
# The alias is not broken by in-place operations
print (a,b)
print (id(a),id(b))
</code></pre>
<p><br />
(C)</p>
<pre><code class="language-python"># Create a <list>
a = [5]
# Create a new <list> with the same value
b = list(a)
# We now have two separate variables with identical but separate values
print (a,b)
print (id(a), id(b))
# Same with the full slice technique:
b = a[:]
print (a,b)
print (id(a), id(b))
</code></pre>
<p><br />
(D)</p>
<pre><code class="language-python"># Create <tuple>
a = (5,)
# Try to force a copy
b = tuple(a)
# It didn't work...
print (id(a), id(b))
# Neither does this
b = a[:]
print (id(a), id(b))
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>14. Python.</strong> The following is the name list of all people in our class.</p>
<pre><code class="language-text">Christian-Andrew Bagby-wright
Matthew Chrysler
Niyousha Davachi
Pauline Dredger
Marcos Guillen
Lauren Kuffel
Shashank Kumbhare
Hany Mahdy
Sarah Moorman
Andrew Myers
Joshua Osborne
Rebecca Proni
Amir Shahmoradi
Carolina Vedovato
</code></pre>
<p><br />
We want to create a dictionary of members of this class with individuals’ full names serving as dictionary keys, and their roles in class as the corresponding values of the keys. The naive way of generating this dictionary would be to use one of the methods for generating dictionary discussed in the lecture notes. For example,</p>
<pre><code class="language-python">class_dict = {
, 'Christian-Andrew Bagby-wright' : 'student'
, 'Matthew Chrysler' : 'student'
, 'Niyousha Davachi' : 'student'
, 'Pauline Dredger' : 'student'
, 'Marcos Guillen' : 'student'
, 'Lauren Kuffel' : 'student'
, 'Shashank Kumbhare' : 'student'
, 'Hany Mahdy' : 'student'
, 'Sarah Moorman' : 'student'
, 'Andrew Myers' : 'student'
, 'Joshua Osborne' : 'student'
, 'Rebecca Proni' : 'student'
, 'Amir Shahmoradi' : 'instructor'
, 'Carolina Vedovato' : 'student'
}
</code></pre>
<p><br />
However, the problem is that, except me (Amir, the instructor), everyone else has a student role in this class. So it would be a very painful process to type all ‘student’ values by hand manually. Now, the goal is to come up with a shortcut method that avoids the aforementioned problem. Can you find a way of creating this dictionary, without having to type the value ‘student’ 14 times? Note that in order to achieve this, you don’t need anything beyond what you learned in the lecture notes. (<strong>Hint:</strong> Have a look at the section for simultaneous assignments in the lecture notes.)</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-python">class_dict = { 'amir shahmoradi' : 'instructor'
}
</code></pre>
<pre><code class="language-python">class_dict
</code></pre>
<pre><code>{'amir shahmoradi': 'instructor'}
</code></pre>
<pre><code class="language-python">class_dict[ 'Christian-Andrew Bagby-wright' ] = \
class_dict[ 'Matthew Chrysler' ] = \
class_dict[ 'Niyousha Davachi' ] = \
class_dict[ 'Pauline Dredger' ] = \
class_dict[ 'Marcos Guillen' ] = \
class_dict[ 'Lauren Kuffel' ] = \
class_dict[ 'Shashank Kumbhare' ] = \
class_dict[ 'Hany Mahdy' ] = \
class_dict[ 'Sarah Moorman' ] = \
class_dict[ 'Andrew Myers' ] = \
class_dict[ 'Joshua Osborne' ] = \
class_dict[ 'Rebecca Proni' ] = \
class_dict[ 'Carolina Vedovato' ] = 'student'
</code></pre>
<pre><code class="language-python">class_dict
</code></pre>
<pre><code>{'amir shahmoradi': 'instructor',
'Christian-Andrew Bagby-wright': 'student',
'Matthew Chrysler': 'student',
'Niyousha Davachi': 'student',
'Pauline Dredger': 'student',
'Marcos Guillen': 'student',
'Lauren Kuffel': 'student',
'Shashank Kumbhare': 'student',
'Hany Mahdy': 'student',
'Sarah Moorman': 'student',
'Andrew Myers': 'student',
'Joshua Osborne': 'student',
'Rebecca Proni': 'student',
'Carolina Vedovato': 'student'}
</code></pre>
<pre><code class="language-python">type(class_dict)
</code></pre>
<pre><code>dict
</code></pre>
<p>Later on, we will learn more effective methods of constructing this dictionary using Python’s for-loops.</p>
<p><a href="http:/MAPCP2019U/homework/2-variables-values-types">Homework 2: Variables, Values, and Types</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 18, 2019.</p><![CDATA[Homework 1: Version Control Using Git and Github]]>http:/MAPCP2019U/homework/1-version-control-using-git-github2019-06-18T00:00:00-05:002019-06-18T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<!--
The following figure illustrates the grade distribution for this homework.
<figure>
<img src="http:/MAPCP2019U/homework/gradeDist/gradeHistHomework1.png" width="700">
<figcaption style="text-align:center">
Maximum possible points, excluding bonus questions, is 1.<br>
Maximum possible points, including bonus questions, is 1.5.
</figcaption>
</figure>
-->
<p>♣ <strong>Due Date: One week from the posting date @ 10:30 AM</strong>. This homework aims at giving you some experience on how to create Git branches, develop your project on multiple branches, merge them, resolve potential conflicts between different branches upon merging, and finally how to delete them. It also gives you some experience with using other commonly-used Git commands.</p>
<hr />
<hr />
<p><br /></p>
<p>First, use the following Markdown language references, or any other reference that you find or prefer, to design a Github-interpretable README file for each of folders in your project for this course, and a Github web-page for your project.</p>
<ul>
<li><a href="http:/MAPCP2019U/lecture/1/markdown-cheatsheet-online.pdf" target="_blank">Markdown language cheat-sheet (pdf)</a></li>
<li><a href="https://blog.ghost.org/markdown/" target="_blank">Markdown language reference (web)</a></li>
<li><a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">Adam Pritchard’s Markdown cheat-sheet (web)</a></li>
</ul>
<p>Write your code sections of your answer in Markdown syntax.
For example,<br />
<code>
```bash <br />
$ git branch -d test <br />
error: Cannot delete branch 'test' checked out at 'C:/Users/Amir/git/foo' <br />
```
</code>
<br />
will display the following text highlighted as <em>bash</em> code, in your <em>readme.md</em> file.</p>
<pre><code class="language-bash">$ git branch -d test
error: Cannot delete branch 'test' checked out at 'C:/Users/Amir/git/foo'
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>1.</strong> Include the following information with the following format and information in your main directory <code>readme.md</code> file:</p>
<h2 id="beginning-of-the-readme-files-content"><em>Beginning of the README file’s content</em></h2>
<hr />
<p><br /></p>
<h4 id="mapcp2019u---introduction-to-computer-programming-summer-2019">MAPCP2019U - Introduction to Computer Programming (Summer 2019)</h4>
<p><br />
<strong>Name:</strong> <first name> <last name><br />
<strong>UTA EID:</strong> <your UTA EID><br />
<strong>Email:</strong> <your email><br />
<strong>Department:</strong> <a href="https://www.uta.edu/physics/">Department of Physics</a><br />
<strong>University:</strong> <a href="https://www.utexas.edu/">The University of Texas at Arlington</a><br />
<strong>Level:</strong> graduate - <Freshman (1st year) / Sophomore (2nd year) / Junior (3rd year) / Senior (4th year) / Dinosaur (5th year and above) ><br />
<strong>MAPCP-Class Title:</strong> Student<br />
<strong>Course Webpage:</strong> <a href="https://www.cdslab.orghttp:/MAPCP2019U/">https://www.cdslab.orghttp:/MAPCP2019U/</a><br />
<strong>Photo:</strong></p>
<p><img src="http:/MAPCP2019U/images/AmirShahmoradi.png" alt="Amir Shahmoradi" /></p>
<h4 id="description-of-the-projects-content">Description of the project’s content</h4>
<p><br /> This repository contains my homework, quizzes, and virtually every effort that I have made for <a href="https://www.cdslab.orghttp:/MAPCP2019U/">MAPCP2019U class</a>. The structure of the project is the following:</p>
<ul>
<li><strong><a href="#homework">homework</a>:</strong> (the homework hyperlink should take the reader to the homework folder)<br />
This directory contains all my homework submissions, each of which is a folder properly named with homework number, containing the homework submission.<br />
<br /></li>
<li><strong><a href="#quiz">quiz</a>:</strong> (the quiz hyperlink should take the reader to the quizzes folder)<br />
This directory contains all my quiz submissions, each of which is a folder properly named with quiz number, containing the quiz submission.<br />
<br /></li>
<li><strong><a href="#exam">exam</a>:</strong> (the exam hyperlink should take the reader to the exams folder)<br />
This directory contains all my exam submissions, each of which is a folder properly named with exam name or number, containing the exam submission.<br />
<br /></li>
</ul>
<p>For questions and troubleshooting, please contact:</p>
<p><your name><br />
<your email><br />
<any other contact or signature information that you would like to add></p>
<blockquote>
<p>I have not failed. I’ve just found 10,000 ways that won’t work.<br />
<a href="https://en.wikipedia.org/wiki/Thomas_Edison" target="_blank">Thomas A. Edison</a></p>
</blockquote>
<p><br /></p>
<hr />
<h2 id="end-of-the-readme-files-content"><em>End of the README file’s content</em></h2>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>Answer:</strong></p>
<hr />
<p><strong>Use the following Markdown code in your <code>readme.md</code> file to get the exact same behavior as requested above:</strong></p>
<pre><code class="language-markdown">#### MAPCP2019U - Introduction to Computer Programming (Summer 2019)
<br>
**Name:** \<first name> \<last name>
**UT EID:** \<your UTA EID>
**Email:** \<your email>
**Department:** [Department of Physics](https://www.uta.edu/physics/)
**University:** [The University of Texas at Arlington](https://www.utexas.edu/)
**Level:** graduate - \<Freshman (1st year) / Sophomore (2nd year) / Junior (3rd year) / Senior (4th year) / Dinosaur (5th year and above) >
**MAPCP-Class Title:** Student
**Course Webpage:** <https://www.cdslab.orghttp:/MAPCP2019U/>
**Photo:**
![Amir Shahmoradi](../../images/AmirShahmoradi.png)
#### Description of the project's content
<br> This repository contains my homework, quizzes, and virtually every effort that I have made for [MAPCP2019U class](https://www.cdslab.orghttp:/MAPCP2019U/). The structure of the project is the following:
* **[homework](#homework):** (the homework hyperlink should take the reader to the homework folder)
This directory contains all my homework submissions, each of which is a folder properly named with homework number, containing the homework submission.
<br>
* **[quiz](#quiz):** (the quiz hyperlink should take the reader to the quizzes folder)
This directory contains all my quiz submissions, each of which is a folder properly named with quiz number, containing the quiz submission.
<br>
* **[exam](#exam):** (the exam hyperlink should take the reader to the exams folder)
This directory contains all my exam submissions, each of which is a folder properly named with exam name or number, containing the exam submission.
<br>
For questions and troubleshooting, please contact:
\<your name>
\<your email>
\<any other contact or signature information that you would like to add>
>I have not failed. I've just found 10,000 ways that won't work.
>[Thomas A. Edison](https://en.wikipedia.org/wiki/Thomas_Edison){:target="_blank"}
</code></pre>
<p><br />
<strong>Note that you will have to change the relevant information and hyper-references in the above Mardown code to those that match your own information in your own repository (including your own photo).</strong></p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>2. </strong> Create two additional test branches in your project, each of which is branched directly from <em>master</em>. <strong>For each of the following cases, write the command and the corresponding output message of Git, in Markdown language in a <code>readme.md</code> file inside your <code>homework/1/</code> folder in your master branch</strong>. If you don’t have this folder in your project, then create the folder and then place your initial <code>readme.md</code> file in this folder with your signature as the content of the file. Then stage and commit this file together with homework-1 folder to your local repository. Throughout the rest of this homework, you will fill this <code>readme.md</code> file with your answers.</p>
<p>(A) Create two branches, <strong>both from your <em>master</em> branch</strong>, with names <em>test1</em> and <em>test2</em>.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git branch
* master
$ git branch test1
$ git branch test2
$ git branch
* master
test1
test2
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(B) Now checkout the <em>test1</em> branch and create a new text file named <code>test.txt</code> in the <code>homework/1/</code> directory of this branch.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout test1
Switched to branch 'test1'
$ git status
On branch test1
nothing to commit, working tree clean
$ ls
readme.md
$ touch test.txt
$ ls
readme.md test.txt
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(C) Inside <code>test.txt</code> in <em>test1</em> branch write this message: <em>This is some example text for branch test1</em>, and save it.</p>
<p><strong>Answer:</strong></p>
<p>Use <code>vim test.txt</code> to open <em>vim</em> editor. Press <code>shift + I</code> to switch to <em>vim insert mode</em>. write <em>This is some example text for branch test1</em> in <code>test.txt</code> file. Now, Press <code>ESC</code> key and write <code>:wq</code> on the <em>vim</em> command line to save the file and quit <em>vim</em>.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(D) Now stage and commit <code>test.txt</code> file to branch <em>test1</em>.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git status
On branch test1
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add --all
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
$ git commit -m"commiting the test.txt file in test1 branch"
[test1 715ca59] commiting the test.txt file in test1 branch
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ git status
On branch test1
nothing to commit, working tree clean
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(E) Checkout the branch <em>test2</em>. Do you still see <code>test.txt</code> that you just created in your <code>homework/1/</code> directory? You can search for it by the <em>bash</em> command <code>ls</code>. Explain why you see/don’t see the file in your working directory anymore.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout test2
Switched to branch 'test2'
$ ls
readme.md
</code></pre>
<p><br />
The <code>test.txt</code> files is not in the project’s working directory, since I just chaecked out a new branch <em>test2</em> that does not contain any files that were generated and committed in <em>test1</em> branch.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(F) Create a new text file named <code>test.txt</code> in the <code>homework/1/</code> directory of this branch as well, and add <em>This is some example text for branch test2</em> to its content.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ touch test.txt
$ vim test.txt
$ git status
On branch test2
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
</code></pre>
<p><br />
The procedure for adding content to the file is very similar to that in part (C) of the problem, explained above.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(G) Now try to checkout <em>test1</em>. What error/warning message do you get? Fix the source of error and then checkout <em>test1</em> branch.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout test1
error: The following untracked working tree files would be overwritten by checkout:
test.txt
Please move or remove them before you switch branches.
Aborting
$ git add --all
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
$ git commit -m"commtting the test2 branch changes"
[test2 fce6a94] commtting the test2 branch changes
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ git status
On branch test2
nothing to commit, working tree clean
$ git checkout test1
Switched to branch 'test1'
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(H) Now merge the content of <em>test1</em> with <em>master</em> branch. (Hint: Note from which branch you doing this merge!)</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout master
Switched to branch 'master'
$ ls
readme.md
$ git status
On branch master
nothing to commit, working tree clean
$ git merge test1
Updating a661e87..715ca59
Fast-forward
test.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 test.txt
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(I) Now what do you see as the content of <em>master</em> branch? (Hint: Use <code>ls</code> <em>bash</em> command, to list the files in the working directory.)</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ ls
readme.md test.txt
$ git status
On branch master
nothing to commit, working tree clean
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(J) Now merge the content of <em>test2</em> with <em>master</em> branch. What error/warning message do you get? Why does this error arise?</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git merge test2
Auto-merging test.txt
CONFLICT (add/add): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(K) Now checkout <em>test2</em>. What error/warning message do you get?</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout test2
test.txt: needs merge
error: you need to resolve your current index first
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(L) Run the Git command <code>git status</code>. Why does such a conflict exist, as mentioned in <code>git status</code> output?</p>
<p><strong>Answer:</strong><br />
Basically, by running <code>git merge test2</code> command, we attempted to merge test.txt file of <em>test2</em> branch with the existing <code>test.txt</code> file of <em>master</em> branch. But the content of the two is different.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(M) At this stage, you have two options: Either 1. stage and commit the combined conlifting <code>test.txt</code> file to Git repository (but this is not recommended), or, 2. open the file <code>test.txt</code> using <em>vim</em> editor on the command line and reslve the conflict by editing the content of the file to only this sentence: <em>. Then save and quit *vim</em>.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ vim test.txt
$ cat test.txt
This is some example text from both test1 and test2 branches combined.
</code></pre>
<p><br />
The <em>bash</em> command <code>cat</code> shows the content of <code>text.txt</code> file.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(N) Now, run <code>git status</code>, then stage and commit your conflict-resolved file. Then checkout <em>test2</em> branch.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add test.txt
$ git commit -m"adding the test.txt resolution file"
[master 4c74098] adding the test.txt resolution file
$ git status
On branch master
nothing to commit, working tree clean
$ git checkout test2
Switched to branch 'test2'
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(O) Now, try deleting branch <em>test1</em>, while on branch <em>test2</em>. What error/warning message do you get?</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git branch -d test1
error: The branch 'test1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D test1'.
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(P) Now, switch back to <em>master</em> branch. Now, try deleting branch <em>test1</em>, while on <em>master</em> branch. What message do you get from Git? List all the existing branches using <code>git branch</code> command.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout master
Switched to branch 'master'
$ git branch
* master
test2
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(Q) Why is there such a difference in Git messages between when you tried deleting <em>test1</em> branch from <em>test2</em> branch, and when you tried deleting <em>test1</em> branch from <em>master</em> branch?</p>
<p><strong>Answer:</strong></p>
<p>The difference arises, because whichever branch you are in, Git assumes that the content of any other branch should be first merged for the current branch before deteting the other branch. Therefore, in the first case, Git warns that there is unmerged data between <em>test1</em> and <em>test2</em> branches. But the delete command from <em>master</em> branch gives no error, since the content of <em>test1</em> branch has been previously appropriately merged with <em>master</em> branch.</p>
<p><br /></p>
<hr />
<p><br /></p>
<p>(R) Now checkout <em>test2</em> branch. While on <em>test2</em>, try to delete branch <em>test2</em>. What error/message do you get?</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout test2
Switched to branch 'test2'
$ git branch -d test2
error: Cannot delete branch 'test2' checked out at '~/test'
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(S) Switch back to <em>master</em> and delete <em>test2</em> branch. List all your project branches by the appropriate Git command.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git checkout master
Switched to branch 'master'
$ git branch -d test2
Deleted branch test2 (was fce6a94).
$ git branch
* master
</code></pre>
<p><br /></p>
<hr />
<p><br /></p>
<p>(T) Stage and commit all the changes (including the file <code>test.txt</code>) to your project’s <em>master</em> branch. Now push it all to the remote repository by Wednesday Feb 15 2017, 9:00 a.m. CDT.</p>
<p><strong>Answer:</strong></p>
<pre><code class="language-bash">$ git add --all
$ git commit
On branch master
nothing to commit, working tree clean
$ git push --all
</code></pre>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>3. </strong> (Bonus, not mandatory) Design a simple Github page for your project, using the main directory’s <code>readme.md</code> file. Submit the link to the page as your answer. Note that you don’t need to add anything extra to your readme file.</p>
<p><strong>Answer:</strong><br />
Ask me in class to teach you how to do it.</p>
<p><br /></p>
<hr />
<hr />
<p><br /></p>
<p><strong>4. </strong> (Bonus, not mandatory) Create a website for your project, such that your project is accessible through its web address based on the content of your project’s website, not based on the content of <em>master</em> branch.</p>
<p><strong>Answer:</strong><br />
Ask me in class and I will explain how to do it.</p>
<p><br /></p>
<p><a href="http:/MAPCP2019U/homework/1-version-control-using-git-github">Homework 1: Version Control Using Git and Github</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 18, 2019.</p><![CDATA[Announcement 1: Assessing your programming knowledge and interests]]>http:/MAPCP2019U/announcement/1-assessing-your-programming-knowledge-and-interests2019-06-04T00:00:00-05:002019-06-04T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>The goal of this survey is to assess your prior programming experience and to identify the favorite programming language for this class, as well as the language that your advisor deems essential for your research. Ask Amir to send you a link to the survey if you have not already received it.</p>
<h2 id="survey-results-as-of-june-4-2019">Survey results as of June 4, 2019</h2>
<p>The following are the summaries of the responses to the survey questions. The total number of survey respondents is 10. It appears that at least half of the class, knows at least one programming language at some elementary level. Also it appears that almost everyone in this class is in love with Python!</p>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q2.png" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q3.png" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q4.png" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q5.png" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q6.png" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="http:/MAPCP2019U/announcement/1/Q7.png" width="100%" />
</figure>
</div>
<p><br /></p>
<p><a href="http:/MAPCP2019U/announcement/1-assessing-your-programming-knowledge-and-interests">Announcement 1: Assessing your programming knowledge and interests</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 04, 2019.</p><![CDATA[Announcement 0: Student-professor connection day]]>http:/MAPCP2019U/announcement/0-student-professor-connection-day2019-06-04T00:00:00-05:002019-06-04T00:00:00-05:00Amir Shahmoradihttp:/MAPCP2019Ushahmoradi@utexas.edu
<p>On the first day of our class, we will try to get to know each other and I will attempt to describe my research work and educational background for you, as well as what we should expect from this course. Then I will present the results of the survey that I sent out to you a week ago to assess your programming knowledge, your favorite programming language, and the programming language that you would need for your research. Based on the survey results and your feedback in class, we will decide on the choice of language and the design of this course.</p>
<div class="post_toc"></div>
<h2 id="about-me-amir-the-instructor">About me, Amir, the instructor</h2>
<p>I am a physicist and researcher, and currently a faculty member at <a target="_blank" href="https://www.uta.edu/physics/">the Department of Physics</a> as well as the Data Science Program in <a target="_blank" href="https://www.uta.edu/science/index.php">The College of Science</a> at <a target="_blank" href="https://www.uta.edu/">The University of Texas at Arlington</a>. You can find more information about me, our group, and our research at <a target="_blank" href="https://www.cdslab.org">cdslab.org</a>. Here is a summary of my life in a few pictures:</p>
<p>I was introduced to the world of information and computer programming around 1991 by my father and elder brother. By the end of elementary school, I was so impressed with and knew enough about computer software to write a few simple <a target="_blank" href=" https://en.wikipedia.org/wiki/PC_game">computer games</a> in <a target="_blank" href="https://en.wikipedia.org/wiki/QBasic">QBasic programming language</a> on our first family personal computer, <a target="_blank" href="https://en.wikipedia.org/wiki/IBM_386SLC">IBM 386</a>. Here is an example of how computer games looked liked 30 years ago.</p>
<div class="center">
<div class="video-wrapper">
<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube.com/embed/4TSF5sIgorA" frameborder="0" allowfullscreen=""></iframe>
<!-- <iframe width="853" height="480" src="https://www.youtube.com/embed/0XL8RNxzrdw?rel=0" frameborder="0" allowfullscreen></iframe> -->
</div>
</div>
</div>
<p><br /></p>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="" width="100%" />
<figcaption>A portrait of me at high-school by my friends</figcaption>
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="" width="100%" />
<figcaption>What I imagined I'd do as a physicist</figcaption>
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="" width="100%" />
<figcaption>A scene from my Ph.D. defense</figcaption>
</figure>
</div>
<p>I never imagined a day I would use computer programming for scientific purposes. Nevertheless, there has been almost no single day that I have not used scientific programming for my work and research, ever since I entered graduate school.</p>
<h2 id="my-research-topics">My research topics</h2>
<p>The following are a few examples of what I do nowadays as part of my scientific research at UT Austin.</p>
<h3 id="theoretical-astrophysics">Theoretical Astrophysics</h3>
<p>While my current focus of research is mathematical modelling of tumor growth and Monte Carlo samplers, I am and have been working in multiple branches of science and engineering for several years, from the subatomic world of <a target="_blank" href="https://en.wikipedia.org/wiki/Elementary_particle">elementary particles</a>, to the microscopic world of <a target="_blank" href="https://en.wikipedia.org/wiki/Macromolecule">biological macromolecules</a>, to <a target="_blank" href="https://en.wikipedia.org/wiki/Gamma-ray_burst">astrophysical phenomena</a> occurring on the grandest scales of the <a target="_blank" href="https://en.wikipedia.org/wiki/Observable_universe">observable Universe</a>.</p>
<p>For several years of my research, I have been working on understanding Gamma-Ray Bursts (GRB) and their physics. Below is a movie of the moment a Short-duration GRB is generated from the merger of a binary Neutron star system.</p>
<div class="center">
<div class="video-wrapper">
<div class="video-container">
<iframe width="853" height="480" src="https://www.youtube.com/embed/P2ESs1rPO_A?rel=0" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/astro_1.png" width="100%" />
</figure>
<p><br /></p>
<h3 id="theoretical-biology-bioinformatics">Theoretical Biology, Bioinformatics</h3>
<p>I have also worked for a few years in the field of bioinformatics and evolutionary biology. The overarching goal in the field of protein bioinformatics and biophysics is to understand how proteins fold into their unique structure, and what determines the stability of the protein <abbr title="3-Dimensional">3D</abbr> structure.</p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/bio_1.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/bio_2.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<p>One of the workhorses of this field, is therefore <a href="https://en.wikipedia.org/wiki/Molecular_dynamics" target="_blank">molecular dynamic simulation</a> to probe the dynamics of proteins and their interactions with other molecules. The following is a 1.5ns molecular dynamics simulation of Human Influenza H1 Hemagglutinin protein (<a href="https://www.rcsb.org/pdb/explore.do?structureId=1rd8" target="_blank">1RD8</a>, chains AB).</p>
<div class="center">
<div class="video-wrapper">
<div class="video-container">
<iframe width="853" height="480" src="https://www.youtube.com/embed/0XL8RNxzrdw?rel=0" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
<p><br /></p>
<h3 id="petroleum-engineering">Petroleum Engineering</h3>
<figure>
<img src="https://cdslaborg.github.io/connection/petro_1.png" width="100%" />
</figure>
<p><br /></p>
<h3 id="computational-oncology">Computational Oncology</h3>
<p>What you see in the figures below, is a representation of the growth of Glioblastoma tumor cells in a Rat’s brain over time.</p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/onco_1.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/onco_2.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<figure>
<img src="https://cdslaborg.github.io/connection/onco_3.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<h4 id="the-temporal-evolution-of-the-growth-of-glioma-tumor-in-rat">The temporal evolution of the growth of Glioma tumor in rat</h4>
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_1_t10.0.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/GBGlastLong.gif" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<!--
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_2_t12.0.png" width="100%">
</figure><br>
---
<br>
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_3_t14.0.png" width="100%">
</figure><br>
---
<br>
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_5_t16.0.png" width="100%">
</figure><br>
---
<br>
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_6_t18.0.png" width="100%">
</figure><br>
---
<br>
<figure>
<img src="https://cdslaborg.github.io/connection/tvccZSliceSubplotWithXYlabWithTB_rad_00gy_7_t20.0.png" width="100%">
</figure><br>
-->
<h3 id="monte-carlo-simulation-and-integration-methods">Monte Carlo Simulation and Integration Methods</h3>
<p>One of the fields on which my research is currently focused, is developing Monte Carlo optimizer/sampler and integrator algorithms for Bayesian inverse problems.</p>
<h4 id="development-of-monte-carlo-sampling-algorithms">Development of Monte Carlo sampling algorithms</h4>
<p>Below you see example animations of two <a href="https://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo" target="_blank">Markov Chain Monte Carlo</a> (MCMC) samplers, both of which sample a double Gaussian-peak function, but with different MCMC sampling parameters.</p>
<figure>
<img src="https://cdslaborg.github.io/connection/PDF_RS_H_Forever20ms.gif" width="100%" />
<figcaption style="text-align:center">Example of highly-efficiency, but bad-mixing MCMC sampler.</figcaption>
</figure>
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/PDF_RS_L_Forever20ms.gif" width="100%" />
<figcaption style="text-align:center">Example of low-efficiency, but good-mixing MCMC sampler.</figcaption>
</figure>
<p><br /></p>
<h4 id="development-of-monte-carlo-integration-algorithms">Development of Monte Carlo integration algorithms</h4>
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/DRI.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/DLI.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/GR3D.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/GR2D.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/GR2D.gif" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/EB3D.png" width="100%" />
</figure>
<p><br /></p>
<hr />
<p><br /></p>
<figure>
<img src="https://cdslaborg.github.io/connection/EB2D.gif" width="100%" />
</figure>
<p><br /></p>
<h4 id="biomedical-data-science">Biomedical Data Science</h4>
<p><br /></p>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="" width="100%" />
</figure>
</div>
<!-- include.path must be given relative to site.url, which is the project's root directory -->
<div style="display:block;text-align:center;margin-right:auto;margin-left:auto">
<figure>
<img src="" width="100%" />
</figure>
</div>
<p><br /><br /></p>
<p><a href="http:/MAPCP2019U/announcement/0-student-professor-connection-day">Announcement 0: Student-professor connection day</a> was originally published by Amir Shahmoradi at <a href="http:/MAPCP2019U">PHYS 6302 - Summer 2019 - TTH 10:30-12:30 - Life Sciences Building LS 102</a> on June 04, 2019.</p>