diff --git a/03_Intro to matlab-octave/.ipynb_checkpoints/lecture_03-checkpoint.ipynb b/03_Intro to matlab-octave/.ipynb_checkpoints/lecture_03-checkpoint.ipynb index 1b7c1ae..19c8d4b 100644 --- a/03_Intro to matlab-octave/.ipynb_checkpoints/lecture_03-checkpoint.ipynb +++ b/03_Intro to matlab-octave/.ipynb_checkpoints/lecture_03-checkpoint.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 9, "metadata": { "collapsed": true, "scrolled": true, @@ -15,6 +15,48 @@ "%plot --format svg" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "|Question|Answered Right|Answered Wrong|Total \\%|\n", + "|----------------------------------------|---|---|---|\n", + "|Define a cell as C={}; C{1}=1.21; C{2}='Gigawatts'; How do you print '1.21 Gigawatts'?|46|29|61.333333333333%|\n", + "|How do you access the third column of an array assigned to the variable A?|58|17|77.333333333333%|\n", + "|What is the result of the following matlab command \"> a=10; b=20; a=5; c=a+b|71|4|94.666666666667%|\n", + "|What is the result of the following Matlab command \"> 1./[2 2]|57|18|76%|\n", + "|Where would a function be saved that cannot be run in Matlab/Octave?|55|20|73.333333333333%|" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false, + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans =\n", + "\n", + " 2 2\n", + "\n" + ] + } + ], + "source": [ + "1*[2 2]" + ] + }, { "cell_type": "markdown", "metadata": { @@ -51,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 46, "metadata": { "collapsed": false, "scrolled": true, @@ -126,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 47, "metadata": { "collapsed": false, "scrolled": true, @@ -166,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 50, "metadata": { "collapsed": false, "scrolled": true, @@ -179,16 +221,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "ans =\n", - "\n", - " 40\n" + "a = 10\n", + "b = 30\n", + "c = 40\n" ] } ], "source": [ - "a=10; % line one assigns a to 10\n", - "b=a*3; % line two assigns b to 10 times 3 by calling 'a' from line one\n", - "a+b % line three does not assign anything directly, but leaving off the \";\" prints the result\n", + "a=10 % line one assigns a to 10\n", + "b=a*3 % line two assigns b to 10 times 3 by calling 'a' from line one\n", + "c=a+b % line three does not assign anything directly, but leaving off the \";\" prints the result\n", " % ans" ] }, @@ -227,10 +269,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 51, "metadata": { "collapsed": false, - "scrolled": true, "slideshow": { "slide_type": "fragment" } @@ -242,34 +283,56 @@ "text": [ "A =\n", "\n", - " 1 2 3\n", - " 4 5 6\n", - " 7 8 9\n", - " 10 11 12\n", - "\n", - "size of A is 4 x 3\n", - "\n", - "ans =\n", - "\n", - " 7\n", + " 1 2 3\n", + " 4 5 6\n", + " 7 8 9\n", + " 10 11 12\n", "\n", + "size of A is 4 x 3\n" + ] + } + ], + "source": [ + "A = [1 2 3;4,5,6;7,8,9;10,11,12]\n", + "fprintf('size of A is %i x %i\\n',size(A))" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "collapsed": false, + "scrolled": true, + "slideshow": { + "slide_type": "subslide" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A =\n", "\n", - "ans =\n", + " 1 2 3\n", + " 4 5 6\n", + " 7 8 9\n", + " 10 11 12\n", "\n", - " 5\n" + "ans = 7\n", + "ans = 11\n" ] } ], "source": [ "A = [1 2 3;4,5,6;7,8,9;10,11,12]\n", - "fprintf('size of A is %i x %i\\n',size(A))\n", "A(3,1)\n", - "A(6)" + "A(8)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 55, "metadata": { "collapsed": false, "scrolled": true, @@ -282,15 +345,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "ans =\n", - "\n", - " 1\n" + "ans = 0\r\n" ] } ], "source": [ "a=10; % a is 1x1 array where a(1,1)==10\n", - "a(1,1)==10\n" + "a(1,1)==1\n" ] }, { @@ -309,7 +370,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 57, "metadata": { "collapsed": false, "scrolled": true, @@ -317,17 +378,35 @@ "slide_type": "fragment" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans =\n", + "\n", + " Columns 1 through 8:\n", + "\n", + " 0.00000 0.11111 0.22222 0.33333 0.44444 0.55556 0.66667 0.77778\n", + "\n", + " Columns 9 and 10:\n", + "\n", + " 0.88889 1.00000\n", + "\n" + ] + } + ], "source": [ "C={};\n", "C{1}=linspace(0,1,10);\n", "C{2}=linspace(0,1,3);\n", - "C{'z'}='holy cow';" + "C{'z'}='holy cow';\n", + "C{1}" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 61, "metadata": { "collapsed": false, "scrolled": true, @@ -342,12 +421,19 @@ "text": [ "ans =\n", "\n", - " 3.5185\n" + " Columns 1 through 8:\n", + "\n", + " 0.00000 0.22222 0.44444 0.66667 0.88889 1.11111 1.33333 1.55556\n", + "\n", + " Columns 9 and 10:\n", + "\n", + " 1.77778 2.00000\n", + "\n" ] } ], "source": [ - "C{1}*C{1}'" + "C{1}+C{1}" ] }, { @@ -364,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 62, "metadata": { "collapsed": false, "scrolled": true, @@ -377,15 +463,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "ans =\n", - "\n", - "computational mechanics\n" + "ans = computational mechanics rocks!\r\n" ] } ], "source": [ "string1 = 'computational'; string2 = 'mechanics';\n", - "[string1, ' ', string2]" + "[string1, ' ', string2, ' rocks!']" ] }, { @@ -401,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 63, "metadata": { "collapsed": false, "scrolled": true, @@ -416,16 +500,13 @@ "text": [ "computational mechanics\n", "\n", - "\n", - "string =\n", - "\n", - "the dog had 4 legs and weighed 10.0 lbs\n" + "string = the dog had 4 legs and weighed 30.9 lbs\n" ] } ], "source": [ "fprintf([string1,' ',string2,'\\n\\n'])\n", - "string = sprintf('the dog had %i legs and weighed %1.1f lbs',4,10.0)" + "string = sprintf('the dog had %i legs and weighed %1.1f lbs',4,30.93)" ] }, { @@ -458,7 +539,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 67, "metadata": { "collapsed": false }, @@ -471,13 +552,16 @@ "\n", " 3 3\n", "\n", - "error: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x2)\n" + "ans =\n", + "\n", + " 0.50000 0.50000\n", + "\n" ] } ], "source": [ "1+[2,2]\n", - "1/[2,2]" + "1./[2,2]" ] }, { @@ -515,7 +599,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": { "collapsed": false, "scrolled": true, @@ -528,22 +612,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "v_row =\n", - "\n", - " 1 2 3\n", - "\n", - "\n", - "v_column =\n", + "ans =\n", "\n", - " 1\n", + " 100\n", " 2\n", - " 3\n" + " 3\n", + "\n" ] } ], "source": [ - "v_row = [1,2,3] %row vector\n", - "v_column = [1;2;3] %column vector\n" + "v_row = [100, 2,3]; %row vector\n", + "v_column = [1;2;3]; %column vector\n", + "v_row'" ] }, { @@ -560,7 +641,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": { "collapsed": false, "scrolled": true, @@ -623,13 +704,13 @@ "text": [ "ans =\n", "\n", - " 1\n", - " 7\n" + " 1 2 3\n", + "\n" ] } ], "source": [ - "A(1:2:end,1) % you can also use `end` " + "A(1,:) % you can also use `end` " ] }, { @@ -649,18 +730,19 @@ "text": [ "ans =\n", "\n", - " 1\n", - " 4\n", - " 7\n", - " 10\n", - " 2\n", - " 5\n", - " 8\n", - " 11\n", - " 3\n", - " 6\n", - " 9\n", - " 12\n" + " 1\n", + " 4\n", + " 7\n", + " 10\n", + " 2\n", + " 5\n", + " 8\n", + " 11\n", + " 3\n", + " 6\n", + " 9\n", + " 12\n", + "\n" ] } ], @@ -683,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 30, "metadata": { "collapsed": false, "scrolled": true, @@ -691,24 +773,51 @@ "slide_type": "subslide" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'mode' is a function from the file /usr/share/octave/4.0.0/m/statistics/base/mode.m\n", + "\n", + " -- Function File: mode (X)\n", + " -- Function File: mode (X, DIM)\n", + " -- Function File: [M, F, C] = mode (...)\n", + " Compute the most frequently occurring value in a dataset (mode).\n", + "\n", + " 'mode' determines the frequency of values along the first\n", + " non-singleton dimension and returns the value with the highest\n", + " frequency. If two, or more, values have the same frequency 'mode'\n", + " returns the smallest.\n", + "\n", + " If the optional argument DIM is given, operate along this\n", + " dimension.\n", + "\n", + " The return variable F is the number of occurrences of the mode in\n", + " the dataset.\n", + "\n", + " The cell array C contains all of the elements with the maximum\n", + " frequency.\n", + "\n", + " See also: mean, median.\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": [ - "A_6666 = zeros(6,6,6,6); %make a 6 x 6 x 6 x 6 array (1296 different values)\n", - "for i=1:6\n", - " for j=1:6\n", - " for k=1:6\n", - " for l=1:6\n", - " A_6666(i,j,k,l)=i+j+k+l; % each value is the sum of the indices\n", - " end\n", - " end\n", - " end\n", - "end\n", - " " + "help mode" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, "metadata": { "collapsed": false, "scrolled": true, @@ -721,25 +830,76 @@ "name": "stdout", "output_type": "stream", "text": [ + "ans = 14\n", + "ans = 3.4170\n", "ans =\n", "\n", - " 14\n", + "ans(:,:,1) =\n", "\n", + " 4 5 6 7 8 9\n", + " 5 6 7 8 9 10\n", + " 6 7 8 9 10 11\n", + " 7 8 9 10 11 12\n", + " 8 9 10 11 12 13\n", + " 9 10 11 12 13 14\n", "\n", - "ans =\n", + "ans(:,:,2) =\n", + "\n", + " 5 6 7 8 9 10\n", + " 6 7 8 9 10 11\n", + " 7 8 9 10 11 12\n", + " 8 9 10 11 12 13\n", + " 9 10 11 12 13 14\n", + " 10 11 12 13 14 15\n", "\n", - " 3.4170\n" + "ans(:,:,3) =\n", + "\n", + " 6 7 8 9 10 11\n", + " 7 8 9 10 11 12\n", + " 8 9 10 11 12 13\n", + " 9 10 11 12 13 14\n", + " 10 11 12 13 14 15\n", + " 11 12 13 14 15 16\n", + "\n", + "ans(:,:,4) =\n", + "\n", + " 7 8 9 10 11 12\n", + " 8 9 10 11 12 13\n", + " 9 10 11 12 13 14\n", + " 10 11 12 13 14 15\n", + " 11 12 13 14 15 16\n", + " 12 13 14 15 16 17\n", + "\n", + "ans(:,:,5) =\n", + "\n", + " 8 9 10 11 12 13\n", + " 9 10 11 12 13 14\n", + " 10 11 12 13 14 15\n", + " 11 12 13 14 15 16\n", + " 12 13 14 15 16 17\n", + " 13 14 15 16 17 18\n", + "\n", + "ans(:,:,6) =\n", + "\n", + " 9 10 11 12 13 14\n", + " 10 11 12 13 14 15\n", + " 11 12 13 14 15 16\n", + " 12 13 14 15 16 17\n", + " 13 14 15 16 17 18\n", + " 14 15 16 17 18 19\n", + "\n" ] } ], "source": [ "mean(A_6666(:))\n", - "std(A_6666(:))" + "std(A_6666(:))\n", + "A_6666(:,:,:,1)" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 22, "metadata": { "collapsed": false, "scrolled": true, @@ -754,12 +914,13 @@ "text": [ "ans =\n", "\n", - " 12\n" + " 1296 1\n", + "\n" ] } ], "source": [ - "A_6666(1,4,2,5)" + "size(A_6666(:))\n" ] }, { @@ -775,7 +936,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 25, "metadata": { "collapsed": false, "scrolled": true, @@ -788,17 +949,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "\\\n" + "n\n", + " n\n" ] } ], "source": [ - "fprintf('\\\\')" + "fprintf('n\\n n')" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 34, "metadata": { "collapsed": false, "scrolled": false, @@ -808,21 +970,26 @@ }, "outputs": [ { - "name": "stderr", + "name": "stdout", "output_type": "stream", "text": [ - "\u001b[0;31mUndefined function or variable 'fid'.\n", - "\u001b[0m" + "ans = 0\r\n" ] } ], "source": [ - "%fid = fopen('file.txt','w');\n", + "fid = fopen('file.txt','w');\n", + "string1='Computational';\n", + "string2='Mechanics';\n", + "string='happy semester';\n", "fprintf(fid,[string1, ' ', string2])\n", "fprintf(fid,'\\n')\n", "fprintf(fid,string)\n", "fprintf(fid,'\\n')\n", - "fprintf(fid,'are you awake?')" + "fprintf(fid,'are you awake?')\n", + "fprintf(fid,'\\n')\n", + "fprintf(fid,'%f is equal to pi',pi)\n", + "fclose(fid)" ] }, { @@ -5422,6 +5589,216 @@ "source": [ "pcolor(X,Y,Z)" ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false, + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "data=dlmread('US_energy_by_sector.csv',',',2,0);;" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "Gnuplot\n", + "Produced by GNUPLOT 5.0 patchlevel 3 \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t \n", + "\t \n", + "\t\n", + "\t\n", + "\t \n", + "\t \n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\t\n", + "\t\t5000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t10000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t15000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t20000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t25000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t30000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1940\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1950\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1960\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1970\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1980\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1990\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2010\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2020\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\n", + "\t\n", + "\t\ttrillions of btus\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\tyear\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\tresidential totals\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\tresidential totals\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\ttransportation totals\n", + "\n", + "\t\n", + "\t\ttransportation totals\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "setdefaults;\n", + "plot(data(:,1),data(:,3),data(:,1),data(:,8))\n", + "xlabel('year')\n", + "ylabel('trillions of btus')\n", + "legend('residential totals','transportation totals')" + ] } ], "metadata": { diff --git a/03_Intro to matlab-octave/lecture_03.ipynb b/03_Intro to matlab-octave/lecture_03.ipynb index 6e385b5..13ce5f9 100644 --- a/03_Intro to matlab-octave/lecture_03.ipynb +++ b/03_Intro to matlab-octave/lecture_03.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 45, + "execution_count": 9, "metadata": { "collapsed": true, "scrolled": true, @@ -15,6 +15,48 @@ "%plot --format svg" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "|Question|Answered Right|Answered Wrong|Total \\%|\n", + "|----------------------------------------|---|---|---|\n", + "|Define a cell as C={}; C{1}=1.21; C{2}='Gigawatts'; How do you print '1.21 Gigawatts'?|46|29|61.333333333333%|\n", + "|How do you access the third column of an array assigned to the variable A?|58|17|77.333333333333%|\n", + "|What is the result of the following matlab command \"> a=10; b=20; a=5; c=a+b|71|4|94.666666666667%|\n", + "|What is the result of the following Matlab command \"> 1./[2 2]|57|18|76%|\n", + "|Where would a function be saved that cannot be run in Matlab/Octave?|55|20|73.333333333333%|" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false, + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans =\n", + "\n", + " 2 2\n", + "\n" + ] + } + ], + "source": [ + "1*[2 2]" + ] + }, { "cell_type": "markdown", "metadata": { @@ -723,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 30, "metadata": { "collapsed": false, "scrolled": true, @@ -731,19 +773,46 @@ "slide_type": "subslide" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'mode' is a function from the file /usr/share/octave/4.0.0/m/statistics/base/mode.m\n", + "\n", + " -- Function File: mode (X)\n", + " -- Function File: mode (X, DIM)\n", + " -- Function File: [M, F, C] = mode (...)\n", + " Compute the most frequently occurring value in a dataset (mode).\n", + "\n", + " 'mode' determines the frequency of values along the first\n", + " non-singleton dimension and returns the value with the highest\n", + " frequency. If two, or more, values have the same frequency 'mode'\n", + " returns the smallest.\n", + "\n", + " If the optional argument DIM is given, operate along this\n", + " dimension.\n", + "\n", + " The return variable F is the number of occurrences of the mode in\n", + " the dataset.\n", + "\n", + " The cell array C contains all of the elements with the maximum\n", + " frequency.\n", + "\n", + " See also: mean, median.\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": [ - "A_6666 = zeros(6,6,6,6); %make a 6 x 6 x 6 x 6 array (1296 different values)\n", - "for i=1:6\n", - " for j=1:6\n", - " for k=1:6\n", - " for l=1:6\n", - " A_6666(i,j,k,l)=i+j+k+l; % each value is the sum of the indices\n", - " end\n", - " end\n", - " end\n", - "end\n", - " " + "help mode" ] }, { @@ -5523,21 +5592,222 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 31, + "metadata": { + "collapsed": false, + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "data=dlmread('US_energy_by_sector.csv',',',2,0);" + ] + }, + { + "cell_type": "code", + "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "error: dlmread: error parsing RANGE\r\n" - ] + "data": { + "image/svg+xml": [ + "\n", + "\n", + "Gnuplot\n", + "Produced by GNUPLOT 5.0 patchlevel 3 \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t \n", + "\t \n", + "\t\n", + "\t\n", + "\t \n", + "\t \n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\t\n", + "\t\t0\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t0.2\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t0.4\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t0.6\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t0.8\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1.2\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1.4\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1940\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1950\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1960\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1970\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1980\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t1990\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2000\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2010\n", + "\t\n", + "\n", + "\n", + "\t\t\n", + "\t\t2020\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\n", + "\t\n", + "\t\ttrillions of btus\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\tyear\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\tresidential totals\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\tresidential totals\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\ttransportation totals\n", + "\n", + "\t\n", + "\t\ttransportation totals\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ - "data=dlmread('US_energy_by_sector.csv',',',[2,0]);" + "setdefaults;\n", + "plot(data(:,1),cumsum(data(:,3))/1e6,data(:,1),cumsum(data(:,8))/1e6)\n", + "xlabel('year')\n", + "ylabel('trillions of btus')\n", + "legend('residential totals','transportation totals','Location','Northwest')" ] }, { diff --git a/HW1/.README.md.swp b/HW1/.README.md.swp new file mode 100644 index 0000000..e73eed8 Binary files /dev/null and b/HW1/.README.md.swp differ diff --git a/HW1/README.html b/HW1/README.html new file mode 100644 index 0000000..dfa2dad --- /dev/null +++ b/HW1/README.html @@ -0,0 +1,77 @@ + + + + + + + + + + + +

Homework #1

+

due 1/24/17

+
    +
  1. The first assignment is to fork the course syllabus and assignment.

    +
      +
    1. Sign into your UConn github account via github.uconn.edu.
    2. +
  2. +
+
+Step 1 +

Step 1

+
+
+Step 2 +

Step 2

+
+
b. Go to
+[https://github.uconn.edu/rcc02007/ME3255S2017.git](https://github.uconn.edu/rcc02007/ME3255S2017.git)
+and watch the repository. 
+
+c. Fork the repository to create your own version of the syllabus and assignments. 
+
    +
  1. The next assignment is to create your own repository named ‘01_ME3255_repo’.

    +
      +
    1. (if you signed out) Sign into your UConn github account via github.uconn.edu.

    2. +
    3. Follow these steps to create your own repository named 01_ME3255_repo:

      +
        +
      1. Click the +-sign and choose ‘New repository’
      2. +
    4. +
  2. +
+

Step 3
+ii. In the ‘Repository name’ enter ‘01_ME3255_repo’. Add a description. Make it private. Then check the box ‘Initialize this repository with a README’.

+

Step 4
+iii. Now you are in your repo. Click on the README.md file and then click the pencil to edit it.

+

Step 5
+iv. Add a header with a # and type # Answer to Homework Question. Under this line answer this question: What do you hope to learn this semester?

+

Step 6
+v. At bottom of page, click ‘Commit changes’.

+

Step 7
+vi. Verify that your README.md file has been updated. Then copy the HTTPS clone URL on the right of the page.

+

Step 8
+vii. Paste this into the Homework #1 Google form reponse. https://goo.gl/forms/b3YrBuFxZaXTYV5s1

+

Step 9
+viii. Click on the gear for “Settings” then “Collaborators” on the left menu. Add rcc02007 (Ryan C. Cooper) and zhs15101 (Zhiqiang Shen) as a collaborators.

+
    +
  1. Use a script to create a variable called A_66, where every row, column is the product of the two indices from 1 to 6 e.g. A_66(3,2)=6 and A_66(4,4)=16. Calculate the mean and standard deviation of the values in A_66.

  2. +
  3. Copy the data in US_energy_by_sector.csv to a file in you working directory in Matlab/Octave.

    +
      +
    1. Plot the US energy consumption from 1949 to 2016 for “Total Energy Consumed by the Residential Sector” and “Total Energy Consumed by the Transportation Sector” in trillions of Btu’s.

    2. +
    3. Plot the cumulative US energy consumption from 1949 to 2016 for “Total Energy Consumed by the Residential Sector” and “Total Energy Consumed by the Transportation Sector” in quintillions of Btu’s (1 quintillion = 10\(^6\) trillion). The cumulative energy is the area under the curve in part a from 1949 to a given year.

    4. +
  4. +
  5. In this part, you will modify the function presented in lecture freefall.m. In lecture, the function required an input of N to divide the 12 second solution into N-steps. Here, modify the input so that you can specify two inputs, step size-h, and timespan-timespan.

    +
      +
    1. Plot a comparison between calculated velocities v(t) for timesteps of h=0.1, 1, and 5 sec from 0 to 30 seconds.

    2. +
    3. Save the script that created the comparison plot as ‘freefall_comparison.m’ and the figure as figure01.png (use command > print(figure01.png))

    4. +
    5. Save your work to a folder called ‘problem_3’ and add it to the ‘01_ME3255_repo’ repository

    6. +
  6. +
  7. In this part we will create functions that calculate velocity and acceleration in 3D based upon x,y,z-coordinates and time.

    +
      +
    1. Create a function that takes four vectors as input, x,y,z,t,(where x,y,z are coordinate positions in meters) and its output are three vectors [vx,vy,vz] which are velocity components in m/s.

    2. +
    3. Create a function that takes four vectors as input, x,y,z,t,(where x,y,z are coordinate positions in meters) and its output are three aectors [ax,ay,az] which are acceleration components in m/s\(^2\).

    4. +
  8. +
+ + diff --git a/HW1/README.md b/HW1/README.md new file mode 100644 index 0000000..701a045 --- /dev/null +++ b/HW1/README.md @@ -0,0 +1,105 @@ +# Homework #1 +## due 9/15/17 + +1. The first assignment is to fork the course syllabus and assignment. + + a. Sign into your UConn github account via + [github.uconn.edu](https://github.uconn.edu/). + +![Step 1](g1.jpg) + +![Step 2](g2.jpg) + + + b. Go to + [https://github.uconn.edu/rcc02007/ME3255S2017.git](https://github.uconn.edu/rcc02007/ME3255S2017.git) + and watch the repository. + + c. Fork the repository to create your own version of the syllabus and assignments. + +2. The next assignment is to create your own repository named '01_ME3255_repo'. + + a. (if you signed out) Sign into your UConn github account via + [github.uconn.edu](https://github.uconn.edu/). + + b. Follow these steps to create your own repository named `01_ME3255_repo`: + + i. Click the +-sign and choose 'New repository' + + ![Step 3](g3.jpg)\ + + ii. In the 'Repository name' enter '01_ME3255_repo'. Add a description. Make it + private. Then check the box 'Initialize this repository with a README'. + + ![Step 4](g4.jpg)\ + + iii. Now you are in your repo. Click on the README.md file and then click the + pencil to edit it. + + ![Step 5](g5.jpg)\ + + iv. Add a header with a `#` and type `# Answer to Homework Question`. Under this + line answer this question: What do you hope to learn this semester? + + ![Step 6](g6.jpg)\ + + v. At bottom of page, click 'Commit changes'. + + ![Step 7](g7.jpg)\ + + vi. Verify that your README.md file has been updated. Then copy the HTTPS clone + URL on the right of the page. + + ![Step 8](g8.jpg)\ + + vii. Paste this into the Homework #1 Google form reponse. + [https://goo.gl/forms/b3YrBuFxZaXTYV5s1](https://goo.gl/forms/b3YrBuFxZaXTYV5s1) + + ![Step 9](g9.jpg)\ + + viii. Click on the gear for "Settings" then "Collaborators" on the left menu. Add + `rcc02007` (Ryan C. Cooper) and `zhs15101` (Zhiqiang Shen) as a collaborators. + +3. Use a script to create a variable called `A_66`, where every element is the product +of the two indices from 1 to 6 e.g. A_66(3,2)=6 and A_66(4,4)=16. Calculate the mean and +standard deviation of the values in A_66. + +3. Copy the data in +[US_energy_by_sector.csv](https://github.uconn.edu/rcc02007/ME3255F2017/blob/master/03_Intro%20to%20matlab-octave/US_energy_by_sector.csv) +to a file in you working directory in Matlab/Octave. Add these two plots to your +01_ME3255_repo with a heading of `#Problem 4` + + a. Plot the US energy consumption from 1949 to 2016 for "Total Energy Consumed by the + Residential Sector" and "Total Energy Consumed by the Transportation Sector" in trillions + of Btu's. + + b. Plot the cumulative US energy consumption from 1949 to 2016 for "Total Energy Consumed by the + Residential Sector" and "Total Energy Consumed by the Transportation Sector" in quintillions + of Btu's (1 quintillion = 10$^6$ trillion). The cumulative energy is the area under + the curve in part a from 1949 to a given year. + +3. In this part, you will modify the function presented in lecture `freefall.m`. In +lecture, the function required an input of `N` to divide the 12 second solution into +N-steps. Here, modify the input so that you can specify two inputs, step size-`h`, and +timespan-`timespan`. + + a. Plot a comparison between calculated velocities v(t) for timesteps of h=0.1, 1, and + 5 sec from 0 to 30 seconds. + + b. Save the script that created the comparison plot as 'freefall_comparison.m' and the + figure as figure01.png (use command `> print(figure01.png)`) + + c. Save your work to a folder called 'problem_3' and add it to the '01_ME3255_repo' + repository + +4. In this part we will create functions that calculate velocity and acceleration in 3D +based upon x,y,z-coordinates and time. + + a. Create a function that takes four vectors as input, x,y,z,t,(where x,y,z are + coordinate positions in meters) and its output are three vectors [vx,vy,vz] which are + velocity components in m/s. + + + b. Create a function that takes four vectors as input, x,y,z,t,(where x,y,z are + coordinate positions in meters) and its output are three aectors [ax,ay,az] which are + acceleration components in m/s$^2$. diff --git a/HW1/g1.jpg b/HW1/g1.jpg new file mode 100644 index 0000000..532ca2b Binary files /dev/null and b/HW1/g1.jpg differ diff --git a/HW1/g1.png b/HW1/g1.png new file mode 100644 index 0000000..fc5bee2 Binary files /dev/null and b/HW1/g1.png differ diff --git a/HW1/g2.jpg b/HW1/g2.jpg new file mode 100644 index 0000000..081f461 Binary files /dev/null and b/HW1/g2.jpg differ diff --git a/HW1/g2.png b/HW1/g2.png new file mode 100644 index 0000000..0a19740 Binary files /dev/null and b/HW1/g2.png differ diff --git a/HW1/g3.jpg b/HW1/g3.jpg new file mode 100644 index 0000000..8ae9566 Binary files /dev/null and b/HW1/g3.jpg differ diff --git a/HW1/g3.png b/HW1/g3.png new file mode 100644 index 0000000..191a402 Binary files /dev/null and b/HW1/g3.png differ diff --git a/HW1/g4.jpg b/HW1/g4.jpg new file mode 100644 index 0000000..7d20135 Binary files /dev/null and b/HW1/g4.jpg differ diff --git a/HW1/g4.png b/HW1/g4.png new file mode 100644 index 0000000..2134b52 Binary files /dev/null and b/HW1/g4.png differ diff --git a/HW1/g5.jpg b/HW1/g5.jpg new file mode 100644 index 0000000..e432bd7 Binary files /dev/null and b/HW1/g5.jpg differ diff --git a/HW1/g5.png b/HW1/g5.png new file mode 100644 index 0000000..c59dc3a Binary files /dev/null and b/HW1/g5.png differ diff --git a/HW1/g6.jpg b/HW1/g6.jpg new file mode 100644 index 0000000..0609ccb Binary files /dev/null and b/HW1/g6.jpg differ diff --git a/HW1/g6.png b/HW1/g6.png new file mode 100644 index 0000000..8905f7c Binary files /dev/null and b/HW1/g6.png differ diff --git a/HW1/g7.jpg b/HW1/g7.jpg new file mode 100644 index 0000000..216dd4e Binary files /dev/null and b/HW1/g7.jpg differ diff --git a/HW1/g7.png b/HW1/g7.png new file mode 100644 index 0000000..283f98e Binary files /dev/null and b/HW1/g7.png differ diff --git a/HW1/g8.jpg b/HW1/g8.jpg new file mode 100644 index 0000000..c6dc7b5 Binary files /dev/null and b/HW1/g8.jpg differ diff --git a/HW1/g8.png b/HW1/g8.png new file mode 100644 index 0000000..4f44447 Binary files /dev/null and b/HW1/g8.png differ diff --git a/HW1/g9.jpg b/HW1/g9.jpg new file mode 100644 index 0000000..70f79c5 Binary files /dev/null and b/HW1/g9.jpg differ diff --git a/HW1/g9.png b/HW1/g9.png new file mode 100644 index 0000000..e27469d Binary files /dev/null and b/HW1/g9.png differ diff --git a/extra_credit/README.md b/extra_credit/README.md new file mode 100644 index 0000000..2c450af --- /dev/null +++ b/extra_credit/README.md @@ -0,0 +1,6 @@ +# Extra Credit Assignment \#1 + +Go to Mathworks [Matlab Onramp](http://bit.ly/2q97vcS) and create an account. Complete +Part 10 - "Review Problems" (Project - Electricity Usage) and (Project - Audio Frequency). + +Save your progress report and put it in a repository called 'ME3255-Extra_Credit'.