Wednesday, September 27, 2017
Not Enough Disk Space to Install High Sierra?
It's on Application folder. Just drag it to flash drive.
Just make sure that it have ntfs or hfs or Mac OS Extended format. FAT will not be able to copy it since it's more than 4GB.
Monday, July 3, 2017
Adding a Comma between Author and Year on Biblatex?
Simple, just add this line at preamble.
\usepackage[style=authoryear]{biblatex} \renewcommand{\nameyeardelim}{\addcomma\addspace}
Monday, June 12, 2017
Change '1st Edition' into 'Edisi 1' in LaTeX.
Of course the new problem arise. Like this.
Okay, thats not new problem (it's the kind of the last minute problem before the show, :D ).
So I add this line at the preamble.
\DefineBibliographyStrings{english}{ backrefpage = {disitasi pada halaman}, backrefpages = {disitasi pada halaman-halaman}, edition = {edisi}, in = {dalam}, and = {dan}, urlseen = {diakses pada} } \DeclareFieldFormat{edition}{\ifinteger{#1}{\bibstring{edition}~\mkbibordedition{#1}}{#1\isdot}}
Looks good.
Change the "Cited on Page" Strings in LaTeX.
The problem is "cited on page" and "cited on pages" string. It's supposed to be "disitasi pada halaman" and "disitasi pada halaman-halaman".
What I need is add this lines to preamble.
\DefineBibliographyStrings{english}{ backrefpage={disitasi pada halaman}, backrefpages={disitasi pada halaman-halaman} }
And I got this, :)
All was well, :)
HyperRef and Bookmark Combo in LaTeX.
I use this preamble in order to show bookmarks on PDF generated from my .tex file.
This way, we could navigate through part, chapter, section and subsection (depending on our depth setting) using table of content sidebar of PDF reader.
code \usepackage{hyperref} \hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor= ocre,bookmarks=true,bookmarksopen=true,bookmarksdepth=3,pdftitle={Title},pdfauthor={Author}} \usepackage{bookmark} \bookmarksetup{ open, numbered, addtohook={% \ifnum\bookmarkget{level}=0 % chapter \bookmarksetup{bold}% \fi \ifnum\bookmarkget{level}=-1 % part \bookmarksetup{color=ocre,bold}% \fi } }
Thursday, June 8, 2017
BibLaTex Problem
$ biber main.aux INFO - This is Biber 2.1 INFO - Logfile is 'main.aux.blg' ERROR - Cannot find control file 'main.aux.bcf'! - did you pass the "backend=biber" option to BibLaTeX? INFO - ERRORS: 1 Nugrohos-MacBook-Air:tesBibTex nugroho$
Me too.
The solution is simple, make sure the command is
$biber main
and not
$biber main.aux
Monday, June 5, 2017
Tuesday, May 23, 2017
Adding Piezo and Replace Tune O Matic on ES175 Replica.
Why? I want acoustic electric package in one guitar. In order to install Fishman piezo, I need to replace Tune O Matic with regular acoustic bridge saddle.
Is it success? Uh, oh, maybe.
What about sound after mod? It's nearly acceptable.
Nearly? Err, there's fret bussing, the action of the mod with acoustic saddle is too low.
Just that? There's intonation problem too, I couldn't set individual string length on the bridge.
Are you crazy? Yup.
Are you happy now? Not yet.
Guitar Intonation.
What's guitar intonation? Well, on traditional style guitar, with straight frets, the fret placement is based on a string or based on 'standard' measurement. The problem with this placement is while it's fine with 1st string, it doesn't sound right with 2nd string (b) or 3rd (G). Of course it's like Heisenberg Uncertainty Principle, if we make it work on G-string, it will sound wrong on high-e string.
Can it be solved? Some people using 'true temperament' system on their fretboard. The fret in this system is not straight but have a certain shape in order to get the strings perfectly in tune. Of course different string gauge will need different fret shape so one guitar will stuck on one type of string. (We might use another string, but it will out of tune, maybe worse than standard straight frets).
Okay, it's not generally practical. Is there another way?
Thursday, May 18, 2017
Playing with Memo in Delphi
I change the font in memo (tMemo) into courier. With this change, it's easy to do string manipulation with old Pascal style.
Below, I create small program with read input from edit into n variable. The input can only contain number 1 to 9.
The output is displayed on Memo. It's just number 123456789 (yeah, it has type string, but its number).
It's that all? No. The number's forming a 'cross' centered on number specified in edit. :)
Palindrom Checker
This simple program is using an edit as input, a button to trigger processing and a memo for output.
I used edit.text as s value and then reverse its value using for command and saved to rs variable.
We compared s and rs to determine that s is palindrom or not.
Here's the code
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Memo1: TMemo; Button1: TButton; procedure proses; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure tform1.proses; var s,rs:string; i:integer; palindrom:boolean; begin memo1.Text:=''; palindrom:=true; s:=edit1.Text; for i:=length(s) downto 1 do begin rs:=rs+s[i]; end; for i:=1 to length(s) do begin if s[i]<>rs[i] then begin palindrom:=false; break; end; end; memo1.Lines.Append(s); memo1.Lines.Append(rs); if palindrom=true then memo1.Lines.Append('is palindrom') else memo1.Lines.Append('is not palindrom'); end; procedure TForm1.FormCreate(Sender: TObject); begin memo1.Text:=''; end; procedure TForm1.Button1Click(Sender: TObject); begin proses; end; end.
Tuesday, May 16, 2017
Walking Star in Delphi's Stringgrid.
I use variable s, an array of string type variable.
For delay, or controlling the speed, I use application.processmessages and sleep() combo command.
This code fills cell with blank (space) value that corresponds with s, except one cell. This one cell then "moves" to the right, into the cell next to it.
For this purpose I declare two integer type variable, sx and sy. This variable add itself by one every step. Based on this two variable, the cell that should be filled with star is decided.
Monday, May 15, 2017
Digit Word.
ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT or NINE.
For example:
• BOUNCE and ANNOUNCE are digit words, since they contain the digit ONE.
• ENCODE is not a digit word, even though it contains an O, N and E, since they are not in order.
Here's my code on Delphi
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Memo1: TMemo; procedure proses; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; digit,cdigit:array[1..9] of string; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin memo1.Text:=''; digit[1]:='one'; digit[2]:='two'; digit[3]:='three'; digit[4]:='four'; digit[5]:='five'; digit[6]:='six'; digit[7]:='seven'; digit[8]:='eight'; digit[9]:='nine'; end; procedure tform1.proses; var s:string; i,j,k,n:integer; c:array[1..9]of integer; ck:array[1..9]of boolean; begin memo1.Text:=''; s:=edit1.Text; memo1.Lines.Append(s); memo1.Lines.Append(''); n:=length(s); for i:=1 to 9 do begin cdigit[i]:=''; c[i]:=1; ck[i]:=true; end; //looking for char for i:=1 to 9 do begin for j:=1 to length(digit[i]) do begin if ck[i]=true then begin ck[i]:=false; for k:=c[i] to n do begin if s[k]=digit[i][j] then begin ck[i]:=true; cdigit[i]:=cdigit[i]+s[k]; c[i]:=c[i]+1; break; end; end; end; end; end; //compare for i:=1 to 9 do begin memo1.Lines.Append(cdigit[i]); end; end; procedure TForm1.Button1Click(Sender: TObject); begin proses; end; end.
Wednesday, May 10, 2017
Animation using Matplotlib
As we could see at the code below that the animation part is in
ani = animation.FuncAnimation(fig, animate, np.arange(-10,10), interval = 25, blit=False)
Sunday, May 7, 2017
What About Unbounded End?
Yeah, what about it? The previous code have the both end bounded.
If we want a free/unbound end, we could set the condition at the with this properties (or we could choose whatever we like)
dy/dx=0
So we will have
y[1]-y[0]=0
y[0] = y[1]
if we want both free ends, we could set the other end as well
y[n] = y[n-1]
So, we just have to modify the original just a bit.
Beware though, with both ends free, we could lost the strings, :)
Saturday, May 6, 2017
Waves Equation Animation in Python
The main code is in def waves(y0,y1,cb) that use finite difference that solved initial value problem and boundary value problem simultaneously.
code from pylab import * import matplotlib.animation as animation fig,ax = subplots() def waves(y0,y1,cb): y2 = y0 for i in range(1,len(y0)-1): y2[i] = 2*y1[i]-y0[i]+cb*(y1[i+1]-2*y1[i]+y1[i-1]) return y2 x = linspace(0.,1.,20) dx = 1./(len(x)) y0 = sin(2*pi*x) vy0 = 12. b = 1./32. #dt2/dx2 dt = sqrt(b*dx*dx) print dt c = 1. cb = c*b y1 = y0 + vy0*dt print y0 print y1 line, = ax.plot(x,y0) def animate(i): global y0,y1,cb y2 = waves(y0,y1,cb) y0 = y1 y1 = y2 line.set_ydata(y0) return line, #plot (x,y0) ani = animation.FuncAnimation(fig, animate, np.arange(1,200), interval = 25, blit=False) grid(True) ylim(-10,10) show()
Tuesday, May 2, 2017
Gauss Jordan in Python.
Thursday, April 27, 2017
"Auto" Gauss Naif in Delphi.
After do this in Python, now it's time to bring it back to Delphi, where all of this is started, :)
The heart of code lay on this one
procedure tform1.gauss; var i,j,k:integer; temp:real; begin for i:=1 to 9 do begin for j:= 1 to i do begin if t[i,j]<>0 then begin temp:=t[i,j]; for k:= 1 to 10 do begin if i=j then t[j,k]:=t[j,k]/temp else t[i,k]:=t[i,k]/temp - t[j,k]; end; end; end; end; //back subtitution for i:=9 downto 1 do begin x[i]:=t[i,10]; for j:=9 downto i do begin if i<>j then x[i]:=x[i]-x[j]*t[i,j]; end; end;
You could say that it consists of zeroing lower tringle and normalizing the diagonal and then subtituting the value.
There's little failsafe code here, that is if we already have zero cell, don't proceed, or it will gave divided by zero error.
Gauss Naif in Python
It's actually just a matter of finding the pattern on that code and after we found the loop, we just have to well... loop it, :)
Wednesday, April 26, 2017
Manual Gauss Jordan in Python.
The idea is after we do operation to make the lower-triangle have zero value, we continue the operation until all the component in the upper-triangle have zero value too, and the diagonal have value of one.
Basically, the matrix becomes identity matrix. This way, we didn't need subtitution at all since all variables already has the exact value on the right side, :)
Tuesday, April 25, 2017
Manual Gauss Naif Elimination using Python
I use tuple, I think it's just the same as array for this purpose.
I created matrix a with random value. It's like linear equation system; three unknown variables with three equation. The purpose of this code is to find x1, x2 and x3.
Oh, in this case, its x0, x1 and x2, :)
Monday, April 24, 2017
That's Not Fair!
Maybe that's something come to our mind when we read this code. Yeah, that's forward dfference. It's designed to get the difference value using the point we calculate and the next one. That means the value will "lopsided" by nature, :)
Friday, April 21, 2017
Searching Multiple Roots Numerically.
The idea is we started from x=0 and walking to the positive direction and evaluating f(x) as we walk.
If there's change of the sign of f(x) from + to -, or vice versa, there must be a root in that area.
We began to surround it to find the-x that correspond to f(x)=0. That x value is the root.
After the root is found, we began to walk along x-axis again until found any sign change of f(x), or until x limit set on code.
Thursday, April 20, 2017
Manual Gauss Elimination on 3x3 Matrices in Delphi
Yes, there is many Gauss code out there. I plan to write it on next post about it. The dynamic Gauss Elimination code that could be implemented to any size of matrices.
But for now, let just settle on this.
https://youtu.be/csiFpdsrzzQ
Wednesday, April 19, 2017
Lagrange Polynomial Interpolation on Python.
It's a whole a lot easier than Newton's divided differences interpolation polynomial, because there is no divided difference part that need a recursive function.
Tuesday, April 18, 2017
Dewa.
Tentang religi, sepertinya @pitoyoamrih memang sangat berhati-hati sekali. Beliau menempatkan setting cerita bukan di dunia nyata kita (yang sudah penuh kontroversi religi), namun di dunia tersendiri yang bernama dunia wayang, :)
Pun demikian, toh dewa-dewa di dunia wayang @pitoyoamrih tidak bertindak sebagai Tuhan, namun sebagai makhluk dengan tugas dan kemampuan khusus.
Bahkan di banyak cerita, para dewa ini cenderung bertindak seperti oknum pejabat yang korup dan/atau sewenang-wenang sehingga perlu dilabrak oleh rakyatnya, :)
Sukati dan Penyukilan.
Monday, April 17, 2017
Tak Terduga dan Menyenangkan.
Unexpected and Enjoyable.
Sunday, April 16, 2017
Differentiation
How about slope of the function? How do we use differentiation to differentiate a function?
If we have y = f(x), we will have slope value on, say, (x0 , f(x(0)) by differentiate it.
m = dy/dx = df(x)/dx.
For slope on x0, just compute it.
We could plot the linear function that have form
y = m x + c
Saturday, April 15, 2017
Creating (And Editing) Movie using iPhone, Macbook Air and Final Cut Pro.
.
What we need?
Of course:
- A camera, I use iPhone Camera, I have iPad Pro but...
- A tripod, I use iPhone because my iPad couldn't be mounted on this.
- A Mac, Final Cut Pro only run on Mac, I use Macbook Air.
- ehm, keyboard, guitar, bass guitar, whatever.
- (optional), sound recording device, my iPad have decent video-sound, but sadly my iPhone isn't (maybe defect product), so I use Behringer Xenyx with usb interface and connect it to my iPhone using usb to lightning adapter.
- a metronome, since I don't use iPad to recording, I play metronome apps an it, :) .
Gibbous Moon
Lah, tapi kemarin kukannya jumat malam sabtu, dan di Indonesia hantu memiliki jadwal standart untuk muncul di kamis malam jumat dan tak ada urusan sama bentuk bulan.
Yeah, seperti kita yang ndak lagi hanya makan nasi jagung atau tiwul, tetapi juga suka spaghetti dan pizza, kemungkinan hantu-hantu Indonesia juga berkembang.
Mereka mungkin selalu update informasi bahwa di luaran sana ada waktu keluar hantu yang beda, bukannya "Malam Jumat Kliwon" tetapi "Friday Night". Ada juga pesta hantu tahunan saat hari jumat bertepatan dengan tanggal 13, yang di daerah jawa mungkin setara dengan tanggal Satu Suro.
Mungkin mereka juga berhubungan via media sosial dengan hantu-hantu luar negeri yang sharing bahwa ada komunitas hantu Eropa yang muncul saat bulan berbentuk benjol.
Friday, April 14, 2017
Numeric Integration using Python and Pylab
Let f(x) = x^2 and we want to integrate it from 0 to 1.
Numerically we could use square method or trapezoidal (which is almost better).
Masa Kecil
Childhood
Thursday, April 13, 2017
Flappy Bird Like in Delphi
Wednesday, April 12, 2017
Newton Polynomial in Python
I use this set of data point
(0,0)
(1,1)
(2,4)
(4,16)
(5,25)
and I use xc=3 for the test data.
It's obvious that these sets of data points have quadratic form and f(xc) must have value of 9.
The heart of code lay on this
def n(j,xc,x):
n = 1
for i in arange(j):
n *= (xc-x[i])
return n
def a(j,l,x,y):
if j==0:
return y[0]
elif j-l==1 :
return (y[j]-y[l])/(x[j]-x[l])
else:
return (a(j,l+1,x,y)-a(j-1,l,x,y))/(x[j]-x[l])
def N(xc,x,y):
N = 0
for j in range(len(x)):
N += a(j,0,x,y)*n(j,xc,x)
return N
Look at the function a(j,l,x,y), that's recursive function to obtain Newton divided difference value.
the whole code is this
from pylab import *
def n(j,xc,x):
n = 1
for i in arange(j):
n *= (xc-x[i])
return n
def a(j,l,x,y):
if j==0:
return y[0]
elif j-l==1 :
return (y[j]-y[l])/(x[j]-x[l])
else:
return (a(j,l+1,x,y)-a(j-1,l,x,y))/(x[j]-x[l])
def N(xc,x,y):
N = 0
for j in range(len(x)):
N += a(j,0,x,y)*n(j,xc,x)
return N
x = []
y = []
#initial value
x.append(0)
x.append(1)
x.append(2)
x.append(4)
x.append(5)
y.append(0)
y.append(1)
y.append(4)
y.append(16)
y.append(25)
#for testing
xc = 3
yc = N(xc,x,y)
print ''
print xc, yc
#plot
t = linspace(-7,7,100)
u = N(t,x,y)
plot(t,u)
grid(True)
show()
here's the graphics
with another sets of data points, I have another result
(0,0)
(1,1)
(2,4)
(4,16)
(5,25)
Tuesday, April 11, 2017
Disorientasi
Kadang bingung sedang membaca buku @PitoyoAmrih yang mana, saking konsistennya. Banyak cerita yang ada di buku satu, menyisip di buku lainnya. Seakan empat atau lebih buku itu sebenarnya cuma satu buku yang dijilid bukan berdasarkan urutan, namun berdasarkan tema.
Saat membaca "Antareja dan Antasena", tiba-tiba serasa baca "Wisanggeni Membakar Api" saat tiba di bagian Antasena menjadi jagung.
Juga saat membaca "Pertempuran Dua Pemanah: Arjuna-Karna" serasa membaca sisipan dari (atau malah babon) dari "Kebaikan Kurawa".
Apakah itu berarti jelek? Tidak sama sekali. Ini berarti penulis memiliki satu plot besar yang dicurahkan di berbagai buku.
Eh, tentu saja memang ada plot besar bernama pakem di pewayangan, :).
Hal yang menarik di sini, dengan berpegang pada plot besar, buku-buku Pitoyo Amrih memiliki konsistensi yang tinggi. Baca buku yang manapun tidak akan mengalami kebingungan tentang mana yang benar karena yang diceritakan bersumber dari hal yang sama. Namun ada juga detil-detil kecil yang menarik yang memang tidak ada di pakem atau (plot besar milik Pitaya Amrih sendiri), detil-detil ini membuat cerita menjadi menyenangkan karena tidak menjadi kaku karena pakem.
Banyak buku yang menjadi kaku karena terlalu ikut pakem, atau buku yang terlalu aneh karena tidak mempedulikan pakem sama sekali (jadinya pembaca malah mengernyit sambil mikir "Arjuna kok gini?", "Samba kok gitu?" dsb )
Ohya, saya belum baca semua buku Pitoyo Amrih, dalam proses, tetapi sudah pasti jadi pengagum beliau, :)
Disorientation
Newton Polinomial.
Here's code for Newton's divided differences interpolation polynomial (quite mouthful huh, :) ).
The purpose of this method is to create a function (polynomial) that passes through given set of data points.
I read data point from several edit box.
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
for i:=0 to n do begin
x[i]:=strToFloat(kx[i].Text);
y[i]:=strToFloat(ky[i].Text);
end;
xc:=strToFloat(kxc.Text);
yc:=fn(xc);
kyc.Text:=floatToStr(yc);
gambarNewton;
end;
kx and ky is tEdit created when button1 is clicked
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
button2.Enabled:=true;
button3.Enabled:=true;
button4.Enabled:=true;
button5.Enabled:=true;
n:=strToInt(edit1.Text);
kxc:=tEdit.Create(form1); kyc:=tEdit.Create(form1);
kxc.Parent:=form1; kyc.Parent:=form1;
kxc.Left:=36; kyc.Left:=72;
kxc.Width:=36; kyc.Width:=36;
kxc.Text:='0,5';
for i:=0 to n do begin
kx[i]:=tEdit.Create(form1); ky[i]:=tEdit.Create(form1);
kx[i].Parent:=form1; ky[i].Parent:=form1;
kx[i].Top:=36+36*i; ky[i].Top:=36+36*i;
kx[i].Left:=36; ky[i].Left:=72;
kx[i].Width:=36; ky[i].Width:=36;
kx[i].Text:=intToStr(i); ky[i].Text:=intToStr(i);
end;
end;
xc is x coordinate where the corresponding y (yc) is obtained using Newton method by calling it
yc=fn(xc)
function tform1.fn(xs:real):real;
var i:integer;fs:real;
begin
fs:=0;
for i:=0 to n do begin
fs:=fs+b(i,0)*c(xs,i);
end;
fn:=fs;
end;
the fn function call the two other function. The b function, a recursive contain divided difference like this
function tform1.b(i,j:integer):real;
begin
if i=0 then b:=y[0]
else if (i-j)=1 then
b:=(y[i]-y[j])/(x[i]-x[j])
else
b:=(b(i,j+1)-b(i-1,j))/(x[i]-x[j]);
end;
and c function, a recursive function (or you could rewrite it using simple for command)
function tform1.c(xs:real;i:integer):real;
begin
if i=0 then c:=1
else c:=(xs-x[i-1])*c(xs,i-1);
end;
and finally, draw the data and the function on image1
fprocedure tform1.gambarNewton;
var i,x0,y0:integer;px,py:real;
begin
x0:=image1.Width div 2; y0:=image1.Height div 2;
image1.Canvas.Brush.Color:=clLime;
image1.Canvas.Rectangle(0,0,image1.Width,image1.Height);
image1.Canvas.Brush.Color:=clWhite;
image1.Canvas.Pen.Color:=clBlack;
image1.Canvas.MoveTo(0,y0); image1.Canvas.LineTo(image1.Width,y0);
image1.Canvas.MoveTo(x0,0); image1.Canvas.LineTo(x0,image1.Height);
for i:=-300 to 300 do begin
px:=i/skala; py:=skala*fn(px);
image1.Canvas.Pixels[x0+i,y0-round(py)]:=clGreen;
end;
for i:=0 to n do begin
px:=x0+skala*x[i]; py:=y0-skala*y[i];
image1.Canvas.Ellipse(round(px)-7,round(py)-7,round(px)+7,round(py)+7);
end;
px:=x0+skala*xc; py:=y0-skala*yc;
image1.Canvas.Brush.Color:=clred;
image1.Canvas.Ellipse(round(px)-7,round(py)-7,round(px)+7,round(py)+7);
image1.Canvas.Brush.Color:=clwhite;
end;
Monday, April 10, 2017
Short Function.
Here's my implementation of function according to The Power of 10;
"Restrict functions to a single printed page."
As bonus, I didn't use global variable if possible. So if a function or procedure need a variable from others, it have to be passed using parameter on that function.
If we look at the code below, we know that it can be rewritten using a long single procedure or function. But according The Power of Ten, a function should be as short as possible so it could be printed in a single page.
So, instead one long multiple page function, I write/break it as several short-single-printed-page functions. :)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
procedure proses;
function konversi(a:real;c,d:char):string;
function konversiC(a:real;d:char):string;
function konversiF(a:real;d:char):string;
function konversiR(a:real;d:char):string;
function konversiK(a:real;d:char):string;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
proses;
end;
procedure tform1.proses;
var
a:real;
s,b:string;
c,d:char;
begin
a:=strToFloat(edit1.Text);
s:=edit2.Text;
c:=s[1];
s:=edit4.Text;
d:=s[1];
b:=konversi(a,c,d);
edit3.Text:=b;
end;
function tform1.konversi(a:real;c,d:char):string;
begin
case c of
'C':konversi:=konversiC(a,d);
'F':konversi:=konversiF(a,d)
'R':konversi:=konversiR(a,d)
'K':konversi:=konversiK(a,d)
else konversi:='error';
end;
end;
function tform1.konversiC(a:real;d:char):string;
begin
case d of
'C':konversiC:=floatToStr(a);
'F':konversiC:=floatToStr(a*9/5+32);
'R':konversiC:=floatToStr(a*4/5);
'K':konversiC:=floatToStr(a+273);
else konversiC:='Error';
end;
end;
function tform1.konversiF(a:real;d:char):string;
begin
case d of
'C':konversiF:=floatToStr((a-32)*5/9);
'F':konversiF:=floatToStr(a);
'R':konversiF:=floatToStr((a-32)*4/9);
'K':konversiF:=floatToStr((a-32)*5/9+273);
else konversiF:='Error';
end;
end;
function tform1.konversiR(a:real;d:char):string;
begin
case d of
'C':konversiR:=floatToStr(a*5/4);
'F':konversiR:=floatToStr(a*9/4+32);
'R':konversiR:=floatToStr(a);
'K':konversiR:=floatToStr(a*5/4+273);
else konversiR:='Error';
end;
end;
function tform1.konversiK(a:real;d:char):string;
begin
case d of
'C':konversiK:=floatToStr(a-273);
'F':konversiK:=floatToStr((a-273)*9/5+32);
'R':konversiK:=floatToStr((a-273)*4/5);
'K':konversiK:=floatToStr(a);
else konversiK:='Error';
end;
end;
end.
Another Turtle in Circle
So, I have another code for "Turtle in Circle" code, :)
In the script below, I use turtle position to determine if it's still inside circle or not. If it outside circle, instead of send it to zero position, I send it to random position inside circle.
import turtle
from random import uniform
import numpy as np
turtle.shape("turtle")
#turtle.speed(1)
x = 0
y = 0
rmax=40
for i in range (1,1000):
a = uniform (-90,90) #angle
turtle.left(a)
d = uniform (-75,75) #distance
x = turtle.xcor()+d*np.cos(a*np.pi/180)
y = turtle.ycor()+d*np.sin(a*np.pi/180)
r = np.sqrt(x*x+y*y)
if r>rmax:
turtle.setx(uniform(-rmax,rmax))
turtle.sety(uniform(-rmax,rmax))
x = 0
y = 0
else:
turtle.forward(d)
turtle.exitonclick()
Sunday, April 9, 2017
Turtle in Circle
I use previous code and improve it so the turtle could only move at certain circle area.
import turtle
from random import uniform
import numpy as np
turtle.shape("turtle")
#turtle.speed(1)
x = 0
y = 0
for i in range (1,1000):
a = uniform (-90,90) #angle
turtle.left(a)
d = uniform (-75,75) #distance
x += d*np.cos(np.pi*a/180)
y += d*np.sin(np.pi*a/180)
r = np.sqrt(x*x+y*y)
if r>40:
turtle.setx(0)
turtle.sety(0)
x = 0
y = 0
turtle.forward(d)
turtle.exitonclick()
Saturday, April 8, 2017
Random Turtle Movement.
I use turtle module, the standard module, in Python.
The turtle movement has random direction (angle), and random distance (forward/backward).
import turtle
from random import uniform
turtle.shape("turtle")
turtle.speed(1)
for i in range (1,100):
#random angle
a = uniform (-90,90)
turtle.left(a)
#random move
d = uniform (-100,100)
turtle.forward(d)
turtle.exitonclick()
The Power of 10
Rules for Developing Safety-Critical Code:
Avoid complex flow constructs, such as goto and recursion.
All loops must have fixed bounds. This prevents runaway code.
Avoid heap memory allocation.
Restrict functions to a single printed page.
Use a minimum of two runtime assertions per function.
Restrict the scope of data to the smallest possible.
Check the return value of all non-void functions, or cast to void to indicate the return value is useless.
Use the preprocessor sparingly.
Limit pointer use to a single dereference, and do not use function pointers.
Compile with all possible warnings active; all warnings should then be addressed before release of the software.
Friday, April 7, 2017
Prime Number on Python
for i in range (2,200):
prime = True
for j in range (2,i):
if i%j==0:
prime=False
if prime==True:
print i
Prime Number on Delphi
if (i mod 2 <>0) and (i mod 3 <>0) and (i mod 5 <>0) and (i mod 7 <>0) then i is prime.
Don't use that.
That's just for prime number below 100.
Use this instead.
var i,j:integer;
prime:boolean;
begin
for i:=2 to 200 do begin
prime:=true;
for j:=2 to i-1 do begin
if i mod j=0 then prime:=false;
end;
if prime=true then memo1.Lines.Append(intToStr(i));
end;
end;
Wednesday, March 29, 2017
Rutinitas Sore.
My sky is high, blue, bright and silent.
Nugroho's (almost like junk) blog
By: Nugroho Adi Pramono