diff --git a/HW2/README.md b/HW2/README.md new file mode 100644 index 0000000..f74173b --- /dev/null +++ b/HW2/README.md @@ -0,0 +1,36 @@ +# Homework #2 +## due 2/3/17 + +1. Now that you have created your own repository, 'homework_1', that has a README.md file. +Create a new file in this repository called `setdefaults.m`. This file is a matlab/octave +script that will set default plotting parameters. In this file, add the following lines: + + ```matlab + set(0, 'defaultAxesFontSize', 16) + set(0,'defaultTextFontSize',14) + set(0,'defaultLineLineWidth',3) + ``` + + Commit the changes to your repository. + + ![projectile(v_mag,theta) predicts the height of the projectile based upon initial +velocity and position, as see in the Figure](projectile.png) + +2. Clone your 'homework_1' repository to your own computer. Now, we want to create a +function that uses kinematic formulas to predict the path of a projectile. The dimensions +are taken from official dart board dimensions +[darts](http://dartbrokers.com/dartboard-height.html). Create a function, +`projectile.m` that will calculate the location of an object with an initial velocity. The +function inputs are v_mag (initial speed), theta (initial angle). The output is the height +of the object 2.37 m from its starting position. Assume g=9.81 m/s^2 and its initial +height is 1.72 m. + + ```matlab + >> h=projectile(v_mag,theta) + + h= 1 + ``` + + In addition to the output of `h`-height at 2.37 m-plot the path of the object from its + initial position to its position at 2.37 m away from the start. *Note: use your + `setdefaults.m` to set the plot defaults before outputting the result.* diff --git a/HW2/projectile.png b/HW2/projectile.png new file mode 100644 index 0000000..f544224 Binary files /dev/null and b/HW2/projectile.png differ diff --git a/HW2/projectile.svg b/HW2/projectile.svg new file mode 100644 index 0000000..bb33043 --- /dev/null +++ b/HW2/projectile.svg @@ -0,0 +1,331 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + 2.37 m + + + + v_mag + theta + + h + + 1.72 m + + diff --git a/README.md b/README.md index eebd665..8059993 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,20 @@ matlab/octave functions and programming best practices. ## Teaching Assistants: - Graduate: Peiyu Zhang -- Office hours: 2 hours / week +- Office hours: Friday 9:00-11:00am in Engineering II room 315 +## Course Information **Prerequisite:** CE 3110, MATH 2410Q **Textbook:** Chapra, Steven, *Applied Numerical Methods with MATLAB for Engineers and Scientists* 3rd edition. +**Tools used:** [Matlab](https://www.mathworks.com/products/matlab.html), +[Octave](https://www.gnu.org/software/octave/) , [Github](https://github.com). + +**Recommended tools:** Github Desktop, git, Atom (text editor), Vim (text editor), +Jupiter notebook (with matlab or octave kernel) + ## Grading | Item | Percent | Requirement | diff --git a/lecture_05/.ipynb_checkpoints/lecture_05-checkpoint.ipynb b/lecture_05/.ipynb_checkpoints/lecture_05-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/lecture_05/.ipynb_checkpoints/lecture_05-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/lecture_05/lecture_05.ipynb b/lecture_05/lecture_05.ipynb new file mode 100644 index 0000000..c04b9f5 --- /dev/null +++ b/lecture_05/lecture_05.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good coding habits\n", + "## naming folders and files" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[Stanford file naming best practices](https://library.stanford.edu/research/data-management-services/data-best-practices/best-practices-file-naming)\n", + "\n", + "1. Include information to distinguish file name e.g. project name, objective of function, name/initials, type of data, conditions, version of file, \n", + "2. if using dates, use YYYYMMDD, so the computer organizes by year, then month, then day\n", + "3. avoid special characters e.g. !, #, \\$, ...\n", + "4. avoid using spaces if not necessary, some programs consider a space as a break in code use dashes `-` or underscores `_` or CamelCase" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Commenting your code" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Its important to comment your code to mention what a variable's units are, what the function is supposed to do, etc. \n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "function i=code(j)\n", + " % Example of bad variable names and bad function name\n", + " for w=1:j\n", + " i(w)=w;\n", + " end\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'code' is a command-line function\n", + "\n", + " Example of bad variable names and bad function name\n", + "\n", + "\n", + "Additional help for built-in functions and operators is\n", + "available in the online version of the manual. Use the command\n", + "'doc ' to search the manual index.\n", + "\n", + "Help and information about Octave is also available on the WWW\n", + "at http://www.octave.org and via the help@octave.org\n", + "mailing list.\n" + ] + } + ], + "source": [ + "help code" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Choose variable names that describe the variable" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "function count_vector=counting_function(max_value)\n", + " % Good variable names and better help documentation\n", + " % \n", + " % counting function creates a vector from 1 to max_value where each index, i, is \n", + " % stored in each vector spot\n", + " for i=1:max_value\n", + " count_vector(i)=i; % set each element in count_vector to i\n", + " end\n", + "end " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'counting_function' is a command-line function\n", + "\n", + " Good variable names and better help documentation\n", + " \n", + " counting function creates a vector from 1 to max_value where each index, i, is \n", + " stored in each vector spot\n", + "\n", + "\n", + "Additional help for built-in functions and operators is\n", + "available in the online version of the manual. Use the command\n", + "'doc ' to search the manual index.\n", + "\n", + "Help and information about Octave is also available on the WWW\n", + "at http://www.octave.org and via the help@octave.org\n", + "mailing list.\n" + ] + } + ], + "source": [ + "help counting_function" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Putting it all together" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Clone your homework_1 to your computer\n", + "2. open Matlab (cli, jupyter or gui)\n", + "3. Change working directory to homework_1 *e.g.* Windows:`cd('C:\\Users\\rcc02007\\Documents\\Github\\homework_1')`, Mac: `cd('/Users/rcc02007/Documents/Github/homework_1')`\n", + "4. You have already created your first script `myscript.m` (if not see lecture_4)\n", + "5. Run `>> my_script.m`\n", + "6. Create a new m-file called nitrogen_pressure.m\n", + "7. Create a function based upon the ideal gas law for nitrogen, Pv=RT\n", + " 1. R=0.2968 kJ/(kg-K)\n", + " 2. inputs to function are v (specific volume m^3/kg), and T, temperature (K)\n", + " 3. output is P, pressure (kPa)\n", + "8. Once the function works, commit the change to the repository (add a message, like 'added file nitrogen_pressure.m'\n", + "9. After file is 'committed', 'push' the changes to your github account\n", + "\n", + "for the command-line git user, this is steps 8 and 9:\n", + "1. `$ git add *`\n", + "2. `$ git commit -m 'added file nitrogen_pressure.m'`\n", + "3. `$ git push -u origin master\n", + " Username for 'https://github.uconn.edu':rcc02007 \n", + " Password for 'https://rcc02007@github.uconn.edu': `\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Octave", + "language": "octave", + "name": "octave" + }, + "language_info": { + "file_extension": ".m", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "octave", + "version": "0.19.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/lecture_05/lecture_05.md b/lecture_05/lecture_05.md new file mode 100644 index 0000000..e0bea24 --- /dev/null +++ b/lecture_05/lecture_05.md @@ -0,0 +1,110 @@ + +# Good coding habits +## naming folders and files + +[Stanford file naming best practices](https://library.stanford.edu/research/data-management-services/data-best-practices/best-practices-file-naming) + +1. Include information to distinguish file name e.g. project name, objective of function, name/initials, type of data, conditions, version of file, +2. if using dates, use YYYYMMDD, so the computer organizes by year, then month, then day +3. avoid special characters e.g. !, #, \$, ... +4. avoid using spaces if not necessary, some programs consider a space as a break in code use dashes `-` or underscores `_` or CamelCase + +## Commenting your code + +Its important to comment your code to mention what a variable's units are, what the function is supposed to do, etc. + + + +```octave +function i=code(j) + % Example of bad variable names and bad function name + for w=1:j + i(w)=w; + end +end +``` + + +```octave +help code +``` + + 'code' is a command-line function + + Example of bad variable names and bad function name + + + Additional help for built-in functions and operators is + available in the online version of the manual. Use the command + 'doc ' to search the manual index. + + Help and information about Octave is also available on the WWW + at http://www.octave.org and via the help@octave.org + mailing list. + + +## Choose variable names that describe the variable + + +```octave +function count_vector=counting_function(max_value) + % Good variable names and better help documentation + % + % counting function creates a vector from 1 to max_value where each index, i, is + % stored in each vector spot + for i=1:max_value + count_vector(i)=i; % set each element in count_vector to i + end +end +``` + + +```octave +help counting_function +``` + + 'counting_function' is a command-line function + + Good variable names and better help documentation + + counting function creates a vector from 1 to max_value where each index, i, is + stored in each vector spot + + + Additional help for built-in functions and operators is + available in the online version of the manual. Use the command + 'doc ' to search the manual index. + + Help and information about Octave is also available on the WWW + at http://www.octave.org and via the help@octave.org + mailing list. + + +## Putting it all together + +1. Clone your homework_1 to your computer +2. open Matlab (cli, jupyter or gui) +3. Change working directory to homework_1 *e.g.* Windows:`cd('C:\Users\rcc02007\Documents\Github\homework_1')`, Mac: `cd('/Users/rcc02007/Documents/Github/homework_1')` +4. You have already created your first script `myscript.m` (if not see lecture_4) +5. Run `>> my_script.m` +6. Create a new m-file called nitrogen_pressure.m +7. Create a function based upon the ideal gas law for nitrogen, Pv=RT + 1. R=0.2968 kJ/(kg-K) + 2. inputs to function are v (specific volume m^3/kg), and T, temperature (K) + 3. output is P, pressure (kPa) +8. Once the function works, commit the change to the repository (add a message, like 'added file nitrogen_pressure.m' +9. After file is 'committed', 'push' the changes to your github account + +for the command-line git user, this is steps 8 and 9: + +1. `$ git add *` +2. `$ git commit -m 'added file nitrogen_pressure.m'` +3. `$ git push -u origin master + Username for 'https://github.uconn.edu':rcc02007 + ` + + + +```octave + +``` diff --git a/lecture_05/lecture_05.pdf b/lecture_05/lecture_05.pdf new file mode 100644 index 0000000..b125659 Binary files /dev/null and b/lecture_05/lecture_05.pdf differ diff --git a/lecture_05/octave-workspace b/lecture_05/octave-workspace new file mode 100644 index 0000000..1ca4b38 Binary files /dev/null and b/lecture_05/octave-workspace differ