Pages

Showing posts with label matplotlib. Show all posts
Showing posts with label matplotlib. Show all posts

Saturday, May 14, 2011

Musing with booting time in Scientific Linux 6, Ubuntu Lucid, Windows 7


Just comparing in booting and login time between Scientific Linux 6, Ubuntu Lucid Lynx 10.04.2 LTS, Windows 7 Home Premium Service Pack 1, all system in 64 bit version.

All system already installed many software that can be used for daily activity like listening various audio formats, watching various video formats, office productivity, internet browsing, updated to the current version, installed in the same HDD(one laptop) with 4 partitions(Win 7, Ubuntu, SL, swap for Linux), development programs installed(C/C++ library, java SDK, python), converting audio/video(SL not).

Specific system configuration:
  • Ubuntu mostly installed by many programs(my primary workstation), i didn't tuned it at all. Installed since it alpha version and just doing upgrade until now version 10.04.2 LTS, using live CD version 64 bit.
  • SL only for fun and learning a red hat based distro. Installed from a 64 bit live DVD version.
  • Windows, i use it for other software that Ubuntu not had yet, like visio, wathing HD movie using ATI vga instead using the AMD processor. And it installed an Antivirus from Microsoft Security Essential cause it rarely false alarm, and firewall using windows default, i knew it could boot faster without it, but it will make me installing windows again and again, many non Microsoft programs turned off on startup like java server, matlab server, etc. This Windows already installed when i bought the laptop, urgh yikes :( , i wonder how much the cost reduced while it not included Windows 7 :p .

The tests result

Below is the code to draw the figure(bar chart comparison) above, using Python with matplotlib module

#!/usr/bin/python

from matplotlib.pylab import arange, bar, xticks, title, ylabel, grid, show, legend

# ubuntu, sl, win
ut = [39, 7, 6]; st = [50, 10, 13]; wt = [44, 122, 20]

idx = arange(3)
wdx = 0.25

grid()
ub = bar(idx, ut, wdx, color='orange')
sb = bar(idx+wdx, st, wdx, color='red')
wb = bar(idx+wdx+wdx, wt, wdx, color='blue')
legend((ub[0], sb[0], wb[0]), ('Ubuntu 10.04', 'SL 6', 'Windows 7'))

xticks(idx+wdx, ('Booting', 'Login', 'Shutdown'))
ylabel('time in seconds')
title('Less is better')
show()
My measurement procedure:
  • using stopwatch in Nokia N900 so my fingers reaction time are to be considered
  • all systems booted from grub2 provided by Ubuntu lucid
  • booting time measured from grub2 until it show login window
  • log on time measured from pressing enter(password already entered) in login window until it show desktop and ready to use(including the LED of HDD not blinking again), well i can use(open a program) while the LED still blinking but it took the same time just like i wait LED off then open a program(yes in this case only happened with windows 7)
  • just open an open office writer in all system, then close it
  • shutdown time measured from pressing shutdown until the laptop turned off.

Monday, April 11, 2011

LTI Transient-Response Analysis using Python(numpy, scipy, matplotlib)

In undergraduate Engineering Physics, i learn how to modelling a system by using a mathematical model of the system, to analyze the character of the system.

This script can be used to generate plot as in the Book of Modern Control Engineering 4th edition, International Edition, by Katsuhiko Ogata, Prentice Hall

Once when taking a subject Automatic Control is often to make a plot of LTI system, that generated in s(signal) domain by transforming mathematical model of the system using Laplace Transformation.

This example i took from page 307 of that book.
To plot transfer function =
(6.3223 s^2 + 18 s +12.811) / (s^4 + 6 s^3 + 11.3223 s^2 + 18s + 12.811)

The plot generated by those script as below

Thursday, March 24, 2011

Basic Using Scite for editing source code and running program

Sebelum bermain-main(atau serius) dalam menggunakan python sebagai scientific/engineering programming
Sebaiknya kuasai dulu tools-nya, belajar scite(sebagai code editor) dulu aja ah.

## Scite ##
Astaga besar sekali font pada editornya saat ane mo coba nulis source code,
cara ganti->  Options > Open Global Options File
lalu edit bagian pada line 328, ubah size menjadi 10(atw bisa disesuaikan dengan mata masing2) seperti berikut
    font.monospace=font:Lucida Console,size:10

Oke mata udah nyaman saatny coding...
PENTING sebelum menulis kode, simpan file dulu dalam ekstensi .py misal kode gue ksh nama foo.py (Halah belom nulis dah ngesave dulu LOL). Tujuannya agar fitur indentasi dan syntax coloring(kodenya warna-warni oiy).

Selanjutnya silahkan coba kode berikut ditulis.
# ditulis setelah symbol '#' adalah comment, tdk di eksekusi oleh python
# classic test is print hello world in terminal/command prompt
print('Hello Python')

# membuat fungsi f(x) = x^2 + 4x + 2
def f(x):
    return (x**2 + 4*x + 2)
'''
identasi sangat penting di python
def f(x):
return (x**2 + 4*x + 2)
SALAH
'''
# memberikan nilai untuk y = f(x) dengan x = 9
x = 9
# cek nilai x
print('Nilai x ='), (x)

# hitung f(x) dgn x = 9, dan berikan hasilnya ke y
y = f(x)

# print hasil
print("Nilai y ="), (y)

# nilai x dari 0 - 10  
# walau sblmny sdh diberikan x = 9, maka x akan diganti dgn isi yg baru
x = range(11) # dapat jg dituliskan seperti -> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# hitung y dengan cara
y = [ f(i) for i in x]

# cek hasil x dan y yg baru
print('x yg baru'), (x)
print('y yg baru'), (y)

# plot hasil nya
# pertama import module pyplot dari matplotlib
from matplotlib import pyplot as plt 
# meng-import pyplot sekaligus mempersingkat nama module nya menjadi plt

# plot nilai y terhadap x, dan memberikan label utk legenda
plt.plot(x, y, label='x^2 + 4x + 2')

# meng-set label x
plt.xlabel('x')
# meng-set label y
plt.ylabel('f(x)')

# show label legend utk line y thd x
plt.legend()

# terakhir menampilkan
plt.show() # yeah show your plot babe!!

Untuk langsung nge-save  n me-running program, tekan F5...
It will be look like...

Instalasi Python untuk Engineering dan Science di Windows OS

Paket modul complete dari Enthought, Inc beserta tools pendukungnya bisa di download secara bebas dari
http://enthought.com/products/edudownload.php
ya tinggal isi first name, last name, email, institutional lalu klik download deh.. Ukuran sekitar 260 MB, saat nge-blog ini dah versi 7.0.2 , file yg di download epd-7.0-2-win-x86.msi

Untuk versi 64bit gunakan email akademik.

Jd gak perlu install manual utk python, numpy, scipy, matplotlib, sympy, ipython seperti  postingan yg utk install di ubuntu, info paket-paket yang ter-bundle ada di http://enthought.com/products/epdlibraries.php

Waktu nyoba ini ane pake Windows 7 Home edition 64 bit service pack 1, ori loh... Bawaan dari si fera, ferrari.

Yak untuk install di windows kayaknya gak perlu di share deh, secara bnyk yg pake windows daripada linux.. So sad.. Hiks..  : (
Tinggal klik sana sini acep ini itu, oh utk directory sebaiknya diganti jd C:\Python27epd\
Jaga-jaga barangkali nanti mo install python doang dari www.python.org

Jika sudah selesai maka akan ada shortcut kayak gini..

Instalasi Paket Sains(Scientific) dan Teknik(Engineering) di Ubuntu

Menginstal modul python untuk keperluan Sains(Scientific) dan Teknik(Engineering)
Spesifikasi saat artikel ini dibuat:
Ubuntu Lucid Lynx versi 10.04
numpy versi 1.3; scipy versi 0.7; matplotlib versi 0.99; sympy versi 0.6.6; ipython versi 0.10

Sebelumnya jangan lupa, harus ada koneksi internet...

Buka terminal aka command prompt
Login sebagai root (masukkan password anda)

sudo -i


lalu install dengan perintah

apt-get install python-numpy python-scipy python-sympy python-matplotlib python-matplotlib-data


dan tekan y untuk melanjutkan
lalu Ctrl-D utk logout sebagai root


Untuk menyesuaikan kompatibilitas dengan modul-modul versi EPD(Enthought Python Distribution) di windows, yah itu lah python ada di linux, and ada juga di windows, di N900 gue juga ada, huehehehe...
Jadi update python-numpy python-scipy python-sympy ke versi yg baru dengan cara memasukan perintah berikut(jgn lupa sebagai root)

easy_install -U numpy
easy_install -U scipy
easy_install -U sympy




saya mencoba mengupdate modul matplotlib dengan cara yg sama seperti diatas tapi gagal euy.. :(