Friday, October 4, 2019

Phasor / Rotating Vector Representation of Sinusoidal Quantities - Interactive Simulation


R, Ω L, mH C, μF ν, Hz
Plot CONTROLS: Click the legends above to hide/unhide individual lines/curves. Double click to show exclusively.
Vary the parameters ( R, L, C, ν ) in the above table and see the effects.
Animation stop/resume: -- uncheck to stop animation, check to resume
Reload the page to reset-restart!!

The animated plot named "Phasors" on the left shows five vectors (phasors, refer description given below) - each rotating at an angular speed of ω ;
  1. V representing v ( t )
  2. I representing i ( t )
  3. V R representing v R ( t )
  4. V L representing v L ( t )
  5. V C representing v C ( t )
It can be seen that, among the above five, the second and the third phasors are co-linear and in same direction. Also, the fourth and the fifth phasors are co-linear and in opposite directions. The end-points of these five rotating vectors are projected horizontally on to the five respective sinusoidal waves on the animated plot on the right titled 'Sinusoids: v ( t ), i ( t ) etc.'. In the animation, the constant parameter is the input voltage phasor:

V = 100 + j 200 Volts     [0]

R, L, C and ν can be varied individually via the input table.

Phasor representation of sinusoidally varying quantities is commonly used in Science and Engineering. For example, voltages and currents in ac (alternating current) circuits, forces and displacement mechanical vibration systems, and, several kinds of quantities in automatic control systems.

The above interactive simulation / visualization shows the phasor representation of four voltage sinusoids and one current sinusoid involved in the steady state analysis of a series RLC circuit excited by an ac supply v ( t ).

The applied voltage, v ( t ) at a time t , is,

v ( t ) = V sin ( ω t + φ )    [1]

Here, ω (rad/s) is its angular frequency and φ (rad) is its initial ( t = 0 ) phase angle. And, the frequency ν is,

ν = ω / 2 π     [2]

Using Euler's formula , the v ( t ) can also be represented as,

v ( t ) = Im{ V e j ( ω t + φ ) }    [3]

with j being the imaginary number √ -1 . For brevity, the notation Im{.} is dropped and,

v ( t ) = V e j ( ω t + φ )     [4]

Further, separating the time-invariant and time-dependent parts,

v ( t ) = V e jωt     [5]

Where,

V = V e     [6]

Applying Kirchhoff's voltage law to the above shown series RLC circuit,

v ( t ) = v R ( t ) + v L ( t ) + v C ( t )    [7]

Assuming i ( t ) to be the current in the (series) circuit, such that,

i ( t ) = I e j ( ω t + φ i )     [8]

or,

i ( t ) = I e jωt     [9]

Where,

I = I e i     [10]

As per the definitions of R-L-C elements,

v R ( t ) = iR     [11]

v L ( t ) = j ( iX L ), with inductive reactance X L = ωL     [12]

v C ( t ) = - j ( iX C ), with capacitive reactance X C = 1/ ωC     [13]

After some algebraic manipulations, one gets,

I = V / Z    [14]

in which, the total impedance of the series RLC circuit is,

Z = R + ( X L - X C )    [15]

Credits:
This article uses Plotly.js - "A free open source interactive JavaScript graphing library".

Monday, September 23, 2019

Transverse Vibration of Strings - Interactive simulation of the Wave Equation


Wave # v ν λ k ω Y T φ
1
2
Transverse vibration of strings is modeled by the following relation [123]:
(Please reload the page if equations do not display properly)
\begin{equation} y(t, x) = Y \sin (\omega t - k x + \phi) \end{equation}
Here, \(y\) is the transverse displacement at time \(t\) at a location identified by the coordinate \(x\).
\(\omega\) is the angular frequency of vibration of the string.
\(k\) is the propagation constant,
\begin{equation} k = \frac{2\pi}{\lambda} \end{equation}
\(\lambda\) is the wavelength.
Other important relations are:
Frequency \(\nu\),
\begin{equation} \nu = \frac{\omega}{2\pi} \end{equation}
Time period \(T\),
\begin{equation} T = \frac{1}{\nu} \end{equation}
Wave velocity \(v\),
\begin{equation} v = \nu \lambda \end{equation}
\(Y\) is the amplitude of vibration.
\(\phi\) is the initial (\(t = 0\)) phase angle at (\(x = 0\)).

The simulation shows 2 different waves - pre-initialised with all parameters having same values, except for \(Y\) and \(\phi\).
Change the values and see the effects.
Noticeably, certain values are coupled.

References

Wednesday, February 17, 2016

Free Open Source Software for Mechanical Engineering Students, Researchers & Professionals

Looking at the AICTE's list of Open Source alternatives to commercial s/w for Engineering students, and also at the chaos going on in this respect in several engineering campuses, I present here, based on my own experiences, a list of open source solutions for such learning and research situations, in particular, and also for industries.

As I have understood it, the basic set of ideas leading myself and several of my colleagues (for example, at IIT-B, University of Alaska Fairbanks, MIT, 2nd one from MIT, Virginia Tech, Harvard, London School of Economics, Sports Biomechanics Lab at UCDavis, San Francisco State University, The University of Utah, The California Institute of Technology (Caltech)) to the use of such software, since past about 20 years, are as follows:

1. Since there is perpetual shortage of funds, these free alternatives become the natural choice and a natural refuge for students, researchers as well as for professionals. In the Indian education scenario, it was surprising a few years back and is painful, even now, to see students taking bank loans to fund their education. Really tragic and painful stories are being now found in the media.

2. From the social perspective of a researcher and a s/w writer, I find it difficult to accept that such s/w should remain captive under the contemporary fund-owners. Each of such s/w is fundamentally a magnificent storehouse of knowledge and experiences of countless man/woman-hours of countless dedicated researchers, professionals etc.

3. In this discussion, the English word "generic" is very important. As per dictionaries, the word-meaning of "generic" is:

a: characteristic of or relating to a class or group of things; not specific:

b: of or relating to a whole group or class, not sold or made under a particular brand name

Obviously, the second word-meaning above is simply amazing! There is a concept of generic software, very much like generic medicine.  Thus, for example, for the generic 3D mechanical modeling s/w like Creo, Solidworks, Catia etc., there is the powerful open source alternative in the form of FreeCAD. It was really wonderful to find that the steps (like 2d drawing, pocketing, extruding etc.) encountered while undergoing a training on a commercial 3D modeling s/w, were found almost the same  in the online documentation/tutorial of FreeCAD.

Moreover, for a particular generic category of s/w, one may find different industrial entities using different commercial s/w, not much unlike different doctors prescribing from different brands for the same "generic medicine".

4. Particularly in the education institutes and universities, the objective is to impart the student the basic understanding of the s/w in a particular "generic" category. For this objective, the open source alternatives should be the natural choice, keeping in mind a comprehensive view of the situation. Also, it may again be emphasized that almost all of these s/w are widely used in research as well as industrial situations.


 The list (not complete, indeed):

1. Operating System: Linux, in the form of its several distributions. The most commonly used distributions being - Debian, Ubuntu and Fedora. For further motivation, see: 1 & 2.

2.  Office s/w: LibreOffice. No probs at all!!

3. C/C++: Most of the engineering students begin their coding experience with learning C/C++ on the blue TurboC/C++ ide which itself is known to be freely downloadable. However, the open source alternative gcc (used with vim and gnu make) provides a universe of advantages in terms of industry-readiness, comprehensive documentation etc. Still, if one wants to use the the blue TurboC/C++ ide, it is easily installable on Linux.

4. Painting, simple line-diagrams and 2D drafting: xfig.

5. AutoCAD: AutoCAD itself has been freely downloadable and installable via AICTE support since about 5 years. Moreover, there is DraftSight from Dassault systems.

6.3D modeling: As already discussed above, in the context of mechanical engineering, this is the most important case of free and open source alternative in the form of FreeCAD (ref.: University of Alaska Fairbanks, MIT, 2nd one from MIT, Virginia Tech, Harvard, Sports Biomechanics Lab at UCDavis, San Francisco State University, The University of Utah, The California Institute of Technology (Caltech)) which must be used in place of commercial alternatives.

7. Matlab: Octave is the Linux-community  solution I have myself been using since past several years. Scilab is another alternative, very strongly being advocated, for example, by academia from IIT Bombay.

8. CAM: "LinuxCNC controls CNC machines. It can drive milling machines, lathes, 3d printers, laser cutters, plasma cutters, robot arms, hexapods, and more."

In conclusion, with increasing laptop population (each laptop costing less than 10% of the expenditure on a typical engineering/technology UG degree (BTech/BE)), the best alternative to mechanical CAD and/or simulation labs would be to encourage students to bring to class their own laptops loaded with s/w solutions listed above, and/or, may be, the student versions of the commercial software.

The shortcomings found in these open source s/w, if any, should be removed by collaborative contributions from academia, governments etc. Indeed, this has already been happening since past several years.

Please do contact/comment for your suggestions, clarifications etc.

Thursday, February 4, 2016

A simple finite differencing example using Matlab/Octave

Listening to the queries of some students and researchers, a need was felt for writing a small and simple tutorial blog post giving a simple finite differencing example using Matlab/Octave.

Taking 'x' as the independent variable and 'f(x) = sin(x)' as the dependent variable, the attached code demonstrates the calculation of first two derivatives.

In the code, taking xVec (= x0, x2, x3 .... xn) to represent the nodal values of 'x',
and,

y1 = sin(xVec);


and,

y3 = cos(xVec);

the derivatives of f(x) at the nodal points are calculated as:

1st derivative:y2 = Dmatx*y1;% dy/dx = Dmatx * y1

2nd derivative:
y4 = Dmatx*Dmatx*y1;% d2y/dx2 = Dmatx * Dmatx * y1

It must be obvious that (y1, y2, y3, y4) are ((n + 11) by 1) vectors and Dmatx is (n + 1) dimension square matrix.

The resulting plots:


For 1at derivative (with n = 10):

For 2nd derivative (with n = 10):



For 1st derivative (with n = 20):
For 2nd derivative (with n = 20):


Please do contact/comment for your suggestions, clarifications etc.

Downloads.

Happy Matlabbing/Octaving!

Monday, December 21, 2015

A Python/openpyxl based timetable tool for automatically updating class, room/lab, teacher and centralized timetables taking an ERP-like input from an excel spreadsheet

A Python/openpyxl based timetable tool

1. Each row (starting from second) in the file “TT_ERP_Input1.xlsx” in “inputs” directory gives the per-event (lecture, tutorial or lab) input for preparing all the above mentioned four timetables using the four Python script files (*.py).

2. An empty row (actually, just the first cell in that row) is sensed to stop further processing of the above stated input-file.

3. The folder “templates” has templates used to prepare class, teacher, room/lab and centralized timetables.

4. The four python scripts for preparing these four timetables are in the base directory.

5. I have used Python 2.7.9 and openpyxl 2.3.2 versions. Using (Open Source) Linux Mint 17.2. However, it is well known that all these tools work just as fine on any other operating system or distribution. LibreOffice 4.3.3.2 was used as the spreadsheet s/w.

6. Each python-script may be run at command prompt as:

$ python makeclasses.py

or, inside the ipython shell (recommended) as:

In [1]: execfile('makeclasses.py')

Based on the contents of file (inputs/TT_ERP_Input1.xlsx), the exact number of "Class_*.xlsx" files are created in the current folder. Same for the other three “*.py” script-files (Of course, the script "makecentralized.py" creates only one "Centralized.xlsx"). A clash in each of these four types of timetables is highlighted by the corresponding cell filled red.

7. The zip-file “openpyxlTT.zip” has all the four script files, templates etc. with proper directory structure.

Feel free to communicate suggestions, comment,s etc. and to make your own modifications etc.

Happy timetabling !!!!!

Thursday, November 20, 2014

Preparing a LaTeX article for Elsevier - example paper "Solving a heat equation in Octave/Matlab"

Below are the details of one of my recent presentation to postgraduate students.

Presentation Title: Preparing a LaTeX article for Elsevier

Example paper: "Solving a heat equation in Octave/Matlab"

The Octave script: myoctave1.m

The LaTeX input file: elsarticle-template-num.tex

The zip-file containing the five image files( one xfig file and its eps copy, four eps files having screen-shots of windows having resulting from the octave script given below) : allfigures.zip

The commands (on Ubuntu 14.04 with texlive etc.):

For getting the plots from Octave:

in konsole or any other terminal:

user@domain:~$ octave

octave> myoctave1

This pops out four windows having a plot each - the screen-shots given in the file allfigures.zip mentioned above.

For preparing the paper

latex elsarticle-template-num.tex
dvipdf elsarticle-template-num.dvi


The otput:
elsarticle-template-num.dvi

and 

elsarticle-template-num.pdf


Thanks for visiting!

Thursday, February 6, 2014

A tutorial on C++ based GSL code for solving partial differential equations (PDE) with finite differencing

Presented below is a C++ based code example of using GSL for solving partial differential equations with finite differencing.

The example problem is the free vibration case of an Euler Bernoulli beam.

Field equation:

EI (d4w/dx4) + (rho*A) (d2w/dt2) = 0

Boundary conditions:

Clamped:

w = 0, dw/dx = 0

Hinged:

w = 0, d2w/dx2 = 0

Free:

d3w/dx3 = 0, d2w/dx2 = 0

Notations are the usual ones.


The code begins

#include < iostream >
#include < fstream >
#include < math.h >

//REF.: http://www.gnu.org/software/gsl/manual/html_node/Linear-Algebra-Examples.html#Linear-Algebra-Examples
#include < stdio.h >
#include < gsl/gsl_linalg.h >
//REF.: http://www.gnu.org/software/gsl/manual/html_node/Linear-Algebra-Examples.html#Linear-Algebra-Examples

//REF.: https://www.gnu.org/software/gsl/manual/html_node/BLAS-Examples.html#BLAS-Examples
#include < gsl/gsl_eigen.h >
#include < gsl/gsl_blas.h >
//REF.: https://www.gnu.org/software/gsl/manual/html_node/BLAS-Examples.html#BLAS-Examples

using namespace std;

int main (){

 cout<<"Hello, i am eulerbeam1... \n";

 fstream ofl1;
 ofl1.open("eulerbeam1.res", ios::out | ios::ate);

 //REF.: http://www.techscience.com/doi/10.3970/sl.2011.006.115.pdf
 double E = 2.1e11, rho = 7.85e3, l = 1, b = 0.01, d = 0.005;
 double I = b*d*d*d/12, A = b*d;
 
 int Nnodes = 60;

 double x0 = 0, xn = 1;
 double deltax = (xn - x0)/(Nnodes - 1);
 double onb2deltax = 1./(2*deltax);

 gsl_vector * vector1 = gsl_vector_alloc(Nnodes);

 gsl_matrix * Cmatx_nt = gsl_matrix_calloc (Nnodes, Nnodes);//Coefficients for first derivative
 gsl_matrix * Cmatx_nt2 = gsl_matrix_calloc (Nnodes, Nnodes);//Coefficients for second derivative
 gsl_matrix * Cmatx_nt3 = gsl_matrix_calloc (Nnodes, Nnodes);//Coefficients for third derivative
 gsl_matrix * Cmatx_nt4 = gsl_matrix_calloc (Nnodes, Nnodes);//Coefficients for fourth derivative
 gsl_matrix * Cmatx_Id = gsl_matrix_calloc (Nnodes, Nnodes);//the Identitiy matrix
 gsl_matrix * Cmatx_K = gsl_matrix_calloc (Nnodes, Nnodes);//the Stiffness matrix
 gsl_matrix * Cmatx_M = gsl_matrix_calloc (Nnodes, Nnodes);//the Mass matrix
 gsl_matrix * Cmatx_invK_M = gsl_matrix_calloc (Nnodes, Nnodes);//for storingthe inv(K)*M

 //for 0th node
 gsl_matrix_set(Cmatx_nt, 0, 0, -1./deltax);
 gsl_matrix_set(Cmatx_nt, 0, 1, 1./deltax);
 //for nth node
 gsl_matrix_set(Cmatx_nt, Nnodes - 1, Nnodes - 2, -1./deltax);
 gsl_matrix_set(Cmatx_nt, Nnodes - 1, Nnodes - 1, 1./deltax);
 for(int i = 1; i < Nnodes - 1; i++){
  gsl_matrix_set(Cmatx_nt, i, i - 1, -onb2deltax);
  gsl_matrix_set(Cmatx_nt, i, i + 1, onb2deltax);
 }

 gsl_blas_dgemm (CblasNoTrans, CblasNoTrans,
     1.0, Cmatx_nt, Cmatx_nt,
     0.0, Cmatx_nt2);
 gsl_blas_dgemm (CblasNoTrans, CblasNoTrans,
     1.0, Cmatx_nt, Cmatx_nt2,
     0.0, Cmatx_nt3);
 gsl_blas_dgemm (CblasNoTrans, CblasNoTrans,
     1.0, Cmatx_nt2, Cmatx_nt2,
     0.0, Cmatx_nt4);

 gsl_matrix_set_identity(Cmatx_Id);


 gsl_matrix_memcpy(Cmatx_K, Cmatx_nt4);

 gsl_matrix_get_row(vector1, Cmatx_Id, 0);//for (deflection, w = 0) at x = 0
 //gsl_matrix_get_row(vector1, Cmatx_nt3, 0);//for (shear force, d3w/dx3 = 0) at x = 0
 gsl_matrix_set_row(Cmatx_K, 0, vector1);

 gsl_matrix_get_row(vector1, Cmatx_Id, Nnodes - 1);//for (deflection, w = 0) at x = 1
 //gsl_matrix_get_row(vector1, Cmatx_nt3, Nnodes - 1);//for (shear force, d3w/dx3 = 0) at x = 1
 gsl_matrix_set_row(Cmatx_K, Nnodes - 1, vector1);

 //gsl_matrix_get_row(vector1, Cmatx_nt, 0);//for (slope, dw/dx = 0) at x = 0
 gsl_matrix_get_row(vector1, Cmatx_nt2, 0);//for (moment, d2w/dx2 = 0) at x = 0
 gsl_matrix_set_row(Cmatx_K, 1, vector1);

 //gsl_matrix_get_row(vector1, Cmatx_nt, Nnodes - 1);//for (slope, dw/dx = 0) at x = 1
 gsl_matrix_get_row(vector1, Cmatx_nt2, Nnodes - 1);//for (moment, d2w/dx2 = 0) at x = 1
 gsl_matrix_set_row(Cmatx_K, Nnodes - 2, vector1);

 gsl_matrix_set_identity(Cmatx_M);
 gsl_matrix_set(Cmatx_M, 0, 0, 0);
 gsl_matrix_set(Cmatx_M, 1, 1, 0);
 gsl_matrix_set(Cmatx_M, Nnodes - 2, Nnodes - 2, 0);
 gsl_matrix_set(Cmatx_M, Nnodes - 1, Nnodes - 1, 0);

//Computing inv(K)*M through LU decomposition
 int signum; 
 gsl_permutation * p_lu = gsl_permutation_alloc (Nnodes);
 gsl_linalg_LU_decomp(Cmatx_K, p_lu, &signum);
 for(int i=0; i < Nnodes; i++){
  gsl_matrix_get_col (vector1, Cmatx_M, i); 
  gsl_linalg_LU_svx(Cmatx_K, p_lu, vector1);
  gsl_matrix_set_col(Cmatx_invK_M, i, vector1);
 }


//Computing eigenvalues and eigenvectors
 gsl_vector_complex *eval = gsl_vector_complex_alloc (Nnodes);
 gsl_matrix_complex *evec = gsl_matrix_complex_alloc (Nnodes, Nnodes);
 gsl_eigen_nonsymmv_workspace * myeigen_ws =
  gsl_eigen_nonsymmv_alloc (Nnodes);
 gsl_eigen_nonsymmv (Cmatx_invK_M, eval, evec, myeigen_ws);
 gsl_eigen_nonsymmv_free (myeigen_ws);
 gsl_eigen_nonsymmv_sort (eval, evec,
   GSL_EIGEN_SORT_ABS_DESC);
  

//saving the frequencies(Hz) in ascending order
 int i, j;
 double dumi= (1./(2*M_PI*l*l))*sqrt(E*I/(rho*A));
 for (i = 0; i < Nnodes; i++)
 {
  gsl_complex eval_i
   = gsl_vector_complex_get (eval, i);
  gsl_vector_complex_view evec_i
   = gsl_matrix_complex_column (evec, i);
  ofl1 << sqrt(1./(GSL_REAL(eval_i)))*dumi << " i" << GSL_IMAG(eval_i) << endl;
 }



 ofl1.close();
 cout << "Hello, i was eulerbeam1... \n";
 return 0;
}



The code ends.
Compilation command on a Linux console/command line:

g++ -lgsl eulerbeam1.cc -o eulerbeam1

Execution:
./eulerbeam1

Results give the following fundamental frequencies (Ref.: http://www.techscience.com/doi/10.3970/sl.2011.006.115.pdf):

Clamped-Clamped: 26.5281Hz
Clamped-Free: 4.44362 Hz
Simply-Supported: 11.7253 Hz