Nugroho's blog.

Thursday, May 2, 2013

Monte Carlo PI

 
c calculating pi by throwing stones
c
PROGRAM stones
IMPLICIT none
c
c declarations
REAL*8 area, x, y, DRAND48
INTEGER i, max, pi, seed
c
c set parameters (number of stones, seed for generator)
max = 1000
seed = 11168
c
c open file, set initial value, seed generator
OPEN(6, FILE='pif.dat')
pi=0
call seed48(seed)
c
c execute
DO 10 i=1, max
x = DRAND48()*2-1
y = DRAND48()*2-1
IF ((x*x + y*y) .LT. 1) THEN
pi = pi+1
ENDIF
area = 4.0 * pi/REAL(i)
WRITE(6,*) i, area
10 CONTINUE
STOP
END

PI on MPI

still trying...
 program main
include "mpif.h"
double precision PI25DT
parameter (PI25DT = 3.141592653589793238462643d0)
double precision mypi, pi, h, sum, x, f, a
integer n, myid, numprocs, i, ierr
c function to integrate
f(a) = 4.d0 / (1.d0 + a*a)

call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)


10 if ( myid .eq. 0 ) then
print *, 'Enter the number of intervals: (0 quits) '
read(*,*) n
endif
c broadcast n
call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
c check for quit signal
if ( n .le. 0 ) goto 30
c calculate the interval size
h = 1.0d0/n
sum = 0.0d0
do 20 i = myid+1, n, numprocs
x = h * (dble(i) - 0.5d0)
sum = sum + f(x)
20 continue
mypi = h * sum
c collect all the partial sums
call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,
& MPI_COMM_WORLD,ierr)
c node 0 prints the answer.
if (myid .eq. 0) then
print *, 'pi is ', pi, ' Error is', abs(pi - PI25DT)
endif
goto 10
30 call MPI_FINALIZE(ierr)
stop
end

Wednesday, April 24, 2013

Mencari Pi



Nilai Pi

Mencoba tanpa webworker. Pi dapat dihitung dengan kode berikut

var Pi=0, n=1, c=100000;
for (var i=0;i<=c;i++) {
Pi=Pi+(4/n)-(4/(n+2));
n=n+4;
}

perintah dalam tag <script> adalah sebagai berikut



function HitungPi()
{
var loop = document.getElementById("loop");
var c = parseInt(loop.value);
var f = parseFloat(loop.value);
var Pi=0, n=1;

try {
if (isNaN(c) || f != c ) {
throw("errInvalidNumber");
} else if (c<=0) {
throw("errNegativeNumber");
}

for (var i=0;i<=c;i++) {
Pi=Pi+(4/n)-(4/(n+2));
n=n+4;
}
document.getElementById("PiValue").innerHTML = Pi;
} catch (e) {
var msg = "Input Error: ";
if (e=="errInvalidNumber")
msg += "harus angka.";
else if (e=="errNegativeNumber")
msg += "Input harus positif.";
else
msg += e.message;

alert(msg);
}
}

.
Perintah dalam <body>

<label for="loop">Jumlah iterasi:</label>
<input id="loop" type="number" value="100" />
<input type="button" onclick="HitungPi()" value="Hitung Pi" />
<div id="PiValue">Nilai Pi</div>

Hello Canvas World

canvas's not supported
Back to first again
Tulisan di atas ditulis dalam canvas seperti kode di bawah. Di sini perintahnya adalah

context.fillText('Hello Canvas World',canvas.width/2-150,canvas.height/2+15);

context adalah '2d' dari canvas, dalam hal ini context kotak yang menyimpan perintah-perintah '2d' canvas seperti contoh diatas, yaitu menulis text.

fillText('tulisan', posisi_x,posisi_y) adalah perintah untuk menampilkan tulisan dengan warna sesuai fillStyle, yaitu 'green'

strokeText('tulisan', posisi_x,posisi_y) adalah perintah untuk menampilkan tulisan dengan warna 'tepi' sesuai strokeStyle yaitu 'red'



var canvas = document.getElementById('canvasexample'),
context = canvas.getContext('2d');

context.font = '38pt Arial';
context.fillStyle = 'green';
context.strokeStyle = 'red';

context.fillText('Hello Canvas',canvas.width/2-150,canvas.height/2+15);
context.strokeText('Hello Canvas',canvas.width/2-150,canvas.height/2+15);

Sunday, April 7, 2013

My Blackberry Experience (part3)

In term of ease of use, I prefer non qwerty phone, thus, I prefer other devices than blackberries (but z10, maybe)



Why I don't like qwerty phone, because I didn't use to it. My first smartphone has candybar form factor, w960i, and I barely use it keyboard because I prefer its handwriting method using stylus.



I still like it and hope iPhone include this feature (unfortunatelly Apple don't bother to include it). I think it's possible cause google applied it in its search engine (work on i Phone too)



I start to used dvorak on my macbook pro in 2009, and since then I "abuse" my home PC, my HP tx2100us, and two server at work keyboards to became dvorak layout. It's simpler and more balance (right and left stroke). Of course blackberry, with its infamous qwerty keyboard, slow me down a bit.



Unfortunately, it applies to iPhone too. Although it allows for changing layout, it don't provide dvorak. Nevertheless, I still prefer iPhone over blackberry because its ability to change its keyboard layout. I'm currently use azerty layout on iPhone.







http://aravir-rose.blogspot.com

My Blackberry Experience (part 2)

So, how about the Blackberry killer app, Blackberry Messenger?



I personally don't know what's so great about it and what's really different with others messenger apps.



My sister in law tell me that BBM benefit is ability to block people and prevent his/her to contact us. Because BBM connect people through PIN, blocked people won't be able to contact via phone number if didn't know our number or we change our number.



I though of that and feel that it's ridiculous. We know yahoo messenger, google talk, whatsapp and other messenger have blocking feature as well.



Another problem is PIN itself. It's tied to one device. While it comes handy as we don't need to create new account as we have new number, it ties us to just one device. If we get another blackberry device, we have to reinvite our contacts again (or just export it? IDK).



Sure whatsapp or LINE is very vulnerable, anyone had our number is able to contact us but what's so bad about it? They still able to text or call us, don't they? And it have (along yahoo, gtalk and other) great portability; we're free to change device and still use same account, even use it in desktop computer.



Maybe it's just me but I don't want to be tied with one device. (Don't you want to upgrade your blackberry device?)



Blackberry Messenger is still great app though, with million users of course, every blackberry owner use it. But in the end, I still found whatsapp or other traditional instant messenger come handy in term of portability.







http://aravir-rose.blogspot.com

Saturday, April 6, 2013

My Blackberry Experience (part 1)

After trying my sister-in-law's blackberry, I feel the urge to compare it with my 4S. This is the first post about it

Maybe it's not fair to compare that two device, iPhone is touch based device while blackberry is scroll-point-click based device, but I'm curious about why blackberry is so famous and became de-facto in business (at least in the past). Well, here is it...

My reaction the first time I grab the blackberry is, confused.

Maybe I used to touch my iPhone to make it work but the blackberry OS confuse me about almost anything. I don't even know how to unlock its display at first because "mute" button is "play" button, :).

The home screen displays few apps and when I want to open apps that not in home screen I have to scroll it down but wait,... it don't scroll. Apparently I have to click "all" first and then scroll it down. While it may easy but the problem is I have to highlight "all" first to click it. iPhone have fewer step to go to anything.

The first app I want to open is mail, it's app that make blackberry powerfull among businessman anyway and guess what? It is...

The push feature is great, it delivers email as "send" is clicked, and receives email as soon as the email sent by sender (whoever it is) thank to BIS.

Yeah, blackberry mail is ok but I found facebook for bb is terrible (second apps I opened after mail). Try to read a twenty lines comment and you know what I mean, you read several lines and when you scroll to read next lines, it goes to last lines, and few lines before last line, there is no way to read 'middle' line

....

Sure iPhone can't transfer file via bluetooth, or download music (or anything) outside app store, but it worth it, faster, smoother and I'll stick with it.


http://aravir-rose.blogspot.com
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)