Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / inverse_matrix.f95
Created February 5, 2020 02:50
Fortran 95 source code to calculate an inverse matrix by cofactor matrix.
!****************************************************
! 逆行列の計算(余因子行列)
!
! 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.
#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.
/*********************************************
* 線形計画法(シンプレックス法) *
*********************************************/
#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.
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.
!************************************************************
! 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 / regression_line_2.rb
Created March 15, 2019 02:03
Ruby script to calculate a simple linear regression line.(Ver.2)
#! /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.
#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.
#include "calc.hpp"
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
/**
* @brief 配列サイズ取得
@komasaru
komasaru / eigen_test.cpp
Created November 8, 2022 06:39
C++ source code to test C++ matrix library Eigen.
/***********************************************************
C++ 行列ライブラリ Eigen のテスト
* 様々な定義、宣言、計算方法を試行
* ベクトルの変数は英小文字、行列の変数は英大文字としている
DATE AUTHOR VERSION
2022.10.20 mk-mode.com 1.00 新規作成
Copyright(C) 2022 mk-mode.com All Rights Reserved.
***********************************************************/
@komasaru
komasaru / multiply_toom_cook_3.py
Last active November 6, 2022 07:00
Python script to multiply big-digit values with Toom-Cook 3-way method.
#! /usr/local/bin/python3.6
"""
Multiplication of big-digit values with Toom-Cook 3-way method
"""
import random
import sys
import traceback
class MultiplyToomCook3: