Friday, May 10, 2013

Matlab/Octave for the UG students of the subject - Control Systems


Students of the subject “Control Systems” can use GNU Octave for practising Matlab code.
Following is an example of a simple session while using Octave version 3.6.3 under a Fedora 17 installation.
BODE PLOT
Example 1:
System: (1 + s)

octave:1> sys1 = tf([1 1],[1])

Transfer function 'sys1' from input 'u1' to output ...

y1: s + 1

Continuous-time model.
octave:2> bode(sys1)
octave:5>

The resulting plot:



Example 1:
System: 30/(1 + 0.5s)(s + 1)(s + 5)

octave:13> [numer, denom] = zp2tf([],[-2 -1 -5], 60)
numer = 60
denom =

1 8 17 10

octave:14> sys2 = tf(numer, denom)

Transfer function 'sys2' from input 'u1' to output ...

60
y1: -----------------------
s^3 + 8 s^2 + 17 s + 10

Continuous-time model.
octave:16> close all
octave:17> bode(sys2)
octave:18>
The resulting plot:
Thanks for visiting!

Wednesday, February 20, 2013

A simple Python based tool for preparing randomized multi-set multiple choice question papers

A simple Python based tool for preparing randomized multi-set multiple choice question papers
Scipy.in 2012, IIT-BPecha Kucha Presentation
December 27-29 2012
Ashish Sharma

The Problem
 A class full of students
 So much to teach
 Frequent, continuous evaluations – QUIZES
 Multiple choice or objective type questions
 Not enough invigilators
 Time constraints
 Quality of evaluations

The Solution
 Randomized multiple choice question papers – orders of questions and answers
 Python - for the randomized text manipulation
 The input is a set of three text (txt or tex) files containing – the questions and the answers,  the header and the footer
 The output is a chosen number question papers containing the same sets of questions and answer choices – both randomly differentiated in terms of order

The Code (download the zip file here: for text & for latex) – imports
import sys, random
import fileinput
from subprocess import call
........
infilename = sys.argv[1]
...........
for line in fileinput.input( infilename ):
...........
random.seed()
...........
call(['latex', outfilename + ".tex"])

A Typical Session – for text only
$ ./otqpr.py

Usage: ./otqpr.py infile.[txt/tex] N
N being the number of versions to be created.
infileH.[txt/tex] and infileF.[txt/tex] must exist to define the header and the footer

$ ls
in1F.txt  in1H.txt  in1.txt  otqpr.py

$ ./otqpr.py in1.txt 3

$ ls
in1F.txt  in1H.txt  in1_OUTV0.txt  in1_OUTV1.txt  in1_OUTV2.txt  in1.txt  otqpr.py

A Typical Session – for latex input$ ./otqpr.py

Usage: ./otqpr.py infile.[txt/tex] N
N being the number of versions to be created.
infileH.[txt/tex] and infileF.[txt/tex] must exist to define the header and the footer

$ ls
Fig2.eps in1F.tex  in1H.tex  in1.tex  otqpr.py

$ ./otqpr.py in1.tex 3

$ ls
Fig2.eps in1F.tex  in1H.tex in1_OUTV0.pdf in1_OUTV1.pdf in1_OUTV2.pdf in1.tex otqpr.py

Typical Outputs – formatted .txt files
VERSION 1
Q. 1: The reason we are not crushed under the atmospheric pressure is
(A) the pressure inside us is almost same as the atmospheric pressure (B) the pressure is too small (C) we are strong enough (D) the resulting force is too small
Q. 2: A force can be providing
(A) neither a push nor a pull (B) either a push or a pull (C) only a pull (D) only a push

VERSION 2
Q. 1: The reason we are not crushed under the atmospheric pressure is
(A) we are strong enough (B) the pressure is too small (C) the pressure inside us is almost same as the atmospheric pressure (D) the resulting force is too small
Q. 4: A force can be providing
(A) neither a push nor a pull (B) either a push or a pull (C) only a push (D) only a pull


Thanks!

Thursday, November 22, 2012

Using Octave/Matlab for plotting a histogram showing frequency of byte-values in a file


octave:1> myfile = fopen('Pachmarhi3.png', 'rb');
octave:2> mydata = fread(myfile, 'uint8');
octave:3> size(mydata)
ans =
           72181       1
octave:4> hist(mydata, (0:255)');

octave:5> axis([0 255]);

octave:6> xlabel ("Byte value")

octave:7> ylabel ("Counts")
octave:8> title ("A histogram showing frequency of byte-values in a file");



octave:9>

 The file "Pachmarhi3.png":

Saturday, March 24, 2012

Potential areas for doing PhD using open source tools

1. General modeling and simulation problems across disciplines.
2. Computational mechanics of laminated composite plates - including static, dynamic (vibration) & buckling problems, both linear as well as non-linear
3. Applications of computational tools like Genetic Algorithm, Simulated Annealing, Neural Networks, Fuzzy logic etc.
4. Computation Fluid Mechanics (CFD) applied in several areas like - flow through pipes, bearings etc.
5. Cryptography - chaos based image encryptionwatermarking etc.
6. Computational Geometry applied to various fields like Finite Element Method (FEM), biology, CAD, computer communications, wild fire propagation etc.

Sunday, January 9, 2011

Solid Mechanics

Formulae: Stress Transformation
The necessary formulae for the plane stress case are as follows(ref. Solid Mechanics, Popov).Stresses on the $\theta$-plane.\begin{displaymath} \sigma_{x'}=\frac{\sigma_x+\sigma_y}{2} + \frac{\sigma_x-\sigma_y}{2} cos(2\theta) + \tau_{xy}sin(2\theta) \end{displaymath}\begin{displaymath} \tau_{x'y'}=-\frac{\sigma_x-\sigma_y}{2} sin(2\theta) + \tau_{xy}cos(2\theta) \end{displaymath}Principal planes\begin{displaymath} tan(2\theta_{1})=\frac{2\tau_{xy}}{\sigma_x-\sigma_y} \end{displaymath}This gives principal planes at $\theta_{11}$ and $\theta_{12}(=\theta_{11}+\pi/2)$. Principal stresses $(\sigma_{1}$ and $\sigma_2)$ corresponding to these planes are found from the formula for $(\sigma_{x'})$ above.Maximum shear stress $(\sigma_1$ ~$ \sigma_2)/2$ and its planes

Planes at 
and,
 
are the planes on which maximum shear stress occurs. Sense of maximum shear stresses corresponding to these planes are found from the formula for $(\tau_{x'y'})$ above.


Principal stresses and maximum shear stress can also be found directly as,

Friday, January 7, 2011

Computational Mechanics of Laminted plates

My research


PhD Thesis  produced following publications:
1. Stability and Vibration of Mindlin Sector Plates: An Analytical Approach, AIAA JOURNAL, Ashish Sharma, H.B. Sharda and Y. Nath, Vol. 43, No. 5, May 2005, pp. 1109-1116 
2. Stability and vibration of thick laminated composite sector plates, Ashish Sharma, H.B. Sharda and Y. Nath, Journal of Sound and Vibration, Vol. 287, 2005, pp. 1-23
3. Non-linear analysis of moderately thick sector plates, Y. Nath , H.B. Sharda and Ashish Sharma, Communications in Nonlinear Science and Numerical Simulation 10 (2005) 765-778
4. Nonlinear transient analysis of moderately thick laminated composite sector plates, Ashish Sharma, Y. Nath and H.B. Sharda, Communications in Nonlinear Science and Numerical Simulation
  • The thesis basically involved obtaining different solutions of five simultaneous partial differential equations
  • Two-dimensional Chebyshev polynomials were used for spatial discretization
  • Houbolt time-marching was used for temporal discretization for simulating the non-linear dynamic model
  • The code was written in C++ on LINUX platform
  • For linear algebra, the C++ library named TNT/JAMA were used
  • For word-processing,  pdflatex was used
  • For Figures & Plots, gnuplot and xfig were used

Tuesday, September 21, 2010

My Software Tools


Thanks to millions of individuals all over the world making the phenomenon called Linuxhappen, `i' have found the following tools quite indispensable in my academic pursuits with the help of computers.
  • vim - the nicest editor
  • gcc- the compiler
  • LaTeX- for numerically controlled text processing
  • Emacs- the great so-many-in-one editor
  • gnuplot- the plotting tool
  • xfig- the drawing tool 
  • gsl - the gnu scientific library