#define N1 N+1 double x[n1] =.5, 1., 2.; double hokan[n1] = 1.65, 2.72, 7.39 ; double xx[]=.2,.4,.6,.8,1.2,1.4,1.6,1.8; double lagrng(double xx); main

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

x(t) + t f(t, x) = x(t) + x (t) t x t Tayler x(t + t) = x(t) + x (t) t + 1 2! x (t) t ! x (t) t 3 + (15) Eular x t Teyler 1 Eular 2 Runge-Kutta

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±


C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

sim98-8.dvi

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

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

c-all.dvi

資料

関数のグラフを描こう

P02.ppt

1 4 2 EP) (EP) (EP)

C言語によるアルゴリズムとデータ構造

Microsoft Word - no14.docx

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

kiso2-09.key

XMPによる並列化実装2

Microsoft PowerPoint - 説明2_演算と型(C_guide2)【2015新教材対応確認済み】.pptx

‚æ2›ñ C„¾„ê‡Ìš|

2 P.S.P.T. P.S.P.T. wiki 26

PowerPoint Presentation

double int 1

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

Gauss

プログラミング基礎

‚æ4›ñ

P05.ppt

θ (t) ω cos θ(t) = ( : θ, θ. ( ) ( ) ( 5) l () θ (t) = ω sin θ(t). ω := g l.. () θ (t) θ (t)θ (t) + ω θ (t) sin θ(t) =. [ ] d dt θ (t) ω cos θ(t

P06.ppt

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

スライド 1

Taro-数値計算の基礎Ⅱ(公開版)

スライド 1

実際の株価データを用いたオプション料の計算

Taro-最大値探索法の開発(公開版

joho09.ppt

12 15 / sample program for a Information class DATE: heron s formula / #include <stdio.h> / for printf() / #include <math.h> / for sqrt() /

8 / 0 1 i++ i 1 i-- i C !!! C 2

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

printf("5つの整数を入力して下さい \n"); /* データ入力 */ for( /*** 02 ***/ ){ printf("%dつ目の入力 :",i+1); scanf("%d", /*** 03 ***/ ); sum=dat[0]; /* 合計値の初期設定 */ n_max= 0

スライド 1

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

新版明解C言語入門編

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){

ープのロープ長以下であれば実現可能である ケース 3: 3 本のロープの杭の位置を点 P 1 = (x 1, y 1, 0), 点 P 2 = (x 2, y 2, 0), 点 P 3 = (x 3, y 3, 0) とする 点 P 1 = (x 1, y 1, 0), 点 P 2 = (x 2,

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1

Taro-プログラミングの基礎Ⅱ(公

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

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

:30 12:00 I. I VI II. III. IV. a d V. VI

Microsoft Word - no15.docx

11042 計算機言語7回目 サポートページ:

joho12.ppt

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile "data.txt" #define OutFile "sorted.txt" #def

Microsoft PowerPoint - program.ppt [互換モード]

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile "data.txt" #define OutFile "surted.txt" #def

新・明解C言語で学ぶアルゴリズムとデータ構造

Numerical Rosetta Stone 1 C, Java, Perl, Ruby, Python [ ] Hello world C: /* hello.c $> gcc hello.c $>./a.out */ #include <stdio.h> main(){ printf("hel

スライド 1

スライド 1

第7章 有限要素法のプログラミング

Taro-再帰関数Ⅱ(公開版).jtd

tuat1.dvi

kiso2-06.key

フローチャートの書き方


演習課題No12

数値計算法

C 言語第 3 回 2 a と b? 関係演算子 a と b の関係 関係演算子 等しい a==b 等しくない a!=b より大きい a>b 以上 a>=b より小さい a<b 以下 a<=b 状態 真偽 値 条件が満たされた場合 TRUE( 真 ) 1(0 以外 ) 条件が満たされなかった場合 F

Taro-再帰関数Ⅲ(公開版).jtd

(x, y) 2. OK NG1 1

Microsoft PowerPoint - lec4.ppt

第 章 Q-1 3 int a =,b =,c = ; printf("%d\t%d\t%d",a,b,c); Q-2 3 int a = -; double b =.2; char c = 'G'; printf("%d\t%.2f\t%c",a,b,c); Q-3 3 int a = 0,b =

cp-7. 配列

A common.h include #include <stdio.h> #include <time.h> #define MAXN int A[MAXN], n; double start,end; void inputdata(

AHPを用いた大相撲の新しい番付編成

main


C言語による数値計算プログラミング演習

新版明解C言語 実践編

num2.dvi

Informatics 2010.key

:30 12:00 I. I VI II. III. IV. a d V. VI

#6 : ( 8-13) URL : j inoue/index.html : Neugart

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

Microsoft Word - 05

プログラミング基礎

Informatics 2014

num3.dvi

OHP.dvi

Microsoft Word - no15.docx

char int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]


p = 1, 2, cos 2n + p)πj = cos 2nπj 2n + p)πj, sin = sin 2nπj 7.1) f j = a ) 0 + a p + a n+p cos 2nπj p=1 p=0 1 + ) b n+p p=0 sin 2nπj 1 2 a 0 +

[ ] π = C: /* pi.c $> gcc pi.c -lm $>./a.out */ #include <stdio.h> #include <math.h> main(){ double pi=4*atan(1); printf("%lf\n", pi); # pi=m

Transcription:

=1= (.5, 1.65), (1., 2.72), (2., 7.39).2,.4,.6,.8, 1., 1.2, 1.4, 1.6 1 1: x.2 1.4128.4 1.5372.6 1.796533.8 2.198 1.2 3.384133 1.4 4.1832 1.6 5.1172 8 7 6 5 y 4 3 2 1.5 1 1.5 2 x 1: /* */ #include <stdio.h> #include <math.h> #define N 2 1

#define N1 N+1 double x[n1] =.5, 1., 2.; double hokan[n1] = 1.65, 2.72, 7.39 ; double xx[]=.2,.4,.6,.8,1.2,1.4,1.6,1.8; double lagrng(double xx); main(void) int z; for(z=;z<=6;z++) printf("%lf %lf\n",xx[z],lagrng(xx[z])); double lagrng(double xx) double p=.,pn,pd; int i,j; for(i=; i<n1; i++) pn=1.; pd=1.; for(j=; j<n1; j++) if( j!=i) pn=pn*(xx-x[j]); pd = pd*(x[i]-x[j]); p=p+pn*hokan[i]/pd; return(p); 2

=2= f(x) =2x 2 1 ±1/ 2=.771... 1.4 5.771 /* */ #include <stdio.h> #include <math.h> #define EPSILON.1E-5 double function(double *f,double *df,double x); double newton(double *x1,int *no,int max); main(void) int num=,max=; double x1; printf("\n \n"); scanf("%lf",&x1); printf(" = "); scanf("%d",&max); newton(&x1,&num,max); printf("\n : %d",num); printf("\n : x= %9.5lf\n",x1); return(); double newton(double *x1,int *no,int max) double f,df,x; do if(*no>=max) break; x=*x1; function(&f,&df,x); *x1=x-f/df; (*no)++; while(fabs(x-*x1)>epsilon); double function(double *f,double *df,double x) *f=2.*x*x-1.; *df=4.*x; 3

=3= f(x) =x 3 +2x 2 +3x +4 x 3 2 2: 1 2 3 4 5 1 1 64.425 63.823125 63.7825 63.768281 63.7617 63.752925 63.7529 63.75 /* */ #include <stdio.h> #include <math.h> #define TRUE 1 #define FALSE 2 main(void) double function(double x); double daikei(double a,double b,int n); double a=.; double b=3.; int n[]=1,2,3,4,5,1,1; int z; /* printf(" \n"); scanf("%lf %lf",&a,&b); printf(" \n"); scanf("%d",&n); */ for(z=;z<=6;z++) printf("%d %f\n",n[z],daikei(a,b,n[z])); double function(double x) double w; w=x*x*x +2.*x*x +3.*x +4.; return(w); 4

double daikei(double a,double b,int n) int j; double h,s; h=(b-a)/n; s=function(a); for(j=1; j<=n-1; j++) s=s+2.*function(a+j*h); s=s+function(b); return(s*h/2.); 5

=4= y = x + y x =,y = x =2 3 3: x Y(euler) Y(heun) Y(runge) Y( )......4..8.784.918.8.16.394.392.4255 1.2.544 1.418 1.566 1.121 1.6 1.2416 2.1979 2.2447 2.353 2. 2.3782 4.18 4.2136 4.3891 5 4 euler heun runge real 3 y 2 1.5 1 1.5 2 x 2: x 5 6

5 4 euler heun runge 3 y 2 1.5 1 1.5 2 x 3: x 5 /* */ #include <stdio.h> #include <math.h> double function(double x,double y); double euler(double h,int n,double x,double y1[]); double heuns(double h,int n,double x,double y2[]); double runge(double h,int n,double x,double y3[]); int main(void) int n,i; double x,yo; double y1[55],y2[55],y3[55]; double h,xn; printf("\n x x="); scanf("%lf",&x); printf("y x="); scanf("%lf",&yo); printf("\n x xn="); scanf("%lf",&xn); printf("\n n="); scanf("%d",&n); h=(xn-x)/n; y1[]=y2[]=y3[]=yo; 7

euler(h,n,x,y1); heuns(h,n,x,y2); runge(h,n,x,y3); printf("\n -E- -H- -R-\n"); for(i=;i<=n;i++) printf("x=%6.3lf %8.4lf",x+h*i,y1[i]); printf(" %8.4lf %8.4lf\n",y2[i],y3[i]); return(); double function(double x,double y) return(x+y); double euler(double h,int n,double x,double y1[]) int i; for(i=; i<=n; i++) y1[i+1]=y1[i]+h*function(x+h*i,y1[i]); double heuns(double h,int n,double x,double y2[]) int i; double k1,k2; for(i=; i<=n; i++) k1=h*function(x+h*i,y2[i]); k2=h*function(x+h*(i+1),y2[i]+k1); y2[i+1]=y2[i]+(k1+k2)/2.; double runge(double h,int n,double x,double y3[]) int i; double xi,k1,k2,k3,k4; 8

for(i=; i<=n; i++) xi=x+h*i; k1=h*function(xi,y3[i]); k2=h*function(xi+h/2.,y3[i]+k1/2.); k3=h*function(xi+h/2.,y3[i]+k2/2.); k4=h*function(xi+h/2.,y3[i]+k3); y3[i+1]=y3[i]+(k1+2.*k2+2.*k3+k4)/6.; 9

=5= - x = x( 2+y) y = y(3 4x) (x =4,y =2) t : 2 4 12 1 x y 8 y 6 4 2 5 1 15 2 x 4: /* */ #include<stdio.h> #include<math.h> double function1(double x1,double y1); double function2(double x2,double y2); double rotoka(double h,int n,double t,double x4[],double y4[]); int main(void) int i,n; double x,yo,to; double x4[11],y4[11]; double h,tn; 1

printf("\n x "); scanf("%lf",&x); printf("\n y "); scanf("%lf",&yo); printf("\n t "); scanf("%lf",&to); printf("\n t "); scanf("%lf",&tn); printf("\n "); scanf("%d",&n); h=(tn-to)/n; x4[]=x; y4[]=yo; rotoka(h,n,to,x4,y4); printf("\n t x y\n"); for(i=;i<=n; i++) printf("%6.3lf %8.4lf %8.4lf\n",to+h*i,x4[i],y4[i]); return(); double function1(double x1,double y1) return(x1*(-.2+.1*y1)); double function2(double x2,double y2) return(y2*(.3-.4*x2)); double rotoka(double h,int n,double to,double x4[],double y4[]) int i; double ti,k1,k2,k3,k4,m1,m2,m3,m4; for(i=; i<=n; i++) ti=to+h*i; k1=h*function1(x4[i],y4[i]); m1=h*function2(x4[i],y4[i]); k2=h*function1(x4[i]+k1/2,y4[i]+m1/2); m2=h*function2(x4[i]+k1/2,y4[i]+m1/2); k3=h*function1(x4[i]+k2/2,y4[i]+m2/2); 11

m3=h*function2(x4[i]+k2/2,y4[i]+m2/2); k4=h*function1(x4[i]+k3,y4[i]+m3); m4=h*function2(x4[i]+k3,y4[i]+m3); y4[i+1]=y4[i]+(m1+m2+m3+m4)/6.; x4[i+1]=x4[i]+(k1+k2+k3+k4)/6.; 12

=6= u t = c2 2 u x 2 (c 2 =1/12) u(x, ) = x(1 x), ( x 1), u(,t)=,u(1,t)= 5 4: t x..25.5.75 1....1875.25.1875..375..125.1875.125..75..9375.125.9375. 1.125..625..9375.625. 1.5..46875.625.46875. 1.875..3125.46875.3125. u.3.25.2.15.1.5 1.8.5 t 1 1.5 2.2.4.6 x 5: /* */ #include <stdio.h> #include <math.h> #define NMAX 11 #define NNMAX 21 13

#define TRUE 1 #define FALSE double intcon(double h,int n); double solute(int n,double fa,double fb,int nn,double lamda); double f[nmax],u[nmax][nnmax]; main() int n,nn,i,j; double c2=1./12.; double a,b,fa,fb,h,lamda,k; printf("\n\n x \n"); scanf("%lf %lf",&a,&b); printf(" \n"); scanf("%lf %lf",&fa,&fb); printf("x (<%2d)\n",NMAX-1); scanf("%d",&n); printf("t (<%2d)\n",NNMAX-1); scanf("%d",&nn); printf(" \n"); scanf("%lf",&lamda); h=(b-a)/n; k=lamda*h*h/c2; intcon(h,n); solute(n,fa,fb,nn,lamda); for(j=; j<=nn; j++) printf("%8.4f : ",j*k); for(i=; i<=n; i++) printf("%1.6f",u[i][j]); printf("\n"); double intcon(double h,int n) int i; for(i=; i<=n; i++) f[i]=i*h*(1.-i*h); 14

double solute(int n,double fa,double fb,int nn,double lamda) int i,j; for(i=; i<=n; i++) u[i][]=f[i]; for(j=; j<nn; j++) u[][j+1]=fa; u[n][j+1]=fb; for(i=1; i<n; i++) u[i][j+1]=lamda*u[i-1][j]+(1.-2.*lamda)*u[i][j]+lamda*u[i+1][j]; 15

=7= ( u = ( ) = 2 x 2 + 2 y 2 (x, y); x 1, y 1 y = x 2 y =1 x = =1 6 5: x y..2.4.6.8 1....4.16.36.64 1..2..7611.24239.4145.688324 1..4..92276.242472.45716.719286 1..6..12497.292183.5544.7481 1..8..163348.348676.555357.775842 1. 1...2.4.6.8 1. u 1.8.6.4.2.2.4 x.6.8 1.2.4.6.8 y 1 6: /* */ #include <stdio.h> #include <math.h> #define NMAX 11 16

#define NNMAX 21 #define EPS.5 #define TRUE 1 #define FALSE double intcon(int nx, double h,double k); double solute(int nx,int ny, double aa,double bb,double h,double k); double f1[nmax],f2[nmax],u[nmax][nnmax]; main() int nx,ny,i,j; double aa,bb,h,k; printf("\n\n, \n"); scanf("%lf %lf",&aa,&bb); printf("x,y \n"); scanf("%d %d",&nx,&ny); h=1./nx; k=1./ny; intcon(nx,h,k); solute(nx,ny,aa,bb,h,k); for(j=; j<=ny; j++) printf("%8.4f : ",j*k); for(i=; i<=nx; i++) printf("%1.6f",u[i][j]);printf(" "); printf("\n"); double intcon(int nx,double h,double k) int i; double x1,x2; for(i=; i<=nx; i++) x1=i*h; x2=i*k; f1[i]=x1*x1; f2[i]=x2; double solute(int nx,int ny, double aa,double bb,double h,double k) 17

int i,j; double ubefore,uafter,uzettaiue,uzettaiue2,uzettaisita,utotal; uzettaisita=.; uzettaiue2=.; utotal=1.; for(i=;i<=nx; i++) for(j=;j<=ny; j++) u[i][j]=.; while(utotal>eps) for(i=; i<=nx; i++) u[i][]=f1[i]; u[i][ny]=f2[i]; for(j=1; j<ny; j++) u[][j]=aa; u[nx][j]=bb; for(i=1; i<nx; i++) ubefore=u[i][j]; u[i][j]=1./(2.*(h*h+k*k))*(k*k*(u[i+1][j]+u[i-1][j])+h*h*(u[i][j+1]+u[i][j-1])); uafter=u[i][j]; uzettaisita=uzettaisita+uafter; if(ubefore<=uafter) uzettaiue=uafter-ubefore; else uzettaiue=(uafter-ubefore)*(-1.); uzettaiue2=uzettaiue2+uzettaiue; utotal=uzettaiue/uzettaisita; printf("%1.6f", utotal); 18