Difference between revisions of "EGR 103/Fall 2017/Minilab 7"

From PrattWiki
Jump to navigation Jump to search
 
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== Clarifications ==
 +
To mount your CIFS drive on a PC, use the instructions at: [[User:DukeEgr93/WindowsPermission#Mount_your_drive_via_windows|Mount your drive via windows.]] Note that you only need to mount the drive - you do not need to change permissions!
 +
 +
== Troubleshooting ==
 +
* If you get a broadcast error, it will generally tell you the number of elements in two variables that are different -- look in the variable explorer to figure out what sizes things are (and what they should be)and fix your code.  This has most often happened when someone uses the model values to create estimates or vice versa.
 +
* "invalid syntax errors" often happen because the line of code '''above''' the one specified have imbalanced parentheses - put the cursor near the last closed parentheses on the line above and see which opener lights up.
 +
* It is generally a bad idea to copy and paste from a PDF -- among other things, you will get the wrong kind of quote (` instead of ') and will need to go back and fix those.
 +
* If there is a complaint about a variable being equal to none, you have likely either called a function without an input argument or you have forgotten to have your function return something.  Be sure your function looks like
 +
<source lang=python>
 +
def func(x)
 +
    return x**2
 +
</source>
 +
and not just
 +
<source lang=python>
 +
def func(x)
 +
    x**2
 +
</source>
 +
 +
== Typos ==
 +
*Prior to 6:45am on 12/5/2017, these problems used numbers from a previous edition of the book.  This particularly changed the answers to 7.8.3 and 7.8.4.  Those have been updated.
 +
* Problem 8.1 in the lab is really 8.2 in the book
 +
 
== 7.8.1 ==
 
== 7.8.1 ==
 +
Be sure to store your data using code similar to <code>a = np.array([1, 2, 3, 4])</code> and not just <code>a = [1, 2, 3, 4]</code>.
 +
 +
Also, to return the result of a long formula, be sure to put the whole thing in parentheses to break it across lines; for instance:
 +
<source lang=python>
 +
return (1 + 2 + 3 +
 +
    4 + 5 + 6 + 7)
 +
</source>
 +
 +
For the legend, add labels to each plot command and then call the legend command; for example:
 
<source lang=python>
 
<source lang=python>
St: 5.627e+00
+
plt.plot(t, x, 'k-', label='position')
 +
plt.plot(t, v, 'r--', label='velocity')
 +
plt.legend()
 +
</source>
 +
=== Partial Answer ===
 +
<source lang=python>
 +
St: 5.793e+00
 
Sr: 7.850e-02
 
Sr: 7.850e-02
r2: 9.861e-01
+
r2: 9.864e-01
 
</source>
 
</source>
 
The model should be a green dashed line going through the data points.
 
The model should be a green dashed line going through the data points.
  
 
== 7.8.2 ==
 
== 7.8.2 ==
 +
* Be sure to create a function called <code>u_y</code> that returns a value.  Also, since the return calculation is long, you will want to put it in parentheses and then on multiple lines, so something like:
 +
<source lang=python>
 +
def u_y(x):
 +
    return ( calculations stuff then
 +
            more calculation stuff )
 +
</source>
 +
=== Partial Answer ===
 
<source lang=python>
 
<source lang=python>
 
Root 1: 2.338e+00
 
Root 1: 2.338e+00
Line 19: Line 63:
  
 
== 7.8.3 ==
 
== 7.8.3 ==
 +
=== Partial Answer ===
 
<source lang=python>
 
<source lang=python>
 
(1)
 
(1)
[[ 5  8 13]
+
[[ 5  8 15]
  [ 8  3  9]
+
  [ 8  4 10]
 
  [ 6  0 10]]
 
  [ 6  0 10]]
 
(3)
 
(3)
[[ 3 -2 1]
+
[[ 3 -2 -1]
  [-6  1 3]
+
  [-6  0 4]
 
  [-2  0 -2]]
 
  [-2  0 -2]]
 
(4)
 
(4)
 
[[28 21 49]
 
[[28 21 49]
  [ 7 14 42]
+
  [ 7 14 49]
 
  [14  0 28]]
 
  [14  0 28]]
 
(5)
 
(5)
[[2 6 1]]
+
[[3 6 1]]
 
(6)
 
(6)
[[21 13 61]
+
[[25 13 74]
  [35 23 67]
+
  [36 25 75]
 
  [28 12 52]]
 
  [28 12 52]]
 
(7)
 
(7)
[[53 23 75]
+
[[54 76]
  [39  7 48]
+
  [41 53]
  [18 10 36]]
+
  [28 38]]
 
(8)
 
(8)
[[ 5 2]
+
[[ 9 2]
  [ 4 1]
+
  [ 4 -1]
 
  [ 3  7]
 
  [ 3  7]
  [-7 5]]
+
  [-6 5]]
(9)
 
[[56]]
 
 
(11)
 
(11)
[[66 12 51]
+
[[ 66 19  53]
  [12 26 33]
+
  [ 19  29  46]
  [51 33 81]]
+
  [ 53  46 109]]
 
(12)
 
(12)
[[41]]
+
[[46]]
 
</source>
 
</source>
  
 
== 7.8.4 ==
 
== 7.8.4 ==
 +
For complex numbers, write the imaginary part followed directly by a j with no space -- including if you are writing just j.  Also, do not put spaces around the + or - between the real and imaginary parts -  for instance:
 +
<source lang=python>
 +
a = 4+1j
 +
</source>
 +
Do not use i and do not forget to put the number in front of j, even if that number is a 1.
 +
 +
Also, Python does not build matrices the way MATLAB does if you use the string version of the input for the matrix function; you '''cannot''' assign values to variables and then build a matrix the way you might think you could; for instance, the following will not work:
 +
<source lang=python>
 +
m = 2+1j
 +
n = np.matrix('m, 1; 2, 3')
 +
# produces malformed string error
 +
</source>
 +
You '''can''' use this method if you use the double-bracket input version:
 +
<source lang=python>
 +
m = 2+1j
 +
n = np.matrix([[m, 1], [2, 3]])
 +
# works like a charm
 +
</source>
 +
=== Partial Answer ===
 
<source lang=python>
 
<source lang=python>
 
8.3:
 
8.3:
[[-17.01923077]
+
[[-15.18115942]
  [ -9.61538462]
+
  [ -7.24637681]
  [ -1.53846154]]
+
  [ -0.14492754]]
 
8.5:
 
8.5:
 
[[-0.53333333+1.4j      ]
 
[[-0.53333333+1.4j      ]
Line 69: Line 131:
  
 
== 7.8.5 ==
 
== 7.8.5 ==
 +
Note: when you define your function for curve fitting, the independent variable needs to be the first argument, followed by any constants you are trying to find.  Your definition line will likely be something like:
 +
<source lang=pyth0n>
 +
def func(i, p_max, i_sat):
 +
</source>
 +
=== Partial Answer ===
 
<source lang=python>
 
<source lang=python>
St: 2.327e+04
+
St: 2.837e+04
 
Sr: 1.116e+03
 
Sr: 1.116e+03
r2: 9.520e-01
+
r2: 9.607e-01
 
</source>
 
</source>
 
Coefficients and graph should match your for this lab.  Be sure you are using good initial guesses - bad initial guesses will result in a flat red line!
 
Coefficients and graph should match your for this lab.  Be sure you are using good initial guesses - bad initial guesses will result in a flat red line!

Latest revision as of 15:35, 7 December 2017

Clarifications

To mount your CIFS drive on a PC, use the instructions at: Mount your drive via windows. Note that you only need to mount the drive - you do not need to change permissions!

Troubleshooting

  • If you get a broadcast error, it will generally tell you the number of elements in two variables that are different -- look in the variable explorer to figure out what sizes things are (and what they should be)and fix your code. This has most often happened when someone uses the model values to create estimates or vice versa.
  • "invalid syntax errors" often happen because the line of code above the one specified have imbalanced parentheses - put the cursor near the last closed parentheses on the line above and see which opener lights up.
  • It is generally a bad idea to copy and paste from a PDF -- among other things, you will get the wrong kind of quote (` instead of ') and will need to go back and fix those.
  • If there is a complaint about a variable being equal to none, you have likely either called a function without an input argument or you have forgotten to have your function return something. Be sure your function looks like
def func(x)
    return x**2

and not just

def func(x)
    x**2

Typos

  • Prior to 6:45am on 12/5/2017, these problems used numbers from a previous edition of the book. This particularly changed the answers to 7.8.3 and 7.8.4. Those have been updated.
  • Problem 8.1 in the lab is really 8.2 in the book

7.8.1

Be sure to store your data using code similar to a = np.array([1, 2, 3, 4]) and not just a = [1, 2, 3, 4].

Also, to return the result of a long formula, be sure to put the whole thing in parentheses to break it across lines; for instance:

return (1 + 2 + 3 + 
     4 + 5 + 6 + 7)

For the legend, add labels to each plot command and then call the legend command; for example:

plt.plot(t, x, 'k-', label='position')
plt.plot(t, v, 'r--', label='velocity')
plt.legend()

Partial Answer

St: 5.793e+00
Sr: 7.850e-02
r2: 9.864e-01

The model should be a green dashed line going through the data points.

7.8.2

  • Be sure to create a function called u_y that returns a value. Also, since the return calculation is long, you will want to put it in parentheses and then on multiple lines, so something like:
def u_y(x):
    return ( calculations stuff then
             more calculation stuff )

Partial Answer

Root 1: 2.338e+00
Root 2: 7.762e+00
Min of y=-2.086e+01 at x=+1.279e+00
Min of y=-3.274e+01 at x=+8.708e+00
Min of y=-2.086e+01 at x=+1.279e+00
Max of y=+1.953e+02 at x=+5.702e+00

The graph should be like your graph for Lab 5

7.8.3

Partial Answer

(1)
[[ 5  8 15]
 [ 8  4 10]
 [ 6  0 10]]
(3)
[[ 3 -2 -1]
 [-6  0  4]
 [-2  0 -2]]
(4)
[[28 21 49]
 [ 7 14 49]
 [14  0 28]]
(5)
[[3 6 1]]
(6)
[[25 13 74]
 [36 25 75]
 [28 12 52]]
(7)
[[54 76]
 [41 53]
 [28 38]]
(8)
[[ 9  2]
 [ 4 -1]
 [ 3  7]
 [-6  5]]
(11)
[[ 66  19  53]
 [ 19  29  46]
 [ 53  46 109]]
(12)
[[46]]

7.8.4

For complex numbers, write the imaginary part followed directly by a j with no space -- including if you are writing just j. Also, do not put spaces around the + or - between the real and imaginary parts - for instance:

a = 4+1j

Do not use i and do not forget to put the number in front of j, even if that number is a 1.

Also, Python does not build matrices the way MATLAB does if you use the string version of the input for the matrix function; you cannot assign values to variables and then build a matrix the way you might think you could; for instance, the following will not work:

m = 2+1j
n = np.matrix('m, 1; 2, 3')
# produces malformed string error

You can use this method if you use the double-bracket input version:

m = 2+1j
n = np.matrix([[m, 1], [2, 3]])
# works like a charm

Partial Answer

8.3:
[[-15.18115942]
 [ -7.24637681]
 [ -0.14492754]]
8.5:
[[-0.53333333+1.4j       ]
 [ 1.60000000-0.53333333j]]

7.8.5

Note: when you define your function for curve fitting, the independent variable needs to be the first argument, followed by any constants you are trying to find. Your definition line will likely be something like:

def func(i, p_max, i_sat):

Partial Answer

St: 2.837e+04
Sr: 1.116e+03
r2: 9.607e-01

Coefficients and graph should match your for this lab. Be sure you are using good initial guesses - bad initial guesses will result in a flat red line!