tag:blogger.com,1999:blog-71079251328135910592019-04-14T15:22:33.137+05:30Programming, Numerical Computation and FOSSrandom thoughts on programming, numerical and scientific computing and free and opensource softwareUnknownnoreply@blogger.comBlogger38125tag:blogger.com,1999:blog-7107925132813591059.post-13833260139893037712014-07-24T23:30:00.001+05:302014-07-25T05:12:26.000+05:30Installing a Python 3 Scientific Computing Environment
Python is a versatile and complete scientific computing environment. With NumPy, SciPy and Matplotlib modules, it gets most of the capabilities that one finds in a barebones Matlab environment. After this, you can choose the modules appropriate to your applications. For example, Pandas adds data structures and analysis tools for data analysis. SymPy brings symbolic computing to Python. Then <img src="http://feeds.feedburner.com/~r/numericComp/~4/4pypSJiGKCY" height="1" width="1" alt=""/>Unknownnoreply@blogger.com1http://www.annigeri.in/2014/07/installing-python-3-scientific.htmltag:blogger.com,1999:blog-7107925132813591059.post-25602465123376821082013-01-04T00:11:00.001+05:302013-01-04T22:28:19.368+05:30Importing Modules into a Python Program
In Python, a module introduces a new namespace and adds functions, classes and variables into your programs, enabling them to do things which they would not be able to without the capabilities imported from the module
"Modules" in Python are what other programming languages call "libraries". You import a module with the import statement. Modules typically contain valid lines of Python code, <img src="http://feeds.feedburner.com/~r/numericComp/~4/fhvchd-FzBo" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.12395470000001315.2422193 74.962593200000015 15.4871973 75.285316200000011http://www.annigeri.in/2013/01/importing-modules-into-python-program.htmltag:blogger.com,1999:blog-7107925132813591059.post-39941352394127527992012-05-24T20:20:00.002+05:302012-05-24T20:20:30.331+05:30NumPy Array Indexing
Extracting values from and inserting values into a Python list object is intuitive and powerful
This post demonstrates how to access elements of a Python list object. Once this concept is understood for a list, it can be easily extended to multi dimensioned NumPy arrays in a straight forward manner.
Let us first generate a one dimensioned NumPy array containing 11 elements, with values <img src="http://feeds.feedburner.com/~r/numericComp/~4/_h9lgzjibE4" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/05/numpy-array-indexing.htmltag:blogger.com,1999:blog-7107925132813591059.post-13862545042624697292012-05-22T13:10:00.001+05:302012-12-20T00:27:14.282+05:30Direct Stiffness Method - An Overview
A brief overview of the direct stiffness method as applicable to skeletal structures
The direct stiffness method is a matrix method of structural analysis. This post pertains only to the analysis of skeletal structures, that is, structures that can be modelled using only 1D truss/beam elements in either 2D or 3D space. Further, element stiffness is explicitly derived from first principles.
In <img src="http://feeds.feedburner.com/~r/numericComp/~4/lWZTJTL-NNk" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/05/direct-stiffness-method-overview.htmltag:blogger.com,1999:blog-7107925132813591059.post-23740377047807354992012-04-12T11:49:00.000+05:302012-04-12T11:59:02.305+05:30NumPy Arrays
NumPy ndarray is a versatile n-dim array implementation and quite different compared to Scilab matrices
Let us begin with examining how NumPy and Scilab define and use arrays. In Scilab, all arrays are treated as two dimensional arrays. Therefore, size of a scalar in Scilab is reported as 1x1, that is 1 row and 1 column. So, there is no such thing as a vector or a one-dimensioned array. A row <img src="http://feeds.feedburner.com/~r/numericComp/~4/O7ynmZtpy_o" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/04/numpy-arrays.htmltag:blogger.com,1999:blog-7107925132813591059.post-26722125499395739802012-04-08T09:13:00.000+05:302012-04-18T06:46:55.793+05:30Direct Stiffness Method - DoF Numbering
An introduction to numbering degree of freedom numbers for direct stiffness method of analysis of skeletal structures
Direct stiffness method of analysis of skeletal structures represents skeletal structures using one dimensional truss or beam elements and sets up the stiffness equation, namely:
[K]{x} = {P}
where [K] is the structure stiffness matrix, {x} is the column vector of <img src="http://feeds.feedburner.com/~r/numericComp/~4/IoL5z9gPlAQ" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, India15.3647083 75.123954715.3034678 75.0449907 15.4259488 75.2029187http://www.annigeri.in/2012/04/direct-stiffness-method-dof-numbering.htmltag:blogger.com,1999:blog-7107925132813591059.post-30510046281272864062012-03-14T04:34:00.000+05:302012-04-12T08:55:42.706+05:30IPython Notebook
Interactive Python in your browser
IPython is a souped up Python shell with features such as inline help, tab completion, enhanced support for NumPy, SciPy and Matplotlib and a host of magic functions (IPython commands that begin with %).
But with version 0.12, IPython it goes one step further. It now introduces a web-based notebook. This means that you can access IPython running as a web <img src="http://feeds.feedburner.com/~r/numericComp/~4/7_Rplc0wMn0" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/03/ipython-notebook.htmltag:blogger.com,1999:blog-7107925132813591059.post-39397301720734996972012-03-06T09:43:00.000+05:302012-03-06T19:04:12.792+05:30Python Class for Numerical Integration
A Python class implementation of Trapezoidal and Simpson's 1/3 rules
This is a continuation of my previous post where I implemented a function for Trapezoidal rule. This time around, I will implement a class and include Simpson's rule. Along the way, I will point out the key differences between the procedural and object oriented approaches to programming.
Let us use the same polynomial <img src="http://feeds.feedburner.com/~r/numericComp/~4/tb6wHgO7dxA" height="1" width="1" alt=""/>Unknownnoreply@blogger.com1Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/03/python-class-for-numerical-integration.htmltag:blogger.com,1999:blog-7107925132813591059.post-85045798485553367742012-02-14T09:55:00.002+05:302012-03-05T12:57:16.686+05:30Python Function for Trapezoidal Rule
Implementing a function for numerical integration using trapezoidal rule
Here is the input I am assuming will be available:
A function of 'x' which we want to integrate. For illustration, let f(x) = 2x2 - x - 4. That is, the coefficients 2, -1 and -4.
The interval over which the function f(x) is to be integrated. In this illustration, say, from a=0 to b=5
The number of equal intervals into <img src="http://feeds.feedburner.com/~r/numericComp/~4/5DQz5WG_NSI" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/02/python-function-and-class-for.htmltag:blogger.com,1999:blog-7107925132813591059.post-34338488476081550602012-02-07T07:36:00.000+05:302012-02-14T11:05:45.929+05:30Python Class for Quadratic Equations
This posts implements a Python class to represent a quadratic equation, evaluate the equation, find its roots and a few special methods.
In continuation of the previous post where I implemented a Python class to represent a Line, this time I will dwell a little on its design and implement a few special functions.
A quadratic equation is of the form f(x) = ax^2 + bx + c and the things we <img src="http://feeds.feedburner.com/~r/numericComp/~4/Wm1uhjI6ZBA" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2012/02/python-class-for-quadratic-equations.htmltag:blogger.com,1999:blog-7107925132813591059.post-13094252485039212572012-02-06T08:02:00.001+05:302012-03-01T19:04:26.933+05:30Python Classes
This post demonstrates how to write a class in Python
Python supports object orientation but does not impose it. Programmer can choose to write programs entirely as a set of functions and function calls (procedural approach), entirely as classes with not a single user defined function outside a class (object oriented approach) or a mix of the two with both classes and user defined functions <img src="http://feeds.feedburner.com/~r/numericComp/~4/TlxTzca_Qbo" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034673 75.0449907 15.425949300000001 75.2029187http://www.annigeri.in/2012/02/python-classes.htmltag:blogger.com,1999:blog-7107925132813591059.post-37571258590229523052011-12-24T10:24:00.000+05:302012-02-18T05:02:10.930+05:30Scientific Python Development Tools
Identifying the tools needed to develop scientific and engineering applications using Python
Developing scientific and engineering applications in Python requires the following features/tools, some of which are common to all applications and a few specific to scientific/engineering applications. A programming environment with these capabilities is most likely to result in an application that <img src="http://feeds.feedburner.com/~r/numericComp/~4/Hc7bbEmDBhQ" height="1" width="1" alt=""/>Unknownnoreply@blogger.com1Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2011/12/scientific-python-development-tools.htmltag:blogger.com,1999:blog-7107925132813591059.post-32342031155577857732011-12-17T18:29:00.000+05:302012-03-02T05:20:17.935+05:30Plot Graphs of Trigonometric Functions using Python
Pylab, Python with NumPy, SciPy and matplotlib aims to provide a viable alternative to Matlab. Here is an attempt to show how to plot sine and cosine interactively as well as through a script. I will leave it to you to decide whether it is easier or tougher than using Matlab, Scilab or GNU Octave
First, the requirements. You must have installed, Python 2 along with the following modules - NumPy<img src="http://feeds.feedburner.com/~r/numericComp/~4/Mx76z9OFTk4" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2011/12/python-program-to-plot-graphs-of.htmltag:blogger.com,1999:blog-7107925132813591059.post-91143662083038596242011-12-16T23:01:00.004+05:302012-02-06T07:15:46.418+05:30Writing a Python Function
Python has the reputation of being easy to learn. So here is a function in Python to calculate the length of a line in 3D space. Well, it looks almost similar to the one written in Scilab
In a previous post, I discussed some aspects of designing functions and followed it up with implementing one in Scilab programming language. Well, functions in any programming language serve the same purpose, <img src="http://feeds.feedburner.com/~r/numericComp/~4/QH7wIA3BeoI" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2011/12/writing-python-function.htmltag:blogger.com,1999:blog-7107925132813591059.post-9763233270090488832011-11-29T10:31:00.001+05:302011-11-29T23:14:51.129+05:30Object Oriented Programming Concepts (with a C++ Flavour)
A comparison of the two approaches, procedural and object oriented, to program design, development and maintenance.
The title of the book by Niklaus Wirth, Algorithms + Data Structures = Programs aptly captures the essence of computer programming. The two components of programs, algorithms and data structures, are intimately related to one another and each exists to serve the other. While <img src="http://feeds.feedburner.com/~r/numericComp/~4/i4Cxzycb3EA" height="1" width="1" alt=""/>Unknownnoreply@blogger.com2Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2011/11/object-oriented-programming-concepts.htmltag:blogger.com,1999:blog-7107925132813591059.post-42437713452858447932011-11-26T12:01:00.001+05:302011-11-28T13:06:57.041+05:30C++ valarray
C++ valarray is a class template to represent an array of numerical values. It is versatile and comes with all basic features required for a one-dimensioned array.
Arrays in C++ are identical to those in C. Consequently, operators, such as, +, -, * are not defined for arrays. C++ classes are a user defined data type (UDT) for which the programmer can define operators, thereby making the UDT <img src="http://feeds.feedburner.com/~r/numericComp/~4/o9FDwjI1emE" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3034638 75.0449907 15.425952800000001 75.2029187http://www.annigeri.in/2011/11/c-valarray.htmltag:blogger.com,1999:blog-7107925132813591059.post-48694960123272951672011-11-25T23:05:00.000+05:302011-11-25T23:09:11.889+05:30C++ Class Templates
A class template is a parameterized class definition.
A class template in C++ is a parameterized class. That is, a class definition in terms of a placeholder for the data type that you intend to use when you want to instantiate an object of the class. If you think that is not a clear explanation, then here is an analogy. When you define a function, the input and output parameters are <img src="http://feeds.feedburner.com/~r/numericComp/~4/d8doWp47JvA" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.3647083 75.123954715.3647083 75.1239547 15.3647083 75.1239547http://www.annigeri.in/2011/11/c-class-templates.htmltag:blogger.com,1999:blog-7107925132813591059.post-38521911517582519002011-11-21T10:18:00.001+05:302011-11-21T22:31:26.457+05:30Array Indexing and Memory Allocation in Programming Languages
Demystifying array indexing and memory storage schemes used by programming languages
When it comes to arrays, the things to understand (wrap your brain around) are two things:
Internal storage allocated for the array
Indexing the elements of the array so that we can read from or write to those elements.
All programming languages agree on the first: Memory for an array is allocated in a <img src="http://feeds.feedburner.com/~r/numericComp/~4/AQdoKrpnnn4" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.2832795 75.056313 15.4057805 75.214241http://www.annigeri.in/2011/11/demystifying-array-indexing-and-memory.htmltag:blogger.com,1999:blog-7107925132813591059.post-64413832243699987312011-11-18T22:54:00.001+05:302011-11-20T06:50:25.055+05:30Object Oriented Numerics
Object oriented programming and scientific and numerical computing.
Some of my previous posts have dealt with arrays in C/C++, and some of the topics that have been discussed are:
Static arrays and dynamic arrays, both one- and two-dimensioned.
Dynamic arrays with user specified start index.
But some other issues remain. For example:
Attributes of the array, such as, the number of rows and<img src="http://feeds.feedburner.com/~r/numericComp/~4/gZL6oEYDU3Y" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.2832795 75.056313 15.4057805 75.214241http://www.annigeri.in/2011/11/object-oriented-numerics.htmltag:blogger.com,1999:blog-7107925132813591059.post-35446604817306358862011-11-16T03:17:00.001+05:302011-11-16T23:14:48.898+05:30Dynamic Two-dimensioned Arrays in C
Extending the concept discussed in dynamic one-dimensioned arrays to two-dimensioned arrays.
Let us now take the concept discussed in Static and Dynamic One-dimensioned Arrays in C forward. Here is the outline of what we intend to do:
Define 'p', a pointer to pointer to float, as the name of the 2D array.
To pointer 'p', let us allocate an array of 'm' elements of type 'pointer to float', Here<img src="http://feeds.feedburner.com/~r/numericComp/~4/SZjdCllXv8A" height="1" width="1" alt=""/>Unknownnoreply@blogger.com1Hubli, Karnataka, India15.34453 75.13527715.283288500000001 75.056313 15.4057715 75.214241http://www.annigeri.in/2011/11/dynamic-two-dimensioned-arrays-in-c.htmltag:blogger.com,1999:blog-7107925132813591059.post-34333079515313410552011-11-14T16:16:00.001+05:302011-11-16T02:34:38.909+05:30Scilab - Submatrix Operations
Getting up to speed with sub-matrix operations in Scilab
For a beginner, sub-matrix operations appear a little baffling. You may need time to master the techniques of sub-matrix operations, but once you do, they are nothing short of amazing.
Let us first see why we need them. Sub-matrix operations can do two things:
Extract parts of an existing matrix, and can stored in a new matrix for <img src="http://feeds.feedburner.com/~r/numericComp/~4/UoNUTB7hFAg" height="1" width="1" alt=""/>Unknownnoreply@blogger.com2Hubli, Karnataka, India15.34453 75.13527715.283288500000001 75.056313 15.4057715 75.214241http://www.annigeri.in/2011/11/scilab-submatrix-operations.htmltag:blogger.com,1999:blog-7107925132813591059.post-16790330521675230702011-11-13T08:12:00.001+05:302018-09-13T23:03:02.506+05:30"Free as in Freedom" - Richard Stallman's Biography by Sam Williams
Free as in Freedom is Richard M. Stallman's biography by Sam Williams that is available as an Open Book by O'Reilly.
It took me quite some time to fully comprehend the meaning of the word "Free" in the definition of "Free Software". But when I did finally understand it, its enormity was astounding. And the reason why Richard Matthew Stallman (RMS in short) tenaciously sticks to that word (and <img src="http://feeds.feedburner.com/~r/numericComp/~4/-j4yQYziDv8" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.283288500000001 75.056313 15.4057715 75.214241http://www.annigeri.in/2011/11/richard-stallmans-biography-by-sam.htmltag:blogger.com,1999:blog-7107925132813591059.post-76498416098948091602011-11-11T22:05:00.001+05:302011-11-16T03:22:46.696+05:30C/C++ Arrays with Arbitrary Start Index
Can you have a C/C++ array with any start index? Yes, provided they are created dynamically.
Arrays in C/C++ are indexed starting with zero. Arrays created at compile time (static arrays) always begin with the index zero and cannot be changed. Thus float x[10] creates an array with 10 elements are accessed using indexes starting from 0 up to 9 as x[0] to x[9]. The index of the initial element <img src="http://feeds.feedburner.com/~r/numericComp/~4/wYO2TdHoBmU" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.2832795 75.056313 15.4057805 75.214241http://www.annigeri.in/2011/11/cc-arrays-with-arbitrary-start-index.htmltag:blogger.com,1999:blog-7107925132813591059.post-23471843515614240472011-11-10T19:16:00.001+05:302012-04-18T06:50:38.514+05:30Polynomials in Scilab
Creating polynomials in Scilab and exploring operations on them.
A polynomial equation can be written as follows:
a0 + a1 x + a2 x2 + ... + an-1 xn-1 + anxn = 0
On the left hand side is the polynomial of order 'n', in terms of the independent variable 'x'. A polynomial of order 'n' requires 'n+1' coefficients ai, i = 0 to n. When the polynomial is equated to zero, it becomes a polynomial <img src="http://feeds.feedburner.com/~r/numericComp/~4/SXwsza1btKs" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.2832795 75.056313 15.4057805 75.214241http://www.annigeri.in/2011/11/polynomials-in-scilab.htmltag:blogger.com,1999:blog-7107925132813591059.post-38073469562326941962011-11-08T09:40:00.000+05:302011-11-10T21:58:06.944+05:30Scilab Script and Function Files
How is a script file different from a function file?
A script file may contain only Scilab executable statements or both executable statements and function definitions. On the other hand, a function file can contain only function definitions without any Scilab executable statements.
Whether it is a script file or a function file, it is written in a text editor (such as Notepad on Windows, vi/<img src="http://feeds.feedburner.com/~r/numericComp/~4/8cxrcO13Kwc" height="1" width="1" alt=""/>Unknownnoreply@blogger.com0Hubli, Karnataka, India15.34453 75.13527715.2832795 75.056313 15.4057805 75.214241http://www.annigeri.in/2011/11/scilab-script-and-function-files.html