Skip to content

Instantly share code, notes, and snippets.

Avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / chudnovsky.cpp
Last active March 30, 2023 13:45
C++ source code to compute pi with Chudnovsky formula and Binary Splitting Algorithm using GMP libarary.
View chudnovsky.cpp
/***************************************************************
* Computing pi by Binary Splitting Algorithm with GMP libarary.
**************************************************************/
#include <cmath>
#include <iostream>
#include <fstream>
#include <gmpxx.h>
using namespace std;
@komasaru
komasaru / inverse_matrix.f95
Created February 5, 2020 02:50
Fortran 95 source code to calculate an inverse matrix by cofactor matrix.
View inverse_matrix.f95
!****************************************************
! 逆行列の計算(余因子行列)
!
! DATE AUTHOR VERSION
! 2019.12.24 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2013 mk-mode.com All Rights Reserved.
!****************************************************
!
module const
@komasaru
komasaru / calc.cpp
Created October 15, 2020 01:16
C++ source code to calculate a Lorenz attractor by Runge-Kutta's method.
View calc.cpp
#include "calc.hpp"
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
namespace my_lib {
@komasaru
komasaru / linear_programming.cpp
Created December 21, 2017 05:22
C++ source code to execute linear programming with Simplex method.
View linear_programming.cpp
/*********************************************
* 線形計画法(シンプレックス法) *
*********************************************/
#include <iostream> // for cout
#include <stdio.h> // for printf()
#define N_ROW 4 // 行数
#define N_COL 6 // 列数
#define N_VAR 2 // 変数の数
@komasaru
komasaru / fb_api.rb
Created August 18, 2013 03:22
Ruby script to get Facebook user informations by Facebook API.
View fb_api.rb
require 'json'
require 'net/https'
# 各種定数
URL_BASE = "https://graph.facebook.com/{ユーザID or ユーザ名}"
APP_ID = "{Facebook アプリの APP-ID}"
APP_SECRET = "{Facebook アプリの APP-SECRET}"
# [CLASS] Facebook API
class FbApi
@komasaru
komasaru / lu_decomposition_3.f95
Last active January 16, 2023 14:51
Fortran 95 source code to do LU-decomposition by Crout method.
View lu_decomposition_3.f95
!************************************************************
! LU 分解(クラウト法(Crout method))
!
! date name version
! 2019.03.08 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2019 mk-mode.com All Rights Reserved.
!************************************************************
!
module const
@komasaru
komasaru / test_daemon.py
Last active January 2, 2023 06:58
Python script to do a process as a daemon.
View test_daemon.py
#!/usr/local/bin/python3.6
import datetime
import sys
import traceback
from daemon import DaemonContext
from os import path
from time import sleep
from lockfile.pidlockfile import PIDLockFile
@komasaru
komasaru / regression_line_2.rb
Created March 15, 2019 02:03
Ruby script to calculate a simple linear regression line.(Ver.2)
View regression_line_2.rb
#! /usr/local/bin/ruby
#*********************************************
# Ruby script to calculate a simple lenear regression line.
# : y = a + b * x
# : 連立方程式を ガウスの消去法で解く方法
#*********************************************
#
class Array
def reg_line(y)
# 以下の場合は例外スロー
@komasaru
komasaru / calc.cpp
Created November 21, 2022 04:39
C++ source code to compute logistic regression.
View calc.cpp
#include "calc.hpp"
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
// 定数
static constexpr double kAlpha = 0.01; // 学習率
static constexpr double kEps = 1.0e-12; // 閾値
@komasaru
komasaru / calc.cpp
Last active November 10, 2022 11:22
C++ source code to interpolate by 3D-Spline.
View calc.cpp
#include "calc.hpp"
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
/**
* @brief 配列サイズ取得