Skip to content

Instantly share code, notes, and snippets.

View ryuichimatsumoto-single's full-sized avatar

Ryuichi Matsumoto ryuichimatsumoto-single

View GitHub Profile
#include<stdio.h>
int main()
{
int i=1;
int count = 0;
for(i=1;i<2017;i++)
{
if(i%20 < i%16)
{
count++;
@ryuichimatsumoto-single
ryuichimatsumoto-single / simpthon.c
Last active February 5, 2016 23:54
シンプソンの台形公式による積分の数値計算
#include<stdio.h>
#include<math.h>
//台形公式に用いる関数をここで定義
double func(double x)
{
return (x*x);
}
//シンプソンの台形公式の定義
@ryuichimatsumoto-single
ryuichimatsumoto-single / prob.c
Created January 20, 2016 13:48
n回の試行のうち、少なくとも1回カードを引く確率を計算(作り途中)
#include<stdio.h>
#include<math.h>
/*
少なくとも1回カードが排出される確率f(n,p)=1-(1-p)^n
において、n,pの情報からf(n,p)を求める
*/
double ProbabilityAtReastOneTime(int n,double p)
{
//例外の値が入力されたときは、仕方なく0を返す
if(n < 0 || p < 0 || p > 1)
@ryuichimatsumoto-single
ryuichimatsumoto-single / dice.py
Last active January 11, 2016 11:36
サイコロをn回振った時の出目をシュミレーション(A roll of the dice)
# coding: UTF-8
# サイコロを100回振った時の出目をシュミレーション(モンテカルロ法)
# 乱数は1〜6が同様に出る乱数(恐らく一様乱数)を使用
# 詳細は「http://qiita.com/yubais/items/bf9ce0a8fefdcc0b0c97」
import numpy as np
N= 100 #サイコロを振る回数
list = np.arange(N)
num = np.zeros(7)
for n in range(0,N):
#ここが計測手法f(X)の部分(1〜6の出目を生成)
@ryuichimatsumoto-single
ryuichimatsumoto-single / Gauss–Legendre.c
Created January 9, 2016 20:31
ガウス=ルジャンドル法に基づく円周率の計算プログラム(C言語版)
#define N 100
#include<stdio.h>
#include<math.h>
int main()
{
int i=0;
double a[N+1];
double b[N+1];
@ryuichimatsumoto-single
ryuichimatsumoto-single / Gauss–Legendre.py
Last active January 9, 2016 20:30
ガウス=ルジャンドル法に基づく円周率の計算プログラム(Python版)
# -*- coding:utf-8 -*-
import math
import time
from decimal import *
N = 3 # 試行回数
a = []
b = []
t = []
p = []
# -*- coding:utf-8 -*-
import numpy
import pylab
import math
import time
X = 0 # 的に当たった回数
N = 500 # 試行回数
# N回の試行を開始
@ryuichimatsumoto-single
ryuichimatsumoto-single / monte_carlo.py
Last active January 6, 2016 04:29
モンテカルロ法における円周率の近似値の計算
# -*- coding:utf-8 -*-
import numpy
import pylab
import math
import time
X = 0 # 的に当たった回数
N = 10000 # 試行回数
# 四分円の境界の方程式[y=√1-x^2 (0<=x<=1)]を描画
@ryuichimatsumoto-single
ryuichimatsumoto-single / 2015_japan_conpact_disc_sales.csv
Last active December 13, 2015 03:45
2015年 日本国内CD売上データ <Compact Disc Sales Data in Japan(2015)>
1位 178.3
2位 132.8
3位 104.5
4位 70.2
5位 68.2
6位 67.8
7位 62.1
8位 57.2
9位 53.1
10位 52.1
#include<stdio.h>
#include<math.h>
//毎度おなじみ階乗の計算
long int fact(int n)
{
if(n == 0)
{
return 1;
}