Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
introduction to modern numerical analysis
Search
N@N
December 19, 2015
Technology
0
140
introduction to modern numerical analysis
数物セミナー冬の大談話会2015 in 大阪での発表資料
N@N
December 19, 2015
Tweet
Share
More Decks by N@N
See All by N@N
Finite Automaton equivalents to Regular Expression
spark6251
0
110
Programmer and English
spark6251
0
110
Let's go to the study session
spark6251
0
95
Quantum Computation
spark6251
0
260
Introduction to use Grunt
spark6251
0
80
Introduction to Regular Expression
spark6251
0
330
Introduction to SCSS+COMPASS
spark6251
0
270
Introduction to Psychology
spark6251
1
250
Introduction to HTML5
spark6251
0
260
Other Decks in Technology
See All in Technology
7日間でハッキングをはじめる本をはじめてみませんか?_ITエンジニア本大賞2025
nomizone
2
1.4k
Nekko Cloud、 これまでとこれから ~学生サークルが作る、 小さなクラウド
logica0419
2
730
「海外登壇」という 選択肢を与えるために 〜Gophers EX
logica0419
0
500
バックエンドエンジニアのためのフロントエンド入門 #devsumiC
panda_program
16
6.5k
組織貢献をするフリーランスエンジニアという生き方
n_takehata
1
1k
現場の種を事業の芽にする - エンジニア主導のイノベーションを事業戦略に装着する方法 -
kzkmaeda
2
1.5k
CZII - CryoET Object Identification 参加振り返り・解法共有
tattaka
0
240
Ask! NIKKEI RAG検索技術の深層
hotchpotch
13
2.8k
30分でわかる『アジャイルデータモデリング』
hanon52_
9
2.2k
偶然 × 行動で人生の可能性を広げよう / Serendipity × Action: Discover Your Possibilities
ar_tama
1
740
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
100
AWSでRAGを実現する上で感じた3つの大事なこと
ymae
3
1k
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
Raft: Consensus for Rubyists
vanstee
137
6.8k
It's Worth the Effort
3n
184
28k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
How STYLIGHT went responsive
nonsquared
98
5.3k
The Language of Interfaces
destraynor
156
24k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Navigating Team Friction
lara
183
15k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
None
• • •
• • • • • •
•
• • •
• • • •
! #include <iostream> int fact(int n) { if(n == 0)
{ return 1; } return n*fact(n-1); } int main() { std::cout<<fact(10); } fact(10) -> 10 * fact(9) -> 10 * 9 * fact(8) -> 10 * ... * 1 * 1 -> 10! = 3628800
! #include <iostream> int fact(int n) { if(n == 0)
{ return 1; } return n*fact(n-1); } int main() { std::cout<<fact(10); } fact 0 = 1 fact n = n*fact(n-1) main = do print $ fact 10
! int fact(int n) { if(n == 0) { return
1; } else if(n < 0) { return -1; } return n*fact(n-1); } fact 0 = 1 fact n | n > 0 = n*fact(n-1)
•
• • • • • •
• • • • •
• • • •
• •
• •
• • • • •
• • • • • •
• • • • •
• • •
, , ∈ ℤ; 1 ≤ , , ≤ 1000
, ,
( ∈ ℤ) ∈ ℤ≥0 ; 1 ≤ ≤ =
+ +1 + ⋯ + +−1 1 ≤ ≤ − + 1
0 = 0 + 1 + ⋯ + −1 1
= 1 + 2 + ⋯ + ⋮ = + + ⋯ + + ⋮ −+1 = −+1 + −+2 + ⋯ + • × − + 1
0 = 0 + 1 + ⋯ + −1 1
= 1 + 2 + ⋯ + = 0 − 0 + ⋮ = −1 − −1 + ⋮ = −1 − −1 + • 2 − •
None
std::cin std::cout
• • •
• •
• • constexpr • #define a b • const constexpr
None
None
op binary decimal 1 0000 0001 1 1 << 6
0100 0000 64 78 0100 1110 78 78 << 5 1100 0000 192
#include <iostream> #define N 1 << 8 // 1<<8 is
256. int main() { std::cout << N * 2; } 1. 512 (256 * 2) 2. 65536 (1<<16) 3.
#include <iostream> #define N 1 << 8 // 1<<8 is
256. int main() { std::cout << N * 2; } // -> 116
#include <iostream> #define N 1 << 8 int main() {
std::cout << N*2; } // -> 116 #include <iostream> int main() { std::cout<<1<<8*2; } // -> 116
#include <iostream> #define N 1 << 8 int main() {
std::cout << N*2; } // -> 116 #include <iostream> int main() { std::cout<<1<<8*2; } // -> 116 #define
#include <iostream> int main() { constexpr int N = 1
<< 8; std::cout << N * 2; } // -> 512
#define N (1 << 8)
•
auto x = 1; // x : int auto x
= 1.3; // x : double auto x; // error!
#include <iostream> #include <vector> int main() { std::vector<int> vec =
{0, 1, 2}; for(auto const& v : vec) { std::cout << v << " "; } } // 0 1 2
•
#include <iostream> int main() { std::cout << [](int x, double
y) { return x + y; }(3, 2.2); }
#include <iostream> int main() { auto add = [](int x,
double y) {return x + y;}; std::cout << add(3, 2.2); }
#include <iostream> int main() { auto add = [](auto x,
auto y) { return x + y; }; std::cout << add(3, 2.2); }
• func(int x) • func(int &x) • func(const int &x)
#include <iostream> void func(int x) { x++; } int main()
{ int a = 42; func(a); std::cout << a << std::endl; // =>42 }
#include <iostream> void func(int &x) { x++; } int main()
{ int a = 42; func(a); std::cout << a << std::endl; // =>43 }
#include <iostream> void func(const int &x) { x++; // error!
read-only! } int main() { int a = 42; func(a); std::cout << a << std::endl; }
std::vector<int> v(10e7); // void func(std::vector<int> x) {} // void func(const
std::vector<int> &x) {}
• • • • • •
• • • • • • • • •
• •
• + −1 −1 −1 + ⋯ + 0 =
• + −1 −1 −1 + ⋯ + 0 = 0 ,
• • • • Δ
≔ lim Δ→0 + Δ − Δ Δ , ≈
+ Δ − Δ + Δ = + , Δ Δ = 0 + 0 , Δ = 0 2Δ = Δ + Δ , Δ Δ, ⋯
• • • • Δ +1 •
+1 = + Δ 6 ,1 + 2,2 + 2,3
+ ,4 , ∈ ℕ 0 = 0 ,1 = , ,2 = + 1 2 Δ, + 1 2 Δ,1 ,3 = + 1 2 Δ, + 1 2 Δ,2 ,4 = + Δ, + Δ,3
• • • • • •
• • • • •
• • • •
• • • • • #include <boost/numeric/odeint.hpp>
void ode(const T &x, T &dxdt, const double t) {
dxdt = ~~~~; } void output(const T &x, const double t) { std::cout << ~~~~; } int main() { T x; boost::numeric::odeint::integrate( ode, x, 0.0, 10.0, 0.1, output); } ∶ 0 → 10, Δ = 0.1
using namespace boost::numeric::odeint; boost::numeric::odeint::integrate integrate
using namespace std; std::cout cout
= − = − − = − , ,
= − = − − = − dxdt[0] = sigma
* ( x[1] - x[0] ); dxdt[1] = x[0] * (rho - x[2]) - x[1]; dxdt[2] = x[0] * x[1] - beta * x[2];
typedef array<double, 3> T; constexpr double sigma = 10.0; constexpr
double rho = 28.0; constexpr double beta = 8.0 / 3.0;
void ode(const T &x, T &dxdt, const double t) {
dxdt[0] = sigma * (x[1] - x[0]); dxdt[1] = x[0] * (rho - x[2]) - x[1]; dxdt[2] = x[0] * x[1] - beta * x[2]; } void output(const T &x, const double t) { cout << t << '¥t' << x[0] << '¥t' << x[1] << '¥t' << x[2] << endl; } int main() { T x0 = {10.0, 1.0, 1.0}; // initial condition integrate(ode, x0, 0.0, 25.0, 0.1, output); }
None
std::ofstream ofs("lorenz.dat", std::ios::binary);
• • http://qiita.com/ignis_fatuus/items/74c b32815753d891a716
• http://qiita.com/ignis_fatuus/items/74c b32815753d891a716
= 1 + −1 + 1 + −1 2 ,
∈ ℝ
typedef complex<double> T; constexpr complex<double> i(0.0, 1.0); void ode(const T
&x, T &dxdt, const double t) { dxdt=(1.0+eta*i)*x+(1.0+alpha*i)*norm(x)*x; } int main() { T x(5.3, -2.0); }
+ −1 −1 −1 + ⋯ + 0 = 0
• 1 1 = , 2 = , ⋯ , = −1 −1 1 = 2 , 2 = 3 , ⋯ , −1 = = − −1 + −2 −1 + ⋯ + 0 1
2 2 + + = N ⋅ s2 m ,
N ⋅ s m , N m
2 2 + + = = = − − +
• • #include <boost/units/systems/si.hpp> #include <boost/units/io.hpp> std::ostream
= 2 m, s m2, m/s 5.5 [m]
• m + m = + m • m ×
m = × m2 • m + kg → • Ω = Ω ⋅ m × m m2 • •
• [s] • [m] • [kg] • [A] • [K]
• [mol] • [cd]
#include <boost/units/systems/si/prefixes.hpp> 1012 si::tera 102 si::hecto 10−3 si::milli 10−15 si::femto
using namespace boost::units; boost::units::si::length si::length
quantity<si::length, int> len; len = 1 * si::meters; // default
: double quantity<si::length> len2(5.0*si::meter); quantity<si::mass> mass; mass = 5.0 * si::kilogram;
quantity<si::length> len(10*si::meter); quantity<si::length> len2(5.0*si::meter); cout << len + len2; //
15 m
quantity<si::length> len(10*si::meter); quantity<si::length> len2; len2 = 5.0 * si::kilo *
si::meters; cout << len + len2; // 5010 m
quantity<si::length> len(10*si::meter); quantity<si::time> time(10*si::second); cout << len / time; //
10 m s^-1
quantity<si::length> len(10*si::meter); cout << len; // 10 m s^-1 cout
<< len.value(); // 10 cout << len; // 10 m s^-1
quantity<si::mass> len(5.0*si::meter);
quantity<si::length> len(10*si::meter); quantity<si::time> time(10*si::second); cout << len + time; //
error!
#include <boost/units/pow.hpp> quantity<si::acceleration> acc(10*si::meter / pow<2>(si::second)); cout << acc; //
10 m s^-2
#include <boost/units/pow.hpp> quantity<si::acceleration> acc(10*si::meter / si::second); // error! length time2
• • • •
• • • • • http://kaworu.jpn.org/cpp/
• • http://qiita.com/hmito/items/483445ac0d4 2fb4428a5 • • http://qiita.com/t_uda/items/7712671389e 016d24df6 • •
http://qiita.com/ignis_fatuus/items/74cb 32815753d891a716
• č • • http://www.slideshare.net/konn/haskell- 6-32258528 • • • •
• • • • •
• •
• • • http://nalab.mind.meiji.ac.jp/~mk/labo/t ext/
•