'Physics/Computational Physics'에 해당되는 글 5건
- 2014.11.17 The Mandelbrot set - python code
- 2010.03.25 윷놀이 기댓값을 구하는 프로그램 2
- 2010.01.07 자작 피규어
- 2009.12.12 Christmas Gift for Me
- 2009.04.30 Radio active decay 1
################################################### ## Python 2.7 ## The Mandelbrot set ## Written by Hasla ## Last Edited May 2nd 2012. ################################################### from matplotlib.pyplot import imshow, show, savefig from matplotlib import colors,cm from numpy import zeros, sqrt, log ################################################### def f(x,const):## Given function f return x*x + const ################################################### def solution(const):## solve with starting point x+yj and return some values about reached solution z = 0 + 0j value = 1.0 count = 100 for i in range(100): z = f(z,const) value = sqrt(z.real**2 + z.imag**2) count +=1 if(value>=2.0): return log(count)## Log of iteration makes structure finer. break else:##This "else" only works when "for loop" finished with out "break" return 0 ################################################### #####-----Set the Range-----##### maxran= 2 binval = 0.01 ################################# #####-----Set the Color map-----##### cmap = colors.ListedColormap(['black', 'white']) bounds = [0,0.1,700] norm = colors.BoundaryNorm(bounds, cmap.N) extent = (-2.,2.,-2.,2.) ##################################### #####-----Initialize-----##### maximum = 2*int(maxran/binval)+1 board = zeros([maximum,maximum]) ############################## #####-----Calculate-----##### x = -2.00001 count =0 for x_count in range(0,maximum): y = -2.00001 for y_count in range(0,maximum): board[y_count][x_count] = solution(complex(x,y)) count +=1 y += binval x += binval ############################# #####-----Output-----##### #imshow(board, cmap=cmap, norm=norm, extent=extent)##Black & White imshow(board, cmap=cm.hot, extent=extent)##Color savefig('result.png') show() ##########################
|
향민이형이 관련 내용을 포스팅 했기에 여기엔 내가 짯던 코드만 게시.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
int main()/*1 Dimensional Yut Nori*/
{
srand(time(NULL));
int i,j;
int k=0;
int n=0;/*Determine Do Gae Geol Yut Mo*/
int m=0;/*Steps for one trial*/
double rnd;
int max;/*Number of trial*/
printf("How many times do u want to try?\n");
scanf("%d",&max);
for(j=0; j<max; j++)
{
n=0;
m=0;
for(i=0; i<4; i++)
{
rnd=(double)(rand()/(RAND_MAX+1.0-1.0));
if(rnd<=0.6)
{
n++;
}
if(i==3&&n==0)
{
n=5;
}
if(i==3&&(n==4||n==5))
{
i= -1;
m=m+n;
n=0;
}
if(i==3)
{
m=m+n;
}
}
k=k+m;
}
printf("%lf\n",(double)k/(double)max);
return 0;
}
1. Younha 3rd Album Par. B + Poster
2. Computational Physics by R. Landau
Part A. 도 샀겠다... Part B. 도... 구입..
배송비도 좀 아낄겸 책을 둘러보다가 눈에띄는 Computational Physics by R. Landau.
흔히들 알고있는 소련의 물리학자 란다우가 아닌... 미국인 란다우. :O
구글을 통해 책 내용을 훑어보니 나쁘지 않은것 같고.. 가격도 저렴하여 구입...
=================================================================
2번의 책이 뭔가의 오류로 수급불능............ 해당가격에 대해서만 환불받았다.... 아쉽지만 다음기회로..
U235와 같은 불안정한 원소의 경우 비교적 빠른 시간안에 붕괴함을 볼 수있다.
그것에 관한 식을 살펴보자.
(1/N)(dN/dt)=-1/tau
위의 식에서 그 해를 찾는다면
N(t) = N0)exp(-t/tau)로 나타낼 수 있고
Taylor Expansion을 통해 유효한 항 까지 취한다면
N(t+Δt) = N(t)+(dN/dt) = N(t) - (N/tau)
의 꼴이 된다.
이 식을 바탕으로 c 언어를 사용해 프로그래밍을 해보면 소스코드는 다음과 같다
/* radioactivedecay.c
* Simulation of radioactive decay
*/
#include <stdio.h>
#include <math.h>
#define MAX 100
int main(void)
{
double n[MAX];
double t[MAX];
double dt;
double tau;
int i;
int j;
FILE *fp_out;
printf("initial number of nuclei->");
scanf("%lf",&(n[0]));
t[0]=0.0;
printf("time constant->");
scanf("%lf",&tau);
printf("time step->");
scanf("%lf",&dt);
for(i=0; i< MAX-1; i++)
{
n[i+1]=n[i]-(n[i]/tau)*dt;
t[i+1]=t[i]+dt;
}
fp_out=fopen("decay.dat","w");
for(j=0; j<MAX; j++)
{
fprintf(fp_out, "%g\t%g\n", t[j], n[j]);
}
fclose(fp_out);
return 0;
}