www.teramari.us - Science & Technology
http://teramari.us/taxonomy/term/7
enRugged Watch Criteria
http://teramari.us/node/121
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Watches are jewelry and as a result there is a wide variation both in price and quality. I'd love to perform a study and scatter map price and quality. The most you could hope for is a straight line: higher price results in higher quality. But in reality I think what you'd end up with is a cloud with very little statistical correlation. Even if you were able to normalize for precious metals or technologies that lend themselves to aesthetics rather than robustness I don't think if would make much of a difference.</p>
<p>That hasn't stopped me from attempting the task for myself. There are several watch brands that spec (and in some cases overspec) their watches. Some invest heavily in new technologies, some use custom movements, some don't. Some are just a little more honest in what you are buying. On the opposite end are many watches that make no claims about anything and are modestly priced. Still others make grandiose claims about performance and charge for it. Sometimes those watch brands back it up and some don't.</p>
<p>So what I have done is cooked up a list of criteria, a specification if you will, for watch performance. And to make it easy to compare watches I have created a scoring system as well.</p>
<p>Watch design is essentially a two step process:</p>
<ol><li>Choose a watch movement with some minimum nominal performance.</li>
<li>Design structure around the movement that minimizes any environmental variation from nominal to ensure performance does not vary.</li>
</ol><p>IMHO analog watch movements are pretty good. They aren't as accurate as quartz and for that reason I prefer quartz most of the time. But I also think that the analog movement industry has stood still for too long. They are offering the same 3-5 9's quality of movements for literally decades now without much improvement. I don't wish to be too harsh. ETA has introduced the first affordable perpetual movement. And many movement designers are introducing these "double barrel" movements which increase the reserve to around 80 hours. But still Omega is the only vendor who is really addressing watch accuracy. No ultra stable watches have been produced in the analog segment. At least better than COSC. I know it is a herculean task but no public efforts made that I can find.</p>
<p>Accuracy is straightforward once you understand the concepts:</p>
<ul><li><em>Accuracy over time:</em> This is the long term accuracy of a watch. It is an average of all the fluctuations, perturbations, etc.</li>
<li><em>Max variation:</em> Accuracy will have peaks/values though. One day it might be +2, the next -10. That still makes the average -6. There should not be too many extremes. I have not listed this as a requirement for my watch guide.</li>
<li><em>Isochronism:</em> This is the term that defines how accuracy is affected as a function of the reserve. Watches typically have best accuracy at full winding (100% energy reserve) and get worse as they deplete. In other words over night or left at home for a day you can expect more drift than if it were on your hand being automatically wound and kept at 100%.
</li></ul><p>Here is the criteria for nominal watch accuracy:</p>
<table><tr><td>Requirement</td>
<td>Description</td>
<td>Moderate</td>
<td>Excellent</td>
</tr><tr><td>Nominal</td>
<td>Maximum average accuracy to be expected from a randomly manufactured movement in a specific environment (e.g. humidity, temp,<br />
no magnetism, etc)</td>
<td>+/-59s per month</td>
<td>+/-5s per month</td>
</tr><tr><td>Isochronism</td>
<td>Maximum error to be expected as a watch winds down and uses up its reserve (but of course hasn't stopped)</td>
<td>3-10s per day</td>
<td><3s per day</td>
</tr></table><p>Here are the criteria for robustness:</p>
<table><tr><td>Requirement</td>
<td>Description</td>
<td>Moderate</td>
<td>Excellent</td>
</tr><tr><td>Env: Magnetism</td>
<td>Resistance to magnetic fields. Very few things exceed ~1,500A/m</td>
<td>1,500-4,800A/m</td>
<td>>4,800A/m</td>
</tr><tr><td>Env: Humidity/Water</td>
<td>Resistance to humidity, water and low pressure</td>
<td>5-10bar</td>
<td>10bar</td>
</tr><tr><td>Env: Temperature</td>
<td>Exposure to temperature including direct sunlight</td>
<td>0-50degC</td>
<td>-10-60degC</td>
</tr><tr><td>Env: Shock/Vibe</td>
<td>Shock comes from drops and knocks (e.g. tables) and vibe comes from equipment, driving, trains, etc.</td>
<td>DIN9110/ISO1413</td>
<td>DIN8330</td>
</tr><tr><td>Env: Orientation</td>
<td>Performance over watch orientation (e.g. face up, face down, on it's side, etc)</td>
<td>4 or 5</td>
<td>ALL (i.e. 6)</td>
</tr><tr><td>Strength: Case</td>
<td>How resistant is the case to scuffs, scratches and dents?</td>
<td>100-500 Vickers</td>
<td>>500 Vickers</td>
</tr><tr><td>Strength: Coverglass</td>
<td>How resistant is the coverglass to scuffs, scratches and dents?</td>
<td>Mineral/Acrylic</td>
<td>Sapphire/Gorilla</td>
</tr></table><p>And here are some functional criteria to round out the selection:</p>
<table><tr><td>Requirement</td>
<td>Description</td>
<td>Moderate</td>
<td>Excellent</td>
</tr><tr><td>Function: Night Readability</td>
<td>How well does the lume work? How long does it last?</td>
<td>2-6hrs</td>
<td>>6hrs</td>
</tr><tr><td>Function: Energy Reserve</td>
<td>How many hours / months does the energy reserve last?</td>
<td>Auto: 3-6days<br />
Quartz: 24-42mths</td>
<td>Auto: >6days<br />
Quartz: >42mths</td>
</tr><tr><td>Function: Style</td>
<td>Subjective style requirements?</td>
<td>Subjective</td>
<td>Subjective</td>
</tr><tr><td>Function: Complications</td>
<td>Any complications I desire in a new watch</td>
<td>Subjective</td>
<td>Subjective</td>
</tr></table><p>The scoring system is weighted with the following terms:</p>
<ul><li>Excellent Performance: +1 point</li>
<li>Moderate Performance: +0.5 point</li>
<li>Weak Performance: +0.1 point</li>
<li>Unspecified: -0.1 point</li>
</ul><p>Any specification that does not meet at least Moderate is Weak. Any performance that is not specified receives a slight penalty. This is to encourage manufacturers to print more specifications and to stand by their (often very expensive) products. The top score is 13 points.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 06 May 2017 16:46:59 +0000administrator121 at http://teramari.ushttp://teramari.us/node/121#commentsCorrecting A Broken Google Play Games Installation
http://teramari.us/node/116
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Some time ago I had some kind of error or corruption will my Google Play Games on my Shield TV console. Any time I chose to log into google games the system would log in but then the game could not detect the log in. It was odd and I knew the issue was probably a local error. Here's how I fixed it:</p>
<p>First google requires a couple pre-requisites:</p>
<ol><li>A google account</li>
<li>A google+ account</li>
</ol><p>Steps to fix the error:</p>
<ol><li>Force stop, clear data and remove any game that will not work from Settings->Apps. Yes you will lose your progress.</li>
<li>Force stop, remove any updates and clear data for the Download Manager from Settings->Apps.</li>
<li>Force stop, remove any updates and clear data for the Google Play Games from Settings->Apps.</li>
<li>Force stop, remove any updates and clear data for the Google Play Services from Settings->Apps.</li>
<li>Force stop, remove any updates and clear data for the Google Play Store from Settings->Apps.</li>
<li>Remove the game(s) authorization from plus.google.com/apps</li>
<li>Remove google account from Settings. This seems to be a fairly safe and unobtrusive operation.</li>
<li>Restart your Android TV.</li>
<li>Add your account back in. It should have you do this automatically. Follow any other steps.</li>
<li>Open Google Play Store and accept any agreements. Update all apps from the store (not all things mentioned above will be here).</li>
<li>Open Google Play Games and accept any agreements.</li>
<li>Install a game or games back onto the console.</li>
<li>Open the game and try to log in. You will be forced to update Google Play Services.</li>
<li>Try to log in again, this time you may be met with more than one account option. The second worked for me. The first did not successfully log in. When performing this operation don't choose the option to make this permanent. If you have success exit the game, log in with the working option and make the operation permanent.</li>
<li>You should be in business at this point. Games will log in and stay logged in. Your settings, achievements, etc will automatically be saved to the Google Play Games cloud.</li>
</ol></div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sun, 08 Jan 2017 18:56:45 +0000administrator116 at http://teramari.ushttp://teramari.us/node/116#commentsLinear Algebra in Engineering: Summary (Part 7 of 7)
http://teramari.us/node/110
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will attempt to organize the previous series of articles into a decision tree allowing you to quickly choose the best method for a particular problem.</p>
<p><strong>Procedure</strong><br />
First, ask yourself some questions about your data and the type of answer you need.</p>
<ol><li><em>How many dimensions in your data set? Was this data capture or design intent?</em></li>
<li><em>Do you need an exact answer or a best estimate?</em></li>
<li><em>Are you expecting a single result or iterating over time? Are you looking for an asymptote at infinity?</em></li>
<li><em>How many dimensions or values do you expect in your calculated result?</em></li>
</ol><p><strong>Methodology</strong><br />
Which method to use?</p>
<ul><li>Are you solving a system for equilibrium? Is this measurement data or a design problem?
<ul><li>If this is a design problem then you will likely want an exact solution: np.linalg.solve</li>
<li>If this is data is captured from the lab then a least squares solution is probably best: np.linalg.lstsq</li>
<li>For economic problems use an Leontief Input-Output Model</li>
</ul></li>
<li>Are you forecasting? For situations where you need to curve fit to an equation.
<ul><li>For exact fit use scipy.interpolate</li>
<li>For a least squares fit use: np.polyfit</li>
<li>Then use np.poly1d to build a polynomial and forecast</li>
</ul></li>
<li>Forecasting. For situations where you are evaluating flow over time or looking for an asymptote.
<ul><li>To solve a network problem use adjacency matrices and matrix math</li>
<li>For stochastic matrices use Markov chains</li>
</ul></li>
</ul><p><strong>Summary</strong><br />
Hopefully this will provide you with the most common calculation requirements you will encounter.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 10 Dec 2016 18:33:09 +0000will110 at http://teramari.ushttp://teramari.us/node/110#commentsLinear Algebra in Engineering: Analyzing Dynamic Systems with Markov Chains (Part 6 of 7)
http://teramari.us/node/109
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use of Markov Chains. This can be used to analyze models with cyclic or or repeated outcomes.</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_6.py">linear6.py</a> and <a href="http://www.teramari.us/files/linalg/linear_6.xlsx">linear6.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Stochastic Model:</em> a system or a model which includes random variables.</p>
<p><em>Stochastic matrix:</em> describes a particular flow in statistical terms. For example they characterize the percentage of voters that switch or stick with their party (from year to year). Or the flow of people between cities. They are often annotated by the letter <em>P</em>. Stochastic matrices are probability matrices so columns must sum to exactly 1.</p>
<p><em>State Vector:</em> describes the absolute state or value of a model. They are annotated with <strong>x</strong>.</p>
<p><em>Markov Chain:</em> a stochastic model in which the probability of an event occurring is depends solely on the state attained in the previous event. A Markov chain is formed by calculating <em>P</em><strong>x<sub>0</sub></strong>. Subsequent calculations made by calculating <em>P</em><strong>x<sub>0</sub></strong><strong>x<sub>1</sub></strong>...<strong>x<sub>n</sub></strong>.</p>
<p><em>Steady State Vector:</em> a vector that is stable over time as <strong>n</strong> in <strong>x<sub>n</sub></strong> approaches infinity. This is characterized by the equation <em>P</em><strong>x</strong>=<strong>x</strong>.</p>
<p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>We read in two fixed sized arrays. One is a 3x3 stochastic model describing the flow of residents between City, Rural and Suburban areas of a metropolitan from one year to the next. The second describes a state vector of the population in each at the starting year.</p>
<p><img src="http://www.teramari.us/files/linalg/linear_6.png" /></p>
<p><code><br />
filename='linear_6.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code><br /><code><br />
print ' Reading data values'<br />
stoch=[]<br />
for row_index in range(0,sh.nrows):<br />
stoch.append([sh.cell_value(row_index,0),sh.cell_value(row_index,1),sh.cell_value(row_index,2)])<br />
stoch=np.matrix(stoch)<br />
print ' Stochastic model size:',len(stoch)<br />
print<br />
state0=[]<br />
for row_index in range(0,sh.nrows):<br />
state0.append([sh.cell_value(row_index,4)])<br />
state0=np.array(state0)<br />
print ' State model size:',len(state0)<br /></code></p>
<p>The last bit of code converts the array to a numpy matrix which will be necessary for the code below.</p>
<p>Numpy arrays are normally preferred but they do not support 'x*y' which will be handy here.</p>
<p><strong>Calculating the Markov Chain</strong><br />
We need to calculate <strong>x<sub>i+1</sub></strong>= <em>P</em><strong>x<sub>i</sub></strong>.</p>
<p><code><br />
print<br />
print 'Stoch:'<br />
print stoch<br />
print 'State x0:'<br />
print state0<br />
print 'State x1:'<br />
state1=stoch*state0<br />
print state1<br />
print 'State x2:'<br />
state2=stoch*state1<br />
print state2<br /></code></p>
<p>This is the output:<br /><code><br />
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]<br />
__main__<br /></code><br /><code><br />
Opening linear_6.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Stochastic model size: 3<br /></code><br /><code><br />
State model size: 3<br /></code><br /><code><br />
Stoch:<br />
[[ 0.91 0.02 0.04]<br />
[ 0.01 0.97 0.01]<br />
[ 0.08 0.01 0.95]]<br />
State x0:<br />
[[ 980000.]<br />
[ 2450000.]<br />
[ 650000.]]<br />
State x1:<br />
[[ 966800.]<br />
[ 2392800.]<br />
[ 720400.]]<br />
State x2:<br />
[[ 956460.]<br />
[ 2337888.]<br />
[ 785652.]]<br /></code></p>
<p>We can see the inflow/outflow of folks to City, Rural and Suburban areas from the starting year to the year after and the year after that.</p>
<p><strong>Calculating the Steady State</strong><br />
If we continue calculating the Markov Chain over and over we will eventually reach steady state. I do this setting a maximum allowable error rate and calculating <strong>x<sub>i+1</sub></strong>= <em>P</em><strong>x<sub>i</sub></strong> over and over until the first entry in the state vector has an iteration to iteration error less than the maximum allowable.</p>
<p>The code for this is:<br /><code><br />
vector_sub1=[]<br />
vector_sub2=[]<br />
vector_sub3=[]<br />
vector_error_sub1=[]<br />
vector_error_sub2=[]<br />
vector_error_sub3=[]<br />
print<br />
vector_sub1.append(state0[0])<br />
vector_sub2.append(state0[1])<br />
vector_sub3.append(state0[2])<br />
vector_error_sub1.append([0])<br />
vector_error_sub2.append([0])<br />
vector_error_sub3.append([0])<br />
max_error=1e-3<br />
ss_state_prev=state0<br />
ss_state_now=stoch*ss_state_prev<br />
i=0<br />
while abs(ss_state_prev[0]-ss_state_now[0]) > max_error:<br />
vector_sub1.append(ss_state_now[0])<br />
vector_sub2.append(ss_state_now[1])<br />
vector_sub3.append(ss_state_now[2])<br />
vector_error_sub1.append(ss_state_prev[0]-ss_state_now[0])<br />
vector_error_sub2.append(ss_state_prev[1]-ss_state_now[1])<br />
vector_error_sub3.append(ss_state_prev[2]-ss_state_now[2])<br />
i=i+1<br />
ss_state_prev=ss_state_now<br />
ss_state_now=stoch*ss_state_prev<br />
print<br />
print 'Max Error: ', max_error<br />
print 'Final Error: ', ss_state_now[0]-ss_state_prev[0]<br />
print 'Number of Iterations: ', i<br />
print<br />
print 'Steady State Vector:'<br />
print ss_state_now<br /></code></p>
<p>This code includes a bunch of extra arrays to plot error rates below.</p>
<p>The output:</p>
<p><code><br />
Max Error: 0.001<br />
Final Error: [[ 0.00098843]]<br />
Number of Iterations: 401<br /></code><br /><code><br />
Steady State Vector:<br />
[[ 1098461.5147391 ]<br />
[ 1020000.10675093]<br />
[ 1961538.37850993]]<br /></code></p>
<p>Plotting code:<br /><code><br />
t=range(0,i+1)<br />
plt.plot(t,vector_sub1,t,vector_sub2,t,vector_sub3)<br />
plt.ylabel('# people')<br />
plt.xlabel('time interval')<br />
plt.show()<br />
plt.clf()<br />
plt.plot(t,vector_error_sub1,t,vector_error_sub2,t,vector_error_sub3)<br />
plt.ylabel('error')<br />
plt.xlabel('time interval')<br />
plt.show()<br /></code></p>
<p>If we plot the state vectors and also the error these is what it looks like:</p>
<p><img src="http://www.teramari.us/files/linalg/linear_6_population.png" /></p>
<p><img src="http://www.teramari.us/files/linalg/linear_6_error.png" /></p>
<p>In the top graph you see all three variables asymptotically approach equilibrium as time approaches infinity.</p>
<p>In the bottom graph you can see the corresponding error approach zero as time approaches infinity.</p>
<p><strong>Next Up</strong><br />
In the next article I will provide a summary of everything covered under Linear Algebra in Engineering.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Thu, 24 Nov 2016 19:35:05 +0000will109 at http://teramari.ushttp://teramari.us/node/109#commentsLinear Algebra in Engineering: Macroeconomics with Leontief Input-Output Model (Part 5 of 7)
http://teramari.us/node/108
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use of Leontief Input-Output Models. This can be used to analyze macroeconomic models of production.</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_5.py">linear5.py</a> and <a href="http://www.teramari.us/files/linalg/linear_5.xlsx">linear5.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Consumption Matrix:</em> An nxn matrix which specifies how many units from each sector are required to produce 1 unit from a particular sector. Each column/row represents a particular sector. n is the total number of sectors represented in the model.</p>
<p><em>Demand Vector:</em> final output quantity of each sector required of an economy</p>
<p><em>Production Vector:</em> the amount of units from each sector required to meet the demand of the economy (specified by the demand vector).</p>
<p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>The sectors in this example are Caprese, Mozzarella, Basil, Tomato, Toast, Milk, Water, Wheat. While this example is a bit playful, they could easily have been manufacturing, agriculture, technology, health, etc. And we would like to calculate the input requirements for creating 100 units of Caprese.</p>
<table><tr><td></td>
<td>Caprese</td>
<td>Mozzarella</td>
<td>Basil</td>
<td>Tomato</td>
<td>Toast</td>
<td>Milk</td>
<td>Water</td>
<td>Wheat</td>
</tr><tr><td>Caprese</td>
<td>0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Mozzarella</td>
<td>1.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Basil</td>
<td>1.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Tomato</td>
<td>1.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Toast</td>
<td>1.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Milk</td>
<td>0.0</td>
<td> 5.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr><tr><td>Water</td>
<td>0.0</td>
<td> 5.0</td>
<td> 1.0</td>
<td> 3.0</td>
<td> 1.0</td>
<td> 10.0</td>
<td>0.0</td>
<td>1.0</td>
</tr><tr><td>Wheat</td>
<td>0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 2.0</td>
<td> 0.0</td>
<td> 0.0</td>
<td> 0.0</td>
</tr></table><p><code><br />
filename='linear_5.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code><br /><code><br />
print ' Reading data values'<br />
xa=[]<br />
for row_index in range(0,sh.nrows):<br />
row_single=[]<br />
for col_index in range(0,sh.ncols):<br />
row_single.append(sh.cell_value(row_index,col_index))<br />
xa.append(row_single)<br />
xa=np.array(xa)<br />
print ' Design x array size:',len(xa)<br />
print<br />
print xa<br /></code></p>
<p>Here we read in a matrix of unknown size from Excel.</p>
<p>The last bit of code converts the array to a numpy array which will be necessary for the code below.</p>
<p><strong>Finding Final Production Requirements</strong><br />
We need to calculate d = (I-C)*x. Where 'd' is the demand vector and 'C' is the consumption matrix. 'x' is the production vector.</p>
<p><code><br />
idm=np.identity(sh.nrows)<br />
xa=idm-xa<br />
final_demand=np.array([100,0,0,0,0,0,0,0])<br /></code><br /><code><br />
eq=np.linalg.solve(xa,final_demand)<br />
print<br />
print eq<br /></code></p>
<p>This is the output:<br /><code><br />
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]<br />
__main__<br /></code><br /><code><br />
Opening linear_5.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design x array size: 8<br /></code><br /><code><br />
[[ 0. 0. 0. 0. 0. 0. 0. 0.]<br />
[ 1. 0. 0. 0. 0. 0. 0. 0.]<br />
[ 1. 0. 0. 0. 0. 0. 0. 0.]<br />
[ 1. 0. 0. 0. 0. 0. 0. 0.]<br />
[ 1. 0. 0. 0. 0. 0. 0. 0.]<br />
[ 0. 5. 0. 0. 0. 0. 0. 0.]<br />
[ 0. 5. 1. 3. 1. 10. 0. 1.]<br />
[ 0. 0. 0. 0. 2. 0. 0. 0.]]<br /></code><br />
And the production requirements (solution):<br /><code><br />
[ 100. 100. 100. 100. 100. 500. 6200. 200.]<br /></code></p>
<p>We can see that 100 caprese units requires 100 mozzarella, 100 basil, 100 tomato and 100 toast. But we also see, and this is the key value of this method, is that we also know we need 500 units of milk, 200 of toast and 6200 units of water.</p>
<table><tr><td>Caprese</td>
<td>Mozzarella</td>
<td>Basil</td>
<td>Tomato</td>
<td>Toast</td>
<td>Milk</td>
<td>Water</td>
<td>Wheat</td>
</tr><tr><td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td>500</td>
<td>6200</td>
<td>200</td>
</tr></table><p><strong>Next Up</strong><br />
In the next article we will analyze dynamic systems with Markov chains.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 19 Nov 2016 17:08:40 +0000will108 at http://teramari.ushttp://teramari.us/node/108#commentsLinear Algebra in Engineering: Analyzing Networks with Adjacency Matrices (Part 4 of 7)
http://teramari.us/node/107
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use of adjacency matrices to analyze interconnected vertices (for example map or network data).</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_4.py">linear4.py</a> and <a href="http://www.teramari.us/files/linalg/linear_4.xlsx">linear4.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Adjacency Matrix:</em> an nxn matrix where a '1' is placed when two vertices are immediately connected and a '0' when they are not.</p>
<p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>In this example I have fabricated a <em>6 x 6</em> network:</p>
<table><tr><td></td>
<td>Node1</td>
<td>Node2</td>
<td>Node3</td>
<td>Node4</td>
<td>Node5</td>
<td>Node6</td>
</tr><tr><td>Node1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr><tr><td>Node2</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr><tr><td>Node3</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr><tr><td>Node4</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr><tr><td>Node5</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr><tr><td>Node6</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr></table><p><code><br />
filename='linear_4.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code></p>
<p><code><br />
print ' Reading data values'<br />
xa=[]<br />
for row_index in range(0,sh.nrows):<br />
row_single=[]<br />
for col_index in range(0,sh.ncols):<br />
row_single.append(sh.cell_value(row_index,col_index))<br />
xa.append(row_single)<br />
xa=np.matrix(xa)<br />
print ' Design x array size:',len(xa)<br />
print<br />
print 'Adjacency Matrix:'<br />
print xa<br /></code></p>
<p>Here we read in a matrix of unknown size from Excel. If the array is large you should comment the print statements.</p>
<p>The last bit of code converts the array to a numpy matrix which will be necessary for the code below. Please note that numpy arrays are preferred and used in all my other posts. But the convenience of 'x*y' is very handy here and the '*' operator is not supported in numpy arrays the way you think it would be.</p>
<p><strong>Finding n-distance Vertices</strong><br />
Now that the test results and input variables have been imported evaluating the number of possible paths between any two vertices is straight forward.</p>
<p>The number of steps is simply M<sup>k</sup> where 'k' is the number of steps you are testing.</p>
<p><code><br />
k=2<br />
nt=xa**2<br />
print 'For ',k,' points:'<br />
print nt<br /></code></p>
<p>This is the output:<br /><code><br />
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]<br />
__main__<br /></code><br /><code><br />
Opening linear_4.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design x array size: 6<br /></code><br /><code><br />
Adjacency Matrix:<br />
[[ 0. 1. 0. 0. 0. 0.]<br />
[ 1. 0. 1. 0. 1. 0.]<br />
[ 0. 1. 0. 0. 0. 1.]<br />
[ 0. 0. 0. 0. 0. 0.]<br />
[ 0. 1. 0. 0. 0. 1.]<br />
[ 0. 0. 1. 0. 1. 1.]]<br /></code><br /><code><br />
For 2 points:<br />
[[ 1. 0. 1. 0. 1. 0.]<br />
[ 0. 3. 0. 0. 0. 2.]<br />
[ 1. 0. 2. 0. 2. 1.]<br />
[ 0. 0. 0. 0. 0. 0.]<br />
[ 1. 0. 2. 0. 2. 1.]<br />
[ 0. 2. 1. 0. 1. 3.]]<br /></code></p>
<p><strong>Next Up</strong><br />
In the next article we will examine production models in macroeconomics with Leontief Input-Output models.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 19 Nov 2016 15:41:10 +0000will107 at http://teramari.ushttp://teramari.us/node/107#commentsLinear Algebra in Engineering: Trend Analysis with Polynomial Interpolation (Part 3 of 7)
http://teramari.us/node/106
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use polynomial interpolation.</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_3.py">linear3.py</a> and <a href="http://www.teramari.us/files/linalg/linear_3.xlsx">linear3.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Interpolation:</em> a method by which an equation is fitted to match a set of data. This equation relates the relationship of the variables in the data. This allows you to evaluate new data points not contained within a data set. It also allows you to evaluate and analyze the behavior of a system without actually measuring the system. Interpolated functions require an exact fit (i.e. the equation must pass through all data points).</p>
<p><em>Regression Analysis:</em> a statistical method for analyzing relationships of variables in data, including curve fitting (linear regression and least squares) and statistical analysis. Often further analysis is pursued, for example forecasting and profiling noise (as a probability distribution).</p>
<p><em>Curve Fitting:</em> a method by which an equation is fitted to match a set of data, usually overdetermined and containing noise, with the least error possible. The equation does not have to pass through all data points. In essence the measured data is smoothed or low pass filtered. Common methods include linear regression and least squares.</p>
<p><em>Least Squares:</em> a curve fitting method by which a function is found that minimizes error between the function and the data set. The method is called least squares because it seeks to minimum the sum of the square of residuals, where the residual is the difference between the data point and the estimated function for all points in the data.</p>
<p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>The data set in this example is four data points: (1,29), (-1,-35), (2,31), and (-3,-19).</p>
<p>The interpolation code in numpy is straight forward:</p>
<p><code><br />
filename='linear_3.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code><br /><code><br />
print ' Reading data values'<br />
xa=[]<br />
ya=[]<br />
for row_index in range(0,sh.nrows):<br />
xa.append(sh.cell_value(row_index,0))<br />
ya.append(sh.cell_value(row_index,1))<br />
xa=np.array(xa)<br />
ya=np.array(ya)<br />
print ' Design x array size:',len(xa)<br />
print ' Design y array size:',len(ya)<br /></code></p>
<p>Here we assemble two arrays. One with the x values and one with the y value measurements.</p>
<p>The last bit of code converts the array to a numpy array which will be necessary for the code below.</p>
<p><strong>Finding the Interpolated Equation</strong><br />
Now that the test results and input variables have been imported let's evaluate the fn at new values.</p>
<p><code><br />
coeff = interp1d(xa, ya, kind='cubic')<br />
xnew = np.linspace(-3, 2, num=125, endpoint=True)<br />
ynew=coeff(xnew)<br />
print<br /></code></p>
<p>The type of interpolation that are available: ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic, ‘cubic’ (where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.</p>
<p>This is the output:<br /><code><br />
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]<br />
__main__<br /></code><br /><code><br />
Opening linear_3.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design x array size: 4<br />
Design y array size: 4<br /></code></p>
<p>Now plot the original values and the interpolated values:<br /><code><br />
plt.axis([-10,10,-50,50])<br />
plt.plot(xa,ya,'ro')<br />
plt.plot(xnew,ynew)<br /></code></p>
<p><img src="http://www.teramari.us/files/linalg/linear_3.png" /></p>
<p>Unfortunately interp1d is not good for trend analysis outside the min/max values in the original data array.</p>
<p>If you want to perform some forecasting of values beyond the original data you're better off using least squares interpolation.</p>
<p><strong>Next Up</strong><br />
In the next article we will analyze networks using adjacency matrices.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sun, 13 Nov 2016 00:07:18 +0000will106 at http://teramari.ushttp://teramari.us/node/106#commentsLinear Algebra in Engineering: Trend Analysis with with Polynomial Least Squares (Part 2 of 7)
http://teramari.us/node/105
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use of least squares fit real data to a polynomial.</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_2.py">linear2.py</a> and <a href="http://www.teramari.us/files/linalg/linear_2.xlsx">linear2.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Interpolation:</em> a method by which an equation is fitted to match a set of data. This equation relates the relationship of the variables in the data. This allows you to evaluate new data points not contained within a data set. It also allows you to evaluate and analyze the behavior of a system without actually measuring the system. Interpolated functions require an exact fit (i.e. the equation must pass through all data points).</p>
<p><em>Regression Analysis:</em> a statistical method for analyzing relationships of variables in data, including curve fitting (linear regression and least squares) and statistical analysis. Often further analysis is pursued, for example forecasting and profiling noise (as a probability distribution).</p>
<p><em>Curve Fitting:</em> a method by which an equation is fitted to match a set of data, usually overdetermined and containing noise, with the least error possible. The equation does not have to pass through all data points. In essence the measured data is smoothed or low pass filtered. Common methods include linear regression and least squares.</p>
<p><em>Least Squares:</em> a curve fitting method by which a function is found that minimizes error between the function and the data set. The method is called least squares because it seeks to minimum the sum of the square of residuals, where the residual is the difference between the data point and the estimated function for all points in the data.</p>
<p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>The data set in this example contains 10 data points.</p>
<p>The interpolation code in numpy is straight forward:</p>
<p><code><br />
filename='linear_2.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code><br /><code><br />
print ' Reading data values'<br />
xa=[]<br />
ya=[]<br />
for row_index in range(0,sh.nrows):<br />
xa.append(sh.cell_value(row_index,0))<br />
ya.append(sh.cell_value(row_index,1))<br />
xa=np.array(xa)<br />
ya=np.array(ya)<br />
print ' Design x array size:',len(xa)<br />
print ' Design y array size:',len(ya)<br /></code></p>
<p>Here we assemble two arrays. One with the x values and one with the y value measurements.</p>
<p>The last bit of code converts the array to a numpy array which will be necessary for the code below.</p>
<p><strong>Fitting the Data to an Equation</strong><br />
Now that the test results and input variables have been imported let's solve the system.</p>
<p><code><br />
coeff=np.polyfit(xa, ya, 3, 0.0, 'true')<br />
print<br />
print coeff<br /></code></p>
<p>This is the output:<br /><code><br />
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]<br />
__main__<br /></code><br /><code><br />
Opening linear_2.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design x array size: 4<br />
Design y array size: 4<br /></code><br /><code><br />
(array([-0.10204189, -0.11780368, 0.2065165 , 3.06325665]), array([ 888.07854894]), 4, array([ 1.73123735, 0.87064906, 0.45862879, 0.1855993 ]), 0.0)<br /></code></p>
<p>The first array is the array of coefficients corresponding to the nth degree polynomial. The residual is printed after.</p>
<p><strong>Evaluating the polynomial</strong><br />
The poly1d function is handy here.</p>
<p><code><br />
print<br />
p=np.poly1d(coeff[0])<br />
print p(-10)<br />
print<br />
print p<br /></code></p>
<p>The output:<br /><code><br />
91.2596137966</code></p>
<p> 3 2<br />
-0.102 x - 0.1178 x + 0.2065 x + 3.063<br /></p>
<p>Plotting the original data against the least squares polynomial fit:<br /><code><br />
plt.axis([-10,10,-50,50])<br />
plt.plot(xa,ya,'ro')<br />
x=np.arange(-10,10,0.1)<br />
y=np.array(-0.1020*x**3-0.1178*x**2+0.2065*x+3.063)<br />
plt.plot(x,y)<br /></code></p>
<p><img width="320" height="240" src="http://www.teramari.us/files/linalg/linear_2.png" /></p>
<p><strong>Next Up</strong><br />
In the next article we will use polynomial interpolation to perform trend analysis.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 12 Nov 2016 16:27:49 +0000will105 at http://teramari.ushttp://teramari.us/node/105#commentsLinear Algebra in Engineering: Equilibrium in Linear Systems (Part 1 of 7)
http://teramari.us/node/104
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><strong>Preface</strong><br />
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.</p>
<p><strong>Introduction</strong><br />
This article will demonstrate the use of matrix algebra to solve for equilibrium in systems. This is common in network flow, economics and electrical circuits (current and voltage analysis). We will apply exact and least squares solutions.</p>
<p>If you are not familiar with linear algebra or need a brush up I recommend <a href="https://www.amazon.com/Linear-Algebra-Its-Applications-5th/dp/032198238X">Linear Algebra and its Applications</a> by Lay, Lay and McDonald. It provides an excellent review of theory and applications.</p>
<p>This also assumes you are familiar with Python or can stumble your way through it.</p>
<p>The data and code are available here: <a href="http://www.teramari.us/files/linalg/linear_1.py">linear1.py</a> and <a href="http://www.teramari.us/files/linalg/linear_1.xlsx">linear1.xlsx</a>.</p>
<p><strong>Concepts</strong><br /><em>Linear Equation:</em> an equation that can be written in the form <em>b = a<sub>1</sub>x<sub>1</sub> + a<sub>2</sub>x<sub>2</sub> + ... + a<sub>n</sub>x<sub>n</sub></em>.</p>
<p><em>Linear System:</em> A set of linear equations involving the same variables.</p>
<p><em>Solution:</em> a set of values for the set of variables in a linear system that make the system a true statement.</p>
<p>Linear systems are either consistent (having a solution) or inconsistent (having no solution). Linear systems with a solution are either unique (1 solution) or have a free variable indicating infinitely many solutions.</p>
<p><em>Matrix Equation:</em> The above definition of a linear equation uses a linear combination to create a vector equation. The same equation can be transliterated to matrix notation (used by computers) in the form <strong>Ax</strong> = <strong>b</strong>.</p>
<p><em>Invertible Matrix Theorem:</em> from Lay, Lay, McDonald.<br />
Let <em>A</em> be a square <em>n</em>x<em>n</em> matrix. Then the following statements are equivalent. That is, for a given <em>A</em>, the statements are either all true or all false.</p>
<ol type="a"><li><em>A</em> is an invertible matrix.</li>
<li><em>A</em> is row equivalent to the <em>n</em>x<em>n</em> identity matrix.</li>
<li><em>A</em> has <em>n</em> pivot positions.</li>
<li>The equation <em>A</em><strong>x</strong>=<strong>0</strong> has only the trivial solution.</li>
<li>The columns of <em>A</em> form a linearly independent set.</li>
<li>The linear transformation <strong>x</strong>-><em>A</em><strong>x</strong> is one-to-one.</li>
<li>The equation <em>A</em><strong>x</strong>=<strong>b</strong> has at least one solution for each <strong>b</strong> in <em>R<sup>n</sup></em>.</li>
<li>The columns of <em>A</em> span <em>R<sup>n</sup></em>.</li>
<li>The linear transformation <strong>x</strong>-><em>A</em><strong>x</strong> maps <em>R<sup>n</sup></em> onto <em>R<sup>n</sup></em>.</li>
<li>There is an <em>n</em>x<em>n</em> matrix <em>C</em> such that <em>CA</em>=<em>I</em>.</li>
<li>There is an <em>n</em>x<em>n</em> matrix <em>D</em> such that <em>AD</em>=<em>I</em>.</li>
<li><em>A<sup>T</sup></em> is an invertible matrix.</li>
<li>The columns of <em>A</em> form a basis of <em>R<sup>n</sup></em>.</li>
<li>Col <em>A</em>=<em>R<sup>n</sup></em>.</li>
<li>dim Col <em>A</em>=<em>n</em></li>
<li>rank <em>A</em>=<em>n</em></li>
<li>Nul <em>A</em>={<strong>0</strong>}</li>
<li>dim Nul <em>A</em>=0</li>
<li>The number 0 is not an eigenvalue of A.</li>
<li>The determinant of A is not zero.</li>
</ol><p><strong>Importing Your Data Set</strong><br />
I will use the <a href="https://www.continuum.io/downloads">Anaconda package suite</a> with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.</p>
<p>I usually have the following boilerplate code in my scripts:<br /><code><br />
import sys<br />
import xlrd<br />
import numpy as np<br />
import matplotlib.pyplot as plt<br />
from scipy.interpolate import interp1d<br /></code><br /><code><br />
np.set_printoptions(threshold=np.nan)<br />
print sys.version<br />
print __name__<br /></code></p>
<p>The system in this example is traffic flow for 4 intersections in a city grid. All ingress/egres traffic is known and is pictured below.</p>
<p><img width="320" height="240" src="http://www.teramari.us/files/linalg/linear_1.png" /></p>
<p>The data above has been arranged into matrix notation and stored in the excel file with the coefficients in the first five columns and the dependent variables in the sixth (last) column.</p>
<p><code><br />
filename='linear_1.xlsx'<br />
print<br />
print 'Opening',filename<br />
ss=xlrd.open_workbook(filename,on_demand=True)<br />
sheet_index=0<br />
print ' Worksheet',ss.sheet_names()[sheet_index]<br />
sh=ss.sheet_by_index(sheet_index)<br /></code><br /><code><br />
print ' Reading data values'<br />
spec=[]<br />
for row_index in range(0,sh.nrows):<br />
spec.append([sh.cell_value(row_index,0),sh.cell_value(row_index,1),sh.cell_value(row_index,2),sh.cell_value(row_index,3),sh.cell_value(row_index,4)])<br />
spec=np.array(spec)<br />
print ' Design spec array size:',len(spec)<br /></code><br /><code><br />
b=[]<br />
for row_index in range(0,sh.nrows):<br />
b.append(sh.cell_value(row_index,5))<br />
b=np.array(b)<br />
print ' Design b array size: ',len(b)<br /></code></p>
<p>Set filename to your Excel filename and set sheet_index to the tab you're reading from (counting starts from zero). Set range(x,y) and {a,b,c,...,n} to the array you are reading in from the sheet. <code>range(0,sh.nrows)</code> is a handy expression to use here.</p>
<p>The last bit of code converts the array to a numpy array which will be necessary for the code below.</p>
<p>The whole operation has fairly good performance.</p>
<p><strong>Solving the System for Equilibrium</strong><br />
Now that the test results and input variables have been imported let's solve the system. We want to find the equilibrium price.</p>
<p>I have found that np.linalg.solve() is not always the best solution because it cannot handle systems that are underdetermined, overdetermined or linearly dependent. A better alternative seems to be the np.linalg.lstsq() function.</p>
<p>Both functions take the form <em>function(a,b)</em> where <em>a</em> and <em>b</em> are from <em>ax=b</em>.</p>
<p><code><br />
#eq=np.linalg.solve(spec,b)<br />
eq=np.linalg.lstsq(spec,b)<br />
print<br />
print eq<br /></code></p>
<p>This is the output:<br /><code><br />
Opening linear_1.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design spec array size: 6<br />
Design b array size: 6<br /></code><br /><code><br />
(array([ 375., 425., 400., 275., 225.]), array([], dtype=float64), 4, array([ 2.11688316e+00, 1.63978419e+00, 1.41421356e+00,<br />
9.10995891e-01, 8.65181300e-17]))<br /></code></p>
<p>The first array is the compute result. DO NOT take that result for granted. You must examine the second array for anything unusual. The most relevant thing to note is that the fifth value is close to zero. This is a strong indication of a free (dependent) variable.</p>
<p>Adding a sixth row to the data set that hard sets the fifth variable to 9 results in this output:<br /><code><br />
Opening linear_1.xlsx<br />
Worksheet Sheet1<br />
Reading data values<br />
Design spec array size: 6<br />
Design b array size: 6<br /></code><br /><code><br />
(array([ 591., 209., 400., 491., 9.]), array([ 4.32956906e-27]), 5, array([ 2.16121248, 1.7660084 , 1.47046231, 0.92978281, 0.42850842]))<br /></code></p>
<p>An entirely different and this time correct result. We can see the fifth variable hard set to 9. If you plug the <strong>x</strong> array into each row of coefficients you'll find 100% agreement.</p>
<p><strong>Systems of Systems</strong><br />
It is often desirable to solve more than one system. This can be done by iterating through each array, one at a time. This is okay but I have found that memory requirements can be utterly huge for this method. The method below seems bulky but is exponentially faster and uses less memory (I don't know how much because the last time I tried the iterative method I kept running out of memory after 4-8 hours).</p>
<p>The following pseudo code works well when the set of coefficients is the same and the dependent values are different. It works just as well for different sets of coefficients you just have to build your array appropriately.</p>
<p>I also include a determinant check to verify the array is invertible and therefore solvable.</p>
<p><code><br />
a=np.array([[some],[set],[of],[coefficients]])<br />
b=np.array([[some],[set],[of],[dependents]])<br />
n=number of coefficients<br />
if np.linalg.det(a) != 0:<br />
csi=np.linalg.solve([a]*n,b)<br /></code></p>
<p><strong>Next Up</strong><br />
In the next article we will examine trend analysis using polynomial least squares.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/13">Hardware & Design</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Mon, 07 Nov 2016 06:11:51 +0000will104 at http://teramari.ushttp://teramari.us/node/104#commentsNew Smartphone is a Disappointment
http://teramari.us/node/99
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I must express my disappointment in my new smartphone. I thought upgrading from the dated, failing and left behind Samsung Galaxy S III to the larger, faster, updated Samsung Galaxy S6 would be just the tool I needed to bump my game to the next level. But it was not so.</p>
<p>On the plus side the updated audio provided a <em>much</em> higher fidelity listening experience. And the display is gorgeous. And the ambient light sensor actually works (even in the dark it can be adjusted to a reasonable level). The camera is significantly faster, more capable and higher resolution.</p>
<p>The interaction experience is significantly improved. Touch works as good or better than it did on the old phone. Organization is improved. Sharing is at the center of device interaction. I can get more done with less clicks. The pull down menu is quite good. As is the home screen (it's more configurable.) I also enjoy how newer versions of Android give you more control over the device and apps.</p>
<p>And so is security. The phone is encrypted and has thumbprint recognition. Wi-Fi voice quality has been good (but facebook beats it hands down).</p>
<p>But that's where it ends. Most of the have were not found in the new phone and there were even some disappointing regressions:</p>
<ol><li>Battery life sucks. Bad. Maybe it would be worth it if the phone were fast. It isn't. Better than the old phone? Yes. Blazingly fast and without stall, delay or lag? Not even close. It's slow and the battery life sucks. Who is the architect who chose an 8 core SoC for a phone? Fucking idiots. Really.</li>
<li>I was relieved when I bought the phone because I thought that supporting the latest WiFi, WAN and BT protocols would solve my connectivity issues. It hasn't. I can say that WAN support is better but it's not great. My old phone did not work at all (data or voice) over WAN in my entire neighborhood except for one spot on my bed in my bedroom (not even my entire bed). It also did not work in the subway. Things are improved but not great. Sometimes the subway works and I get some coverage in my neighborhood but it's a low bit rate for sure. All I can say is thank god for wifi calling. It can provide a significant improvement on voice quality but it's not nearly as good as facebook calling. Seriously? FB has better voice quality than a telephone company with a hundred years in the business?</li>
<li>Speakerphone is better but not good. Why no front facing speakers? Why no stereo? These things are not just for me, they are for all the people around me.</li>
<li>No way to disable DND lights. It's annoying, It eats battery. It's a simple feature that was present on the old phone.</li>
<li>USB2.0 only</li>
<li>Remove the health hardware. It's useless, doesn't work well and eats battery.</li>
<li>The lock screen is a trainwreck. It doesn't use the screen efficiently. Buttons are small and hard to press. You have to manually assign priorities to apps. Apps clearly don't have access to parts of the screen. Apps are forced into the list rather than displaying a simple icon up top. For all the improvements to Android this is still a cluster fuck.</li>
<li>For that matter the samsung keyboard sucks. I like the 1-9+0 across the top but the keyboard guessing is AWFUL. The last phone <em>came with swype</em>. Why didn't this one? I had to install it. While the keyboard guessing on swype is nothing short of extraordinary I wish they included more detail on the keyboard. They removed all the tiny icons which makes it much harder to use. I also wish they would add the option to include 1-9+0 across the top. Regardless the keyboard, one of the most frequently used input methods is garbage.</li>
<li>With that said wouldn't voice control be a focus? You'd think! They removed it completely! On the gs3 I could voice control alarms, music, etc. On the gs6 it's just gone. No more turning off a timer from the kitchen. I have to rub my raw chicken and flour covered fingers all over my phone to shut it up.</li>
<li>If we continue onto UX, the default themes suck. They lack beauty and sophistication. None of them approach professional. They all try to be cute or cool or something that would appeal to a 16yr old boy or girl. This is a $600 phone. Who the fuck do you think is buying these? The same goes for the pre installed sounds.</li>
<li>I wish I could say "thanks for the preinstalled apps, I use a lot of them and the rest I just ignore or remove". But no. Instead they force themselves on me like a drunken date that never ends because it's in my pocket 24/7.
</li><li>File browser is useless. I used to be able to browse music by album. Now it's a randomly sorted mess of tracks that are unreadable because the file names are too long. Bring it back Samsung. There's no excuse.</li>
<li>Smart stay does not work. If I stare at my phone for a couple minutes the screen shuts off. I had the same exact problem on my old phone and it's frustrating.</li>
<li>Night time camera is not improved. All the reviews showed improved night time pics. But in my experience it's still pretty much useless.</li>
<li>They removed the ability to charge while plugged into a USB DAC. I know this is a niche feature. But default Android supports this. Why the fuck did you remove it???</li>
</ol><p>Overall I feel like I got a few nice things on the phone but none of them were items I needed. They are nice to haves. I am completely disappointed with the phone, would not purchase it again and cannot recommend it to anyone for any reason.</p>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/2">Personal</a></div><div class="field-item odd"><a href="/taxonomy/term/7">Science & Technology</a></div></div></div>Sat, 23 Apr 2016 18:25:52 +0000will99 at http://teramari.ushttp://teramari.us/node/99#comments