Nugroho's blog.: computer
Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts

Saturday, December 10, 2011

Portable Python

When I wandering around, through virtual world, looking for Python reference of matplotlib, don't know what link I'd click, suddenly I'm landing in Portable Python page. Barely interested, not because it's not interesting, but I've already have python on my Mac and this Portable Python came with .exe download, such a tedious job if I try to run it on my machine (clearly, it's Windows apps). However, it's really useful distribution of Python.



At download section, it's recommended to download via torrent network, another interesting idea. Here some excerpt from Portable Python website



Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application.

One of the most powerful dynamic programming languages that is used in a wide variety of application domains and is used at many companies and institutions around the world ( YouTube, Google, NASA, Firaxis Games, etc.).

iRig

Several weeks ago my iRig package has come, finally. I expect it'll come earlier but alas my home's in the middle of nowhere surounded with forest and mountain, even google map refuse to map my place, :). At least it comes safely at my front door.

 I planned to use it with Amplitube on my iPad. It worked flawlessy of course. A minor annoyance, it's built in jack is undetachable, so it's uncool if you planned to bring it on your front pocket.

 I'm surprised when the thing work well with my macbookpro too. My 13' MacBook Pro only have one port audio, either for input or output, so it's big 'yeah yeah' for me for be able to record my guitar on GarageBand AND listen it.

 iRig work with GarageBand for iPad too, and several music apps like digital effect apps for ipad (forget its name), I'm sure not just that. Sadly, amplitube didn't support more space for effect, eight slot effect will cool. Here some screenshot.

From Blogsy Photos
From Blogsy Photos
From Blogsy Photos
From Blogsy Photos

Script Python untuk Menghitung Nilai Input berupa Fungsi

Script di bawah adalah kode python sederhana untuk menghitung nilai sebuah fungsi yang dimasukkan sebagai input pada variabel tertentu. Fungsi yang diinputkan bisa bermacam-macam.



Kita bisa memasukkan fungsi kuadrat, sinus, pangkat tiga dan lain-lain sebagai input.

import sys,parser
from math import *
y = sys.argv[1]
x = int(sys.argv[2])
z = parser.expr(y).compile()
print 'Nilai fungsi ', y, ' pada x = ',x,' adalah ',eval(z)


Simpan dengan nama f.py. Jalankan dengan perintah

python f.py

Berikut beberapa hasilnya, lengkap beserta kesalahan-kesalahannya

Nugrohos-MacBook-Pro:python nugroho$ python f.py x**2 4
Nilai fungsi  x**2  pada x =  4  adalah  16
Nugrohos-MacBook-Pro:python nugroho$ python f.py sin(x) 4
-bash: syntax error near unexpected token `('
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'sin(x)' 4
Nilai fungsi  sin(x)  pada x =  4  adalah  -0.756802495308
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'sin(x)+x**2' 4
Nilai fungsi  sin(x)+x**2  pada x =  4  adalah  15.2431975047
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'x**2+2x-8' 4
Traceback (most recent call last):
  File "f.py", line 5, in
    z = parser.expr(y).compile()
  File "", line 1
    x**2+2x-8
          ^
SyntaxError: invalid syntax
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'x**2-2x-8' 4
Traceback (most recent call last):
  File "f.py", line 5, in
    z = parser.expr(y).compile()
  File "", line 1
    x**2-2x-8
          ^
SyntaxError: invalid syntax
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'x**2-2*x-8' 4
Nilai fungsi  x**2-2*x-8  pada x =  4  adalah  0
Nugrohos-MacBook-Pro:python nugroho$ python f.py 'x**2+2*x-8' 4
Nilai fungsi  x**2+2*x-8  pada x =  4  adalah  16
Nugrohos-MacBook-Pro:python nugroho$ python f.py x**2+2*x-8 4
Nilai fungsi  x**2+2*x-8  pada x =  4  adalah  16
Nugrohos-MacBook-Pro:python nugroho$ python f.py "(x**2+2*x-8+sin(x))/(2*x+2)" 4
Nilai fungsi  (x**2+2*x-8+sin(x))/(2*x+2)  pada x =  4  adalah  1.52431975047
Nugrohos-MacBook-Pro:python nugroho$

Perhatikan bahwa lebih aman untuk menuliskan fungsi di dalam dua tanda petik (bisa petik satu ataupun petik dua).


Agar Python Lebih Manusiawi


Kita dapat menggunakan parser pada python untuk memasukkan input berupa fungsi atau persamaan. Namun, fungsi yang kita masukkan harus mengikuti aturan python, misal kita ingin fungsi y=x^2+2x+2, maka untuk input kita harus memasukkan  x**2+2*x. Memang tidak begitu merepotkan, namun akan lebih baik jika input yang kita masukkan sesuai dengan kebiasaan kita.


Untuk itu kita dapat menambahkan fungsi untuk mengubah x^2 menjadi x**2. Berikut adalah kode untuk melakukannya

>>> w='x^2'
>>> w.replace('^','**')
'x**2' 
>>> w
'x^2'
>>>

Hati-hati bahwa sintaks tersebut tidak benar-benar mengubah variabel w,dia tetap bernilai 'x^2' dan tidak dapat diproses. Untuk dapat mengubah string, maka kita perlu variabel baru untuk menampung dengan perintah y=w.replace('^','**'), atau tampung ke variabel itu sendiri dengan perintah w=w.replace('^','**'). Berikut adalah contohnya

>>> w='x^2'
>>> w
'x^2'
>>> w.replace('^','**')
'x**2'
>>> w
'x^2'
>>> y=w.replace('^','**')
>>> y
'x**2'
>>> w
'x^2'
>>> w=w.replace('^','**')
>>> w
'x**2'
>>> 

Dengan demikian pengguna dapat memberi input berupa x^2 atau x**2 untuk x pangkat dua.

Selain memakai perintah replace, kita juga bisa menggunakan regular expression menggunakan library re.
Berikut adalah hasil coba-coba menggunakan re.

Nugrohos-MacBook-Pro:~ nugroho$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s='persamaan pangkat 2''
  File "", line 1
    s='persamaan pangkat 2''
                           ^
SyntaxError: EOL while scanning string literal
>>> s='persamaan pangkat 2'
>>> s
'persamaan pangkat 2'
>>> import re
>>> re.sub("a",',',s)
'pers,m,,n p,ngk,t 2'
>>> s='persamaan pangkat 2'
>>> re.sub("\a",',',s)
'persamaan pangkat 2'
>>> s='persamaan pangkat 2'
>>> re.sub("\a",' ',s)
'persamaan pangkat 2'
>>> re.sub("a",' ',s)
'pers m  n p ngk t 2'
>>> s='persamaan pangkat 2'
>>> re.sub("a",'',s)
'persmn pngkt 2'
>>> s.replace('p','n')
'nersamaan nangkat 2'
>>> exit

Friday, December 9, 2011

Input berupa Fungsi Fleksibel pada Python dengan Menggunakan Parser


Saat kita membuat sebuah aplikasi, sering kita memberi kesempatan pengguna untuk memberikan input. Misal pada program untuk menghitung akar persamaan kuadarat ax^2+bx+c, kita memberi input berupa nilai a, b dan c. Ini berarti program yang dibuat hanya dapat menyelesaikan persamaan kuadarat dengan model ax^2+bx+c. Bentuk penulisan seperti ini disebut hardcode. Bagaimana misal jika kita menginginkan akar 3x^3-3? Atau menemukan nilai y=sin(x)? Tentu saja kita harus membuat program yang baru.



Pada python ada fungsi parser yang memungkinkan kita untuk memasukkan input berupa persamaan. Dengan demikian kita dapat membuat hanya satu program untuk misal menggambar grafik suatu fungsi dengan input berupa fungsi. Kita bebas memasukkan sebarang persamaan sebagai input.

Berikut adalah contoh program untuk menentukan nilai fungsi pada sebuah peubah. Dalam hal ini fungsi yang diinputkan adalah f=sin(x)*2x^2. Program mencari nilai fungsi tersebut pada x=10.

Nugrohos-MacBook-Pro:~ nugroho$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import sin
>>> import parser
>>> f="sin(x)*2*x**2"
>>> print f
sin(x)*2*x**2
>>> y=parser.expr(f).compile()
>>> x=10
>>> print eval(y)
-108.804222178
>>>


CUDA



Do you have a computer with NVIDIA Graphics Card. If by any chance the answer is yes then you probably can use that machine to do some cool paralel computation task in this area:
Computational Structural Mechanics
Bio-Informatics and Life Sciences
Medical Imaging
Weather and Space
Data Mining and Analytics
Imaging and Computer Vision
Computational Finance
Computational Fluid Dynamics
Electromagnetics and Electrodynamics
Molecular Dynamics


Yeah, if you bought NVIDIA powered machine this year or last year, your graphics card maybe supported paralel computing using CUDA.

CUDA™ is a parallel computing platform and programming model invented by NVIDIA. It enables dramatic increases in computing performance by harnessing the power of the graphics processing unit (GPU).

With millions of CUDA-enabled GPUs sold to date, software developers, scientists and researchers are finding broad-ranging uses for CUDA, including image and video processing, computational biology and chemistry, fluid dynamics simulation, CT image reconstruction, seismic analysis, ray tracing, and much more.

GPU Computing: The Revolution

It's hard to believe that twenty years ago we stuck on a machine with no GUI and no multitasking, at least multitasking is rare thing. And ten years ago we stop increasing speed of processor at 3GHz, more than that is either we burn our computer or move our PC using towing car as conductor can't be any smaller. Developer focused on multicore machine and cluster machine.

You're faced with imperatives: Improve performance. Solve a problem more quickly. Parallel processing would be faster, but the learning curve is steep – isn't it?

Not anymore. With CUDA, you can send C, C++ and Fortran code straight to GPU, no assembly language required.

GPU computing is possible because today's GPU does much more than render graphics: It sizzles with a teraflop of floating point performance and crunches application tasks designed for anything from finance to medicine.

History of GPU Computing

http://www.nvidia.com/object/cuda_home_new.html

The first GPUs were designed as graphics accelerators, supporting only specific fixed-function pipelines. Starting in the late 1990s, the hardware became increasingly programmable, culminating in NVIDIA's first GPU in 1999. Less than a year after NVIDIA coined the term GPU, artists and game developers weren't the only ones doing ground-breaking work with the technology: Researchers were tapping its excellent floating point performance. The General Purpose GPU (GPGPU) movement had dawned.

But GPGPU was far from easy back then, even for those who knew graphics programming languages such as OpenGL. Developers had to map scientific calculations onto problems that could be represented by triangles and polygons. GPGPU was practically off-limits to those who hadn't memorized the latest graphics APIs until a group of Stanford University researchers set out to reimagine the GPU as a "streaming coprocessor."

In 2003, a team of researchers led by Ian Buck unveiled Brook, the first widely adopted programming model to extend C with data-parallel constructs. Using concepts such as streams, kernels and reduction operators, the Brook compiler and runtime system exposed the GPU as a general-purpose processor in a high-level language. Most importantly, Brook programs were not only easier to write than hand-tuned GPU code, they were seven times faster than similar existing code.

NVIDIA knew that blazingly fast hardware had to be coupled with intuitive software and hardware tools, and invited Ian Buck to join the company and start evolving a solution to seamlessly run C on the GPU. Putting the software and hardware together, NVIDIA unveiled CUDA in 2006, the world's first solution for general-computing on GPUs.

Monday, December 5, 2011

Grapher on Mac OS X

Any wonder how "x power ten" curve is? Well, maybe not, we know that equation is just another parabolic like curve. But how about (x^3-3x)/(4x-3)? Maybe little calculation could help. How about e^x-x^2... (oh my God, WHAT IN EARTH YOU'RE TRYING TO SAY?)

It begin when I bought my first Mac. I realized that we could search anything using spotlight, even application and web.

Someday (forget where and when), when I surfing on internet for solution of mathematic function, I got a page full of wonderfull snapshot of exotic function on 3D with standart cartesian system, rotateable, etc. And it's said that OS X's Grapher did that. So I am Command-Space-ing my mac and voila... There's Grapher, apps I never know exist on my mac did appear.

Grapher have capability to draw almost any kind of equation. It can draw an equation in 3D or 2D. We can draw parametric function in Grapher as well.

Yeah, Grapher is, at least for me, hidden functional application brought by OS X.

The best of all, it's free, :)

Thursday, December 1, 2011

iPad 1 Mirorring without Cydia's DisplayOut on iOS 4.3.3


Many of iPad 1 owner rely on Cydia's DisplayOut app for mirorring their display device on LCD or projector. However, althought just few, some had problem with iPad Dock to VGA connector to get worked with it.
Some experienced a blank display when using VGA connector. It's weird because if we enable 'dotting', and touch iPad display, the dot appear on projector. Maybe that's minor issue when we want a iPad mirror using DisplayOut but we have an alternative (thanks to MacStories). This method can be applied on iOS 4.3.3.
Assumming we could SSH-ing our Ipad, we must navigate to system/library/coreservices/springboard.app. Edit files K48AP.plist (I'm using VIM for iPad), Add lines under with 
display-mirorring
save the change, restart the devices, pray, attach VGA connector, wait n see. :)
Of course we don't have to use VIM editor, we could just download K48AP.plist and edit it with our favorite text editor or plist editor. 

Monday, November 14, 2011

DropBox as iCloud-like Cloud

iCloud coming this fall bringing cloud computing capability to OS X Lion and iOS 5. So Mac user and iDevice (iPhone, iPod Touch, iPad) always have their data synced among their device.


I have a Macbook and an iPad. Unfortunately its OS is still old Snow Leopard and iOS 4.3.3 respectively. I tried to register at icloud.com but maybe apple had "track record" of my device because it ask me to upgrade my mac. Hm, I wonder why Windows Vista, an old released OS, is supported while 2009 released Snow Leopard is not.

Rumors is spread that Apple will bring iCloud capability to Snow Leopard through next 10.6.9 update. While it's good to be true, I've had applied cloud solution slightly longer than apple do, using Dropbox.

Using Dropbox, we can sync files on multiple device. Dropbox upload a file to Dropbox server and then the devices, with Dropbox client installed, compare file version in its local Dropbox folder.

Dropbox is also able to sync via LAN, resulting a faster sync.

Dropbox is available at appstore as free apps.

Saturday, November 12, 2011

iPad as Display Remote Device from Anywhere using iTeleport

We're already know we could access display of computer from other computer using software like VNC, provided we can "reach directly" that computer over network.


If we're using free hotspot or LAN network behind NAT, there is no problem about it, however, if remote display behind NAT it's likely we can't access our remote display easily.

Fortunately, for iPad user, there is iTeleport, an apps used for remote display client. It's act as common remote display through LAN but it's not just that. iTeleport has capability to remote a computer display from anywhere in the world (with internet acces, of course) through gmail connection.

iTeleport

One minor issue is keyboard. From screenshot, it's obvious that my mac use dvorak layout, however my ipad keyboard is still presenting QWERTZ keyboard; the result is gibberish character output if we type using default floating keyboard as is. Can be solved by setting back mac keyboard to QWERTZ.

iTeleport can be obtained at iTunes store. Here excerpt description from AppStore.

Teleport yourself to your computer from anywhere in the world. With its intuitive and patent-pending interface, iTeleport gives you full control of your computer's mouse and keyboard, and provides a rich visual display of your computer screens, without any screen resolution limit....

Friday, November 11, 2011

iPad Mirroring

Yeah, as we know, iPad2 have video mirroring feature using its HDMI cable whereas we, iPad user, stuck with "keynote only" VGA adapter, but there is alternative.


There are app designed to mirorring at iPad named DisplayOut. This app, as mentioned by its name, bring mirroring capability on iPad.

DisplayOut is available to purchase at Cydia. Available at Cydia means your iPad must already jailbroken.

I don't really know if this app work with iPad dock to VGA adapter as I didn't purchase it yet. But if you googling, you'll find there is problem with VGA adapter; it just give black screen. AV component seems have no problem though.

Jailbreaking is legal (at least in US) despite its voided warranty, so it's worth to try this app.

Monday, November 30, 2009

Integral menggunakan Metode Numerik di Python

Integral suatu fungsi merupakan jumlah luasan di bawah fungsi tersebut. Berdasarkan hal tersebut, maka kita dapat membuat sebuah algoritma untuk mencari luasan sebuah fungsi tanpa perlu mengintegralkan fungsi tersebut. Metode ini memiliki bentuk sebagai berikut

From Ubuntu Karmic Koala


N adalah jumlah segmen Untuk mencari integral dengan cara numerik digunakan algoritma berikut:
  1. Bangkitkan x1, x2, ..., xn
  2. Masukkan nilai-nilai tersebut ke g(x)
  3. Jumlahkan nilai-nilai di langkah 2
  4. Bagi dengan N
  5. Kalikan dengan (b − a)
Misal, untuk mencari nilai integral

From Ubuntu Karmic Koala


menggunakan python, gunakan perintah seperti pada gambar 1 yang hasilnya dapat dilihat pada gambar 2.

Dapat dilihat bahwa hasil integral tersebut dengan Monte-carlo dengan 10 segmen adalah 150.36; agak jauh dari nilai secara analitis, yaitu 168.

Agar akurat, kita perlu memperbesar nilai N. Sebagai contoh, jika nilai N kita ubah menjadi 100, maka hasil integralnya adalah 166.203, lebih mendekati
nilai yang sebenarnya. Tentu saja dengan semakin besar nilai N maka akan (relatif) semakin lama pula penghitungannya.

Sebagai improvisasi, kita dapat menyajikan data hasil kode Python dalam bentuk web dengan webserver python atau mengatur agar user dapat memasukkan input saat runtime. Kita juga dapat memproses grafik menggunakan PILmenyimpan hasil perhitungan ke format excel dan membaca file excel hasil penyimpanan 


From Ubuntu Karmic Koala


From Ubuntu Karmic Koala


From Ubuntu Karmic Koala

Saturday, November 28, 2009

Ubuntu 9.10 Karmic Koala in Tablet PC HP TX2500

After having OpenSuSE 11.1 installed on my Tablet PC for about a year, I want to try installing Ubuntu 9.10 on my TX2500. I used Karmic Koala iso image for AMD64 architecture and start with liveCD choice first.

Using LiveCD, everything is seem work without problem. When a familar exotic GNOME welcome sound is heard, I suddenly jump and think ”hooray, this cool Tablet PC is finally supported by ubuntu...”. Ridiculous, yeah, but the big problem prevent me for installing ubuntu on TX2500 is that no sound support (hey..., how we can life without music...), so, realizing that it wasn’t problem anymore (as well as my pen and eraser on touchscreen), I decided to override my SuSE 11.1 with this Koala.

Oh yeah another pleasure is a popup offers me if I want to install Broadcom, SLModem and ATI propietary driver but, planned to install that after install to harddisk, I close that windows (uh, what the poin install something in live system?).

After install Koala and boot into its system, I wait for popup offerring propietary driver installation but it never showed up, but everything is OK:
  1. Sound is work, that’s good
  2. Digitizer is work, I can use my pen and eraser as pointer and primary click eventhough finger-touch isn’t work.
I, after a couple minute, finally found how to install propietary driver, using menu Hardware Driver, I installed Broadcom Wifi, SLModem and fglrx ATI propietary driver. I also want my system always updated and use newest soft- ware, so, using synaptic, I updated software and even upgraded kernel. Here the problem arise.

After updating softwares and upgrading kernel of Karmic Koala, sound refuse to sounding (aaaaaargh..), no sound hardware detected, volume icon represent dummy hardware. I think it’s ALSA problem (like other said when i googling for solution) so I download alsa-driver, alsa-utils and alsa-... and com- piled them form source (uh). Still no sound after restarting.

I do deep search at google again and found realy simple but powerful solution: deactivate slmodem driver from hardware driver and voilaaa...., my sound is back

Here some note from Karmic Koala on my TabletPC tx2500 series
  1. Sound is work
  2. Pen digitizer is work out of the box
  3. Broadcom Wifi is work (propietary driver)
  4. Remote is work out of the box. It can raise volume (master volume), play next/previous song on mp3-player
  5. Webcam could be accessed through cheese
  6. My Sierra HSDPA modem was detected automagically (no need wvdial command line, heheh)
  7. Compiz-fusion run smoothly, so I can use compiz 3D effect and emerald in my desktop

(for Oneiric Ocelot, see here)

From Ubuntu Karmic Koala


From Ubuntu Karmic Koala

Monday, November 9, 2009

Mencari Akar Persamaan menggunakan Python

Program berikut adalah program untuk mencari akar persamaan menggunakan metode Newton-Rhapson. Program tersebut memiliki inti di persamaan berikut:

From Aravir (am I Physicist?)


contoh-contoh programnya sebagai berikut:

mencari akar dari fungsi
From Aravir (am I Physicist?)


From Aravir (am I Physicist?)


Program diatas memiliki tebakan awal x=7, artinya program akan mencoba nilai f(7), jika f(7) bukan nol maka akan dicoba nilai x yang berikutnya sesuai dengan persamaan di atas, jika f(x)=0 maka program akan berhenti dan x adalah akar dari persamaan yang diberikan. Ketelitian program adalah 0.01, artinya jika f(x) bernilai kurang dari 0.01 maka x adalah akar dari persamaan yang diberikan. Ketelitian ini bisa diperkecil sesuai kebutuhan.

From Aravir (am I Physicist?)

dari output diatas dapat dilihat bahwa nilai x konvergen menuju ke nilai 4, sehingga dengan ketelitian 0,01 dapat simpulkan bahwa akar dari fungsi tersebut adalah 4



From Aravir (am I Physicist?)


From Aravir (am I Physicist?)

From Aravir (am I Physicist?)



From Aravir (am I Physicist?)

From Aravir (am I Physicist?)

From Aravir (am I Physicist?)


Ada kalanya hasil yang kita dapatkan kurang cocok, hal ini disebabkan karena iterasi yang kita tentukan terlalu sedikit, contohnya adalah fungsi berikut

From Aravir (am I Physicist?)

From Aravir (am I Physicist?)

From Aravir (am I Physicist?)


Hasil diatas memperlihatkan bahwa x belum mencapai batas kestabilan yang telah ditentukan. Untuk itu kita harus memperbanyak iterasi

From Aravir (am I Physicist?)


From Aravir (am I Physicist?)

Saturday, November 7, 2009

Simulasi Gerak Vertikal di Flash

Software yang dibuat dengan Flash ini mensimulasikan gerak vertikal dengan nilai awal kecepatan dan posisi yang dapat diubah-ubah oleh pengguna. Pengguna bisa memasukan berbagai nilai ketinggian dan kecepatan awal ke atas maupun ke bawah, atau tanpa kecepatan awal sama sekali (gerak jatuh bebas)

From Aravir (am I Physicist?)


Pada simulasi ini, rumus yang dipakai adalah:

g=10
v=v+g*dt
h=y+v*dt
(metode tersebut dinamakan metode Euler)

Nilai awal yang dibutuhkan adalah v dan h.

v adalah kecepatan awal benda; benda bisa dilempar ke atas (v positif) maupun ke bawah (v negatif)

h adalah ketinggian benda dari titik acuan (tanah).

Langkah-langkahnya adalah:
Buat document Flash baru
Buat objek
Convert objek menjadi movie
Pada instance, beri nama “bola”
Buat dua text input, pada instance masing-masing, beri nama kecepatan dan posisi
Buat tombol, pada instance, beri nama tombol
Klik frame pertama; pada jendela action ketikkan perintah berikut

kecepatan.text = 0;
posisi.text = 200;
acuan = 300;
t = 0;
dt = 0.01;
g = -10;
v = Number(kecepatan.text);
h = Number(posisi.text);
jalan = false;
bola._y = acuan-h;
_root.onEnterFrame = function() {
if (jalan == false) {
h = Number(posisi.text);
bola._y = acuan-h;
v = Number(kecepatan.text);
}
if (jalan == true) {
v = v+g*dt;
h = h+v*dt;
kecepatan.text = v;
posisi.text = h;
bola._y = acuan-h;
t+=dt;
waktu.text=t;
if (h<=0) { jalan = false; } } }; tombol.onRelease = function() { jalan = not (jalan); }; Untuk menjalankan program, tekan ctrl-enter Simulasi dapat langsung dijalankan dengan menekan tombol atau sebelum dijalankan, mengubah nilai-nilai awal. Kecepatan awal bisa diberikan, positif untuk kecepatan awal ke atas dan negatif untuk ke bawah). Posisi juga bisa diubah. Saat simulasi berjalan, posisi dan kecepatan tidak dapat kita ubah. Simulasi berhenti saat benda mencapai tanah (h=0) atau dapat kita hentikan dengan enekan tombol. Saat simulasi berhenti, kita dapat mengubah nilai posisi dan kecepatan kembali. Gambar-gambar Gambar. 1
From Aravir (am I Physicist?)


Gambar. 2

From Aravir (am I Physicist?)


Gambar. 3

From Aravir (am I Physicist?)


Gambar.4
From Aravir (am I Physicist?)


Gambar. 5

From Aravir (am I Physicist?)

Thursday, October 29, 2009

Tuesday, September 15, 2009

Sensor Gerak di MacBook Pro menggunakan Python dan AMSTracker

Sebuah diary dari album foto Facebook saya:

Software ini dibuat pada jumat pon malam sabtu wage 28-8-'09 dengan menggunakan bahasa Python setelah menyadari bahwa Macbook ku ternyata memiliki accelerometer, sebuah sensor gerak.

Software ini mensimulasikan bola-bola yang berserakan di lantai (bisa memantul) yang pergerakannya ditentukan oleh kemiringan bidang lantai. Kemiringan lantai ini diatur dengan memiringkan laptop. Detilnya agak mengerikan, tapi toh hasilnya lumayan.


Pertama menjalankan software ini kupikir ada yang salah, kok bolanya menggelinding ke kanan terus, ternyata mejaku yang miring, hei... software ini bisa buat waterpass lho.


From Aravir (am I Physicist?)

Salah satu sensor di laptop Apple merupakan sensor arah gravitasi atau sensor gerakan laptop atau sensor kemiringan. Semacam mendeteksi bidang horizontal. Aku belum menemukan cara langsung mengaksesnya tetapi ada AMSTracker yang bisa menampilkan output yang akan dipakai python untuk menentukan gerakan laptop.

Perintah untuk mengakses output sensor adalah sebagai berikut:
From Aravir (am I Physicist?)

Aku masih bingung, outputnya 3, kuanggap x, y, z. Mungkin masih ada output yang lain , tapi belum tahu cara mengetahuinya
-kalo laptop kumiringkan kiri-kanan, yang berubah x
-kalo laptop kumiringkan depan-belakang, yang berubah z
-yang y konstan menunjuk angka -1, gak tahu kenapa
Kayaknya aslinya memang sensor gravitasi, tujuan utamanya mendeteksi gerakan laptop; jika jatuh (gravitasi 0), maka harddisk otomatis berhenti.
Untuk memudahkan menjalankan software, AMSTracker dan file script python sebaiknya diletakkan di folder yang sama.



Cara menjalankannya adalah melalui perintah di console:
From Aravir (am I Physicist?)



atau buat sebuah file text berekstensi .sh yang berisi:
cd "`dirname "$0"`"
./AMSTracker -u 0.001 -s | python sensorGravitasi.py
Simpan di folder yang sama, dobelklik file tersebut untuk menjalankan software
hasilnya:


From Aravir (am I Physicist?)


From Aravir (am I Physicist?)


From Aravir (am I Physicist?)


From Aravir (am I Physicist?)



From Aravir (am I Physicist?)


From Aravir (am I Physicist?)

list perintah seluruhnya sebagai berikut:

#awal list program, simpan dengan nama sensorGravitasi.py#
###############
#sensor gerak
#oleh Nugroho Adi P
#bahasa: python
#
#########
import sys, os
from visual import *
from random import uniform
from visual.controls import *
scene.x=125
jumlah=19
a=vector(0,-10,0)
e=0.75
dt=0.01
s=17
b=-11
def change():
for bola in lbola:
bola.v=vector(0,uniform(0,23),0)
################
c = controls(title='Tombol-tombol', x=0,
y=0, width=100, height=300, range=200) # Create controls window
# Create a button in the controls window:
bt = toggle( pos=(0,0), width=77, height=30, text1='Jalan',
text0='Stop' )
br = button( pos=(0,100), width=77, height=30, text='Acak',
action=lambda: change())
################
box(pos=(0,b-0.5,0), height=1,length=37, width=37)
lbola=[]
for i in arange(jumlah):
bola=sphere(color=color.green)
bola.pos=vector(uniform(-s,s),uniform(-7,19),uniform(-s,s))
bola.v=vector(0,0,0)
bola.radius=uniform(1,2)
lbola.append(bola)
while 1:
c.interact()
#rate(97)
try:
line = sys.stdin.readline()
x = int(line.split()[0])
y = int(line.split()[1])
z = int(line.split()[2])
#print x, ' ',y,' ',z
except KeyboardInterrupt:
sys.exit(0)
except:
pass
if (bt.value==1):
for bola in lbola:
if bola.y-bola.radius>b:
a=vector(-x/5,-10,z/5)
bola.v=bola.v+a*dt
bola.pos=bola.pos+bola.v*dt
#tumbukan dengan lantai
if bola.y-bola.radius<=b:
bola.v.y=-bola.v.y*e
bola.pos.y=b+bola.radius+0.1
#tumbukan dengan dinding
if bola.x+bola.radius>=s:
bola.v.x=-bola.v.x*e
bola.pos.x=s-bola.radius-0.1
if bola.x-bola.radius<=-s:
bola.v.x=-bola.v.x*e
bola.pos.x=-s+bola.radius+0.1
if bola.z+bola.radius>=s:
bola.v.z=-bola.v.z*e
bola.pos.z=s-bola.radius-0.1
if bola.z-bola.radius<=-s:
bola.v.z=-bola.v.z*e
bola.pos.z=-s+bola.radius+0.1
###deteksi tumbukan antar bola
for i in arange(jumlah):
for j in arange(i+1,jumlah):
jarak=mag(lbola[i].pos-lbola[j].pos)
if jarak<(lbola[i].radius+lbola[j].radius):
arah=norm(lbola[j].pos-lbola[i].pos)
vi=dot(lbola[i].v,arah)
vj=dot(lbola[j].v,arah)
tukar=vj-vi
lbola[i].v=lbola[i].v+tukar*arah
lbola[j].v=lbola[j].v-tukar*arah
pantul=lbola[i].radius+lbola[j].radius-jarak
lbola[i].pos=lbola[i].pos-pantul*arah
lbola[j].pos=lbola[j].pos+pantul*arah
#####akhir list program###

323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)