programmingII2019-v01

Similar documents
double float


p12.dvi

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

Condition DAQ condition condition 2 3 XML key value

Microsoft Word - C.....u.K...doc

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

r07.dvi

ohp07.dvi

資料

ohp03.dvi

PowerPoint プレゼンテーション - 物理学情報処理演習

r03.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

SystemC言語概論

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

273? C

r08.dvi

2008chom.pdf


gnuplot.dvi

新版明解C言語 実践編

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

GNUPLOT GNUPLOT GNUPLOT 1 ( ) GNUPLO

ohp08.dvi

1.3 2 gnuplot> set samples gnuplot> plot sin(x) sin gnuplot> plot [0:6.28] [-1.5:1.5] sin(x) gnuplot> plot [-6.28:6.28] [-1.5:1.5] sin(x),co

cpp1.dvi

2 I I / 61

joho09.ppt

第5回お試しアカウント付き並列プログラミング講習会

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

1 1 Gnuplot gnuplot Windows gnuplot gp443win32.zip gnuplot binary, contrib, demo, docs, license 5 BUGS, Chang

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

x1 GNUPLOT 2 x4 12 x1 Gnuplot Gnuplot,,. gnuplot, PS (Post Script), PS ghostview.,.,,,.,., gnuplot,,, (x2). x1.1 Gnuplot (gnuplot, quit) gnuplot,. % g

新・明解C言語 実践編

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

Debian での数学ことはじめ。 - gnuplot, Octave, R 入門

cpall.dvi

3. :, c, ν. 4. Burgers : t + c x = ν 2 u x 2, (3), ν. 5. : t + u x = ν 2 u x 2, (4), c. 2 u t 2 = c2 2 u x 2, (5) (1) (4), (1 Navier Stokes,., ν. t +


¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

C:/KENAR/0p1.dvi

-2 gnuplot( ) j ( ) gnuplot /shell/myscript 1

3. :, c, ν. 4. Burgers : u t + c u x = ν 2 u x 2, (3), ν. 5. : u t + u u x = ν 2 u x 2, (4), c. 2 u t 2 = c2 2 u x 2, (5) (1) (4), (1 Navier Stokes,.,

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

解きながら学ぶC++入門編

pptx

卒 業 研 究 報 告.PDF

05 I I / 56

yacc.dvi

SystemC 2.0を用いた簡易CPUバスモデルの設計

1.1 ft t 2 ft = t 2 ft+ t = t+ t d t 2 t + t 2 t 2 = lim t 0 t = lim t 0 = lim t 0 t 2 + 2t t + t 2 t 2 t + t 2 t 2t t + t 2 t 2t + t = lim t 0

ex01.dvi

2 T 1 N n T n α = T 1 nt n (1) α = 1 100% OpenMP MPI OpenMP OpenMP MPI (Message Passing Interface) MPI MPICH OpenMPI 1 OpenMP MPI MPI (trivial p

2 A I / 58

: (EQS) /EQUATIONS V1 = 30*V F1 + E1; V2 = 25*V *F1 + E2; V3 = 16*V *F1 + E3; V4 = 10*V F2 + E4; V5 = 19*V99

2017 p vs. TDGL 4 Metropolis Monte Carlo equation of continuity s( r, t) t + J( r, t) = 0 (79) J s flux (67) J (79) J( r, t) = k δf δs s( r,

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

1.ppt

joho07-1.ppt

Unix * 3 PC 2 Linux, Mac *4 Windows Cygwin Cygwin gnuplot Cygwin unix emulator online gnuplot *5 matplotlib *6 SuperMongo *7 gnuplot gnuplot OS *8 Uni

‚æ4›ñ

error_g1.eps

1.3 ( ) ( ) C

2014計算機実験1_1

Microsoft PowerPoint - 14Gnuplot.ppt

web07.dvi

PowerPoint プレゼンテーション - 物理学情報処理演習

Specview Specview Specview STSCI(Space Telescope SCience Institute) VO Specview Web page htt

Intel® Compilers Professional Editions

HABOC manual

ex01.dvi

BW BW

2 1 Mathematica Mathematica Mathematica Mathematica Windows Mac * Mathematica 9-1 Expand[(x + y)^7] (x + y) 7 x y Shift *1 Mathematica 1.12

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

LAN Copyright c Daikoku Manabu This tutorial is licensed under a Creative Commons Attribution 2.1 Japan License

fp.gby

C 資料 電脳梁山泊烏賊塾 ファイルの入出力 C++ のバイナリファイル入出力 初めに 此処では Visual Studio 2017 を起動し 新しいプロジェクトで Visual C++ の Windows デスクトップを選択し Windows コンソールアプリケーションを作成する

sim98-8.dvi

untitled


j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

tebiki00.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裱£²²ó ¡Ý½ÉÂꣲ¤Î²òÀ⡤±é½¬£²¡Ý

Microsoft PowerPoint - kougi9.ppt

tuat1.dvi

XMPによる並列化実装2

本 日 の 授 業 内 容 最 低 限 覚 えるべきUNIXコマンド pwd, ls, mkdir, cd, cp, rm, mv テキストエディタの 簡 単 な 使 い 方 テキストエディット, Jedit X,Emacs C 言 語 プログラミングの 初 歩 hello, world を 画 面

course pptx

0.2 Button TextBox: menu tab 2

WinHPC ppt

2008 IIA (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) ( )

86 6 r (6) y y d y = y 3 (64) y r y r y r ϕ(x, y, y,, y r ) n dy = f(x, y) (6) 6 Lipschitz 6 dy = y x c R y(x) y(x) = c exp(x) x x = x y(x ) = y (init

解きながら学ぶC言語

ohp11.dvi

r11.dvi

Informatics 2010.key

Transcription:

II 2019 2Q

A 6/11 6/18 6/25 7/2 7/9 7/16 7/23 B 6/12 6/19 6/24 7/3 7/10 7/17 7/24

x = 0 dv(t) dt = g Z t2 t 1 dv(t) dt dt = Z t2 t 1 gdt g v(t 2 ) = v(t 1 ) + g(t 2 t 1 ) v v(t) x g(t 2 t 1 ) t 1 t 2 t

v(t 2 ) = v(t 1 ) + g(t 2 t 1 ) = + x ( ) v V T g dv dt = g v(t) = mg 1 m v(t) e m t ϒ: t 1 t 2 t

(differential equation) h i v(t + t) = v(t) + g m v(t) v t (time step size) V T v(t) g t 1 t t t t 2 t

h i v(t + t) = v(t) + g m v(t) t mg v(t + t) = mg v(t) + apple 1 mg v(t) m t ṽ = v mg f t = m t t = t m ṽ( t + f t) = ṽ( t) + 1 ṽ( t) f t

(exact solution) v(t) = 1 t = 1 e t v 1 e t = 0.63 = 1 (time constant) t t = 0.1 1 e t = 0.63 t = 1 t

Xcode (1)

Xcode (2) mac OS > Command Line Tool Xcode Ver.

Xcode (3) Language: C++ Product name: 01FallingParticle Location:

Xcode (4) Xcode Preferences Locations Derived Data Relative

(2)Run main.cpp Build&Run (1) Build Succeeded OK (3) Console Hello OK

main.cpp #include <iostream> int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; return 0; } #include <iostream> int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; return 0; } v 0 = 0 t = 0.1 v(0) = v 0

#include <iostream> main.cpp: int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; std::cout << "v: " << v << std::endl; return 0; } Build, Run Console v: 0.0 OK C printf C++ std::cout std::cout << std::endl (end of line) std standard

#include <iostream> int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; std::cout << "v: " << v << std::endl; v = v + (1.0 - v)*dt; std::cout << "v: " << v << std::endl; return 0; } Build, Run v

#include <iostream> int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; int stepend = 100; int step = 0; std::cout << "v: " << v << std::endl; while(step < stepend){ v += (1.0 - v)*dt; v +=! v = v + step++; step = step + 1 std::cout << "v(" << dt*(double)step << ") = " << v << std::endl; } return 0; } t = t step Build, Run v

gnuplot #include <iostream> int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; int stepend = 100; int step = 0; std::cout << dt*(double)step << " " << v << std::endl; while(step < stepend){ v += (1.0 - v)*dt; step++; std::cout << dt*(double)step << " " << v << std::endl; } return 0; }

gnuplot Terminal Terminal cd (change directory) (1)cd (2) Debug drag & drop (3)Enter pwd ( /Debug/ )

gnuplot Terminal Terminal $./01FallingParticle Terminal $./01FallingParticle > data.txt

rm: Unix Terminal pwd (print working directory) cd: (change directory) ls:./../ cd../ cp: (cp data.txt data_copy.txt ) mv: (mv data.txt../)

gnuplot Terminal gnuplot $gnuplot gnuplot >set xlabel t >set ylabel v >plot data.txt title v

gnuplot >plot data.txt title v, 1-exp(-x)

gnuplot File > Save as PDF

Xcode #include <iostream> #include <cmath> (exp ) double Output(double t, double v, bool display){ double vexact = 1.0 - exp(-t); double error = (v - vexact)/vexact; if(vexact == 0.0) error = 0.0; if(display == true) std::cout << t << ": " << v << ", " << vexact << ", " << error << std::endl; return fabs(error); }; e(t) = v(t) v ex (t) vex (t) int main(int argc, const char * argv[]) { double v0 = 0.0; double dt = 0.1; double v = v0; int stepend = 10; int step = 0; Output(dt*(double)step, v, true); while(step < stepend){ v += (1.0 - v)*dt; step++; Output(dt*(double)step, v, true); } return 0; } t = 1 Output

gnuplot gnuplot pipe gnuplot gnuplot ( ) ( )

GnuplotInterface GnuplotInterface.h &.cpp pipe www2.kobe-u.ac.jp/~hayashi /01FallingParticle/01FallingParticle/ main.cpp drag & drop

in main.cpp header #include <iostream> #include <cmath> #include GnuplotInterface.h" #include (<> ) double Output(double t, double v, bool display){...} int main(int argc, const char * argv[]) { GnuplotInterface* gnuplot = new GnuplotInterface(); double v0 = 0.0; double dt = 0.1; double v = v0; int stepend = 10; int step = 0; Output(dt*(double)step, v, true); while(step < stepend){ v += (1.0 - v)*dt; step++; Output(dt*(double)step, v, true); } delete gnuplot; return 0; } (gnuplot )

#include <iostream> #include <cmath> #include "GnuplotInterface.h" double Output(double t, double v, bool display){...}; int main(int argc, const char * argv[]) { GnuplotInterface* gnuplot = new GnuplotInterface(); gnuplot->setaxislabel("x", "t"); gnuplot->setaxislabel("y", "v"); double v0 = 0.0; double dt = 0.1; double v = v0; int stepend = 10; int step = 0; Output(dt*(double)step, v, true); } gnuplot->injection("plot '-' title 'predicted', 1-exp(-x) \n"); gnuplot->injection(dt*(double)step, v); while(step < stepend){ v += (1.0 - v)*dt; step++; Output(dt*(double)step, v, true); gnuplot->injection(dt*(double)step, v); } gnuplot->injection("e\n"); delete gnuplot; return 0; - e shift + 7 PDF copy&paste

(1) (1) I (2) t dt stepend dt = 0.1 dt = 0.01 dt = 0.001 t = 1 dt dt t=1 gnuplot Terminal x1, y1 x2, y2 gnuplot (plot data.txt ) x3, y3 set logscale x (y ) (2) 01FallingParticleImplicit v(t + t) = v(t) + (1 v(t)) t v(t + t) v(t + t) dt = 0.1

(1) I (1) t 1 1/10 1/10

(2) (2) 01FallingParticleImplicit v(t + t) = v(t) + t 1 + t #include <iostream> #include <cmath> #include "GnuplotInterface.h" void Output(double t, double v, bool display){...}; int main(int argc, const char * argv[]) {... while(step < stepend){ v = (v + dt)/(1.0 + dt); step++; Output(dt*(double)step, v, true); gnuplot->injection(dt*(double)step, v); }... }

(2) (2) v(t + t) = v(t) + (1 v(t)) t v(t + t) = v(t) + t 1 + t

t 1 v(t + t) = v(t) + 1 1! dv dt t t + 1 2! d 2 v dt 2 t t 2 + O( t 3 ) v(t + t) = v(t) + (1 v(t)) t v(t) + 1 1! dv dt t t + 1 2! d 2 v dt 2 t t 2 + O( t 3 ) = v(t) + (1 v(t)) t apple dv 1 d 2 v = 1 v(t) + dt 2! dt 2 t t t 1 + O( t 2 ) (1st-order accuracy) t 1

(3) II v(t + t) = v(t) + t 1 + t

t = n t ( n) v n = v(t) v n+1 = v(t + t) n

df dt = g(f) f n+1 t f n = g(f n k, f n ) (k > 0) (explicit scheme) (implicit scheme) f n+1 t f n = g(f n±k, f n ) (k > 0)

v n+1 = v n + (1 v n ) t v n+1 = v n + (1 v n+1 ) t t 1 Crank-Nicolson f n+1 t f n = g(f n+1 ) + g(f n ) 2

Crank-Nicolson v n+1 t v n = 1 2 (1 v n+1 ) + (1 v n ) v n+1 = vn + 1 1 2 vn t 1 + t 2 #include <iostream> #include <cmath> #include "GnuplotInterface.h" void Output(double t, double v, bool display){...}; int main(int argc, const char * argv[]) {... while(step < stepend){ v = (v + (1.0 - v*0.5)*dt)/(1.0 + dt*0.5); step++; Output(dt*(double)step, v, true); gnuplot->injection(dt*(double)step, v); }... }

Crank-Nicolson Crank-Nicolson

Adams-Bashforth Runge-Kutta Crank-Nicolson Adams-Bashforth f n+1 t f n = 3g(f n ) g(f n 1 ) 2 Runge-Kutta Runge-Kutta f (1) f n t/2 = g(f n ) f n+1 f n t = g(f (1) )

Adams-Bashforth Adams-Bashforth Runge-Kutta Runge-Kutta

t 1 t 2

(Numerical stability) t t = 0.1

gnuplot (1/4) ( ) explicit.txt implicit.txt Terminal gnuplot Terminal plot explicit.txt, implicit, 1-exp(-x) Terminal >

gnuplot (2/4) std::ofstream C fprintf (Terminal > Xcode ) ( ) ( ) int main(int argc, const char * argv[]) { std::ofstream output("data.txt");... output << dt*(double)step << " << v << " << std::endl; while(step < stepend){... step++; output << dt*(double)step << " << v << " << std::endl; }... std::cout ofstream return 0; }

gnuplot (3/4) gnuplot Xcode ( ) gnuplot plot 'data.txt' using 1:2 title 'explicit', '' using 1:3 title 'implicit' 1,2 ( data.txt ) v Crank-Nicolson C std::vector< > double v output std::vector<double> v {v0, v0}; output << dt*(double)step << " "; for(int i=0; i<v.size(); i++) output << v[i] << " "; output << std::endl;

gnuplot (3/4)... double Output(double t, double v, bool display){...}; int main(int argc, const char * argv[]) { std::ofstream output("data.txt"); ofstream GnuplotInterface* gnuplot = new GnuplotInterface(); gnuplot->setaxislabel("x", t"); gnuplot->setaxislabel("y", "v"); double v0 = 0.0; double dt = 0.1; std::vector<double> v {v0, v0}; std::vector int stepend = 10; int step = 0; output << dt*(double)step << " "; for(int i=0; i<v.size(); i++) output << v[i] << " "; output << std::endl; while(step < stepend){ for(int i=0; i<v.size(); i++){ switch (i) { case 0: v[i] += (1.0 - v[i])*dt; break; case 1: v[i] = (v[i] + dt)/(1.0 + dt); break; default: break; } } step++; output << dt*(double)step << " "; for(int i=0; i<v.size(); i++) output << v[i] << " "; output << std::endl; } gnuplot->injection("set key left top\n"); gnuplot->injection("plot 'data.txt' using 1:2 title 'explicit', '' using 1:3 title 'implicit', 1-exp(-x)\n"); for(int i=0; i<v.size(); i++) std::cout << Output(dt*(double)step, v[i], false) << ", "; delete gnuplot; gnuplot return 0; } switch

x m d2 x dt 2 = kx F = kx (k > 0) x x

dx dt = v dv dt =!2 x! = r k m x, v

dx dt = v x n+1 t x n = v n x n+1 = x n + v n t dv dt =!2 x v n+1 t v n =! 2 x n v n+1 = v n! 2 x n t x v

x(0) = x 0 = 1 v(0) = v 0 = 0! = 1 x(t) = cos(!t) T/4 v(t) =! sin(!t) T T = 2 /! T/4 10 t = T 4 1 10

#include <iostream> #include <cmath> #include "GnuplotInterface.h" int main(int argc, const char * argv[]) { GnuplotInterface* gnuplot = new GnuplotInterface(); gnuplot->setaxislabel("x", "t"); gnuplot->setaxislabel("y", "x"); } double x0 = 1.0; double v0 = 0.0; double omega = 1.0; double omega2= omega*omega; double x = x0; double v = v0; double T = 2.0*M_PI/omega; double dt = (T/4.0)*0.1; x 0 v 0!! 2 T = 2 /! gnuplot->setgraphrange("x", 0.0, T); int stepend = (int)(t/dt) + 1; int step = 0; gnuplot->injection("set key left bottom\n"); gnuplot->injection("plot '-' title 'predicted x', cos(x), 0 \n"); gnuplot->injection(dt*(double)step, x); while(step < stepend){ double xtmp = x + v*dt; double vtmp = v - omega2*x*dt; x = xtmp; v = vtmp; step++; gnuplot->injection(dt*(double)step, x); } gnuplot->injection("e\n"); delete gnuplot; return 0; 02OscillatingBody t = T 4 1 10 x n+1 = x n + v n v n+1 = v n! 2 x n t t

(x) dt 1/10

(v)

Runge-Kutta Step 1 Step 2 dx dt = v x (1) t/2 x n = v n x n+1 t x n = v (1) dv dt =!2 x v (1) t/2 v n =! 2 x n v n+1 v n t =! 2 x (1) Runge-Kutta

Runge-Kutta

Runge-Kutta f (1) = f n + f (2) = f n + t 2 gn t 2 g(1) f (3) = f n + tg (2) f n+1 = f n + t 6 (gn + 2g (1) + 2g (2) + g (3) ) 20

dx dt = v x n+1 t x n = v n+1 dv dt =!2 x v n+1 t v n =! 2 x n+1

(x)