# Category Archives: Uncategorized

## Useful Soil Coefficients

Previously we discussed mechanical analysis and the method of sieve analysis. This allowed us to develop the particle size distribution curve. With this curve we can find some useful parameters. They are:

- The Uniformity Coefficient
- The Coefficient of Gradation

Both of these parameters are used in soil classification. The Uniformity Coefficient is defined as:

The Coefficient of Gradation is defined as:

where

These diameters are obtained from the particle size distribution curve by going across from the percent finer, coming to the curve, and turning 90 degrees down to the abscissa to locate the diameter as seen below.

**Related Posts:**

## Least Squares Linear Regression

Least-squares regression is a methodology for finding the equation of a best fit line through a set of data points. It also provides a means of describing how well the data correlates to a linear relationship. An example of data with a general linear trend is seen in the above graph. First, we will go over the derivation of the formulas from theory and then I have also appended at the end of this post Scilab code for implementation of the algorithm.

The equation of a line through a data point can be written as:

The value of any data points that are not directly on the line but are in the proximity of the line can be given by:

Where e is the vertical error between the y-value given by the line and the actual y-value of the data. The goal would be to come up with a line which minimizes this error. In least-squares regression, this is accomplished by minimizing the sum of the squares of the errors. The sum of the squares of the errors is given by:

In order to minimize this value, the minimum finding techniques of differential calculus will be used. First take the derivative with respect to the slope.

Then with respect to the y-intercept yields:

Which can be substituted in the previous equation to solve for the slope.

The y-intercept is then:

It can be seen that these last two formulas only require knowledge about the data point coordinates and the number of points and the equation for the least squares linear regression line can be found.

Finally, below is the Scilab code implementation.

//the linear regression function takes x-values and //y-values of data in the column vectors 'X' and 'Y' and finds //the best fit line through the data points. It returns //the slope and y-intercept of the line as well as the //coefficient of determination ('r_sq'). //the function call for this should be of the form: //'[m,b,r2]=Linear_Regression(x,y)' function [slope, y_int, r_sq]=Linear_Regression(X, Y) //determine the number of data points n=size(X,'r'); //initialize each summation sum_x=0; sum_y=0; sum_xy=0; sum_x_sq=0; sum_y_sq=0; //calculate each sum required to find the slope, y-intercept and r_sq for i=1:n sum_x=sum_x+X(i); sum_y=sum_y+Y(i); sum_xy=sum_xy+X(i)*Y(i); sum_x_sq=sum_x_sq+X(i)*X(i); sum_y_sq=sum_y_sq+Y(i)*Y(i); end //determine the average x and y values for the //y-intercept calculation x_bar=sum_x/n; y_bar=sum_y/n; //calculate the slope, y-intercept and r_sq and return the results slope=(n*sum_xy-sum_x*sum_y)/(n*sum_x_sq-sum_x^2); y_int=y_bar-slope*x_bar; r_sq=((n*sum_xy-sum_x*sum_y)/(sqrt(n*sum_x_sq-sum_x^2)*sqrt(n*sum_y_sq-sum_y^2)))^2; //determine the appropriate axes size for plotting the data and //linear regression line axes_size=[min(X)-0.1*(max(X)-min(X)),min(Y)-0.1*(max(Y)-min(Y)),max(X)+0.1*(max(X)-min(X)),max(Y)+0.1*(max(Y)-min(Y))]; //plot the provided data plot2d(X,Y,style=-4,rect=axes_size); //plot the calculated regression line plot2d(X,(slope*X+y_int)); endfunction

I hope this proves helpful. Let me know in the comments if you have any questions.

**Related Posts:**

## Delay Differential Equations and the Lambert W Function

Delay differential equations are natural to study since most systems involve a delay from the input to the output (accelerators, computers, etc.). On a more nerdy level they involve some pretty interesting math so let’s take a look.

Consider the scalar, linear, pure delay differential equation:

This type of equation is associated with a system where the output is equivalent to the input delayed by a small time constant and multiplied by a system constant . In studying the stability of differential equations, we want to know whether they will behave in one of two ways. Either the solution to the differential equation approaches infinity as time approaches infinity (unstable) or the solution approaches some constant as time approaches infinity (stable). To do this, let’s take the Laplace transform of the DDE.

Collecting the terms and assuming the initial condition to be zero, we arrive at the following equation.

To avoid a trivial solution, only the part of the equation in the parentheses can equal zero. Therefore,

Let’s introduce the Lambert W function. This function satisfies the equation:

The solution to this equation is:

In other words,

where is the Lambert W function of and is the branch number. This equation is called a transcendental equation since there are infinite values that satisfy this equation. The Lambert W function has infinite branches (similar to or ), meaning there are infinite values that will satisfy the equation above. Additionally, it can be shown that the maximum values yielded by the Lambert W function are given by the principal branch (i.e. ).

Returning to the Laplace transform equation,

The roots of this equation determine the stability of the DDE. Therefore, we solve for the values that make this equation zero.

Multiplying both sides by yields:

Clearly, this equation is a candidate for using the Lambert W function. So, for this simple function, it can be seen that the roots for the DDE are given as:

There are infinite values that satisfy this equation; however, since the maximum values for the Lambert W function are given by the principal branch, the only branch that need be evaluated is the principal branch. In other words, if the maximum value for the DDE roots is negative, then all the rest of the values are guaranteed negative. Therefore, for stability

This is an important result for understanding delay systems. However, the study of delays in systems of differential equations is much more difficult and remains an open problem in the field of dynamics and control systems. For example consider the DDE system

where is a vector and is a matrix. Stay tuned for more!

## Mesh Circuit Analysis

Recently I had a reader comment with a request for an example of Kirchoff’s Voltage Law (KVL) with Ohm’s Law. KVL and Ohm’s Law are both used in the circuit analysis methodology called Mesh Circuit Analysis. Consequently I thought I would analyze a small circuit and demonstrate the general principles of this technique that can be used on any circuit.

The circuit we will use below has a 10 volt source and 4 resistors configured as seen.

**STEP 1:**

The first step is to label the circuit as I have done in red ink. This includes the current flowing clockwise through each loop (or mesh) and the voltage drops across each passive element. (In this case all the passive elements are resistors.) Next we will use the picture to write some equations.

**STEP 2:**

If you look at the diagram at the first loop and start at the top, then travel around the loop going clockwise and add up the voltage drops you get the first equation below. Notice the voltage drop across the source is negative because it is not a drop it is an increase.Also notice the sum must equal zero.

The next 2 lines are simply writing the unknown voltage drops in terms of Ohm’s Law. The voltage drop across the resistor is equal to the current through the resistor times the resistance. Notice for resistor 2 the currents are opposing one another. In other words current 1 runs from the top of the circuit toward the bottom of the circuit through resistor 2. Current 2 runs from the bottom to the top. That is why the current component in the second Ohm’s Law equation is i1 minus i2.

Next these two Ohm’s Law equations are substituted in the original equation which gives the 4th line below.

From the 4th line the rest is just algebra. Then do the exact same process for loop 2 as seen above. This gives 2 equations with 2 unknowns. Of course these can be solved by any linear algebra method you prefer.

STEP 3:

Below I solved it using simple substitution. This solves for the unknown currents.

STEP 4:

Finally, substitute these found currents back into the Ohm’s Law equations we developed earlier and you find the unknown voltage drops. The last diagram shows the final solution.

I hope this answers my reader’s question and has been helpful. Please let me know if anyone needs more help.