最終更新:ID:yyCkkWjRdQ 2017年09月01日(金) 22:16:36履歴
#include <stdio.h> #include <math.h> #define A -0.966918 #define B 2.879879 #define C 0.765145 #define D 0.744728 #define X_ONE 0.1 /* x(1) の値 */ #define Y_ONE 0.1 /* y(1) の値 */ #define LINE "-------------------------" int main(void){ func( 1, 1 ); puts( LINE ); func( 2, 2 ); puts( LINE ); func( 1, 5 ); puts( LINE ); func( 5, 10 ); return 0; } /* 数列の第 s 項から第 t 項までを出力する. */ /* 1 ≦ s ≦ t. */ void func( int s, int t ){ int i; double x = X_ONE, y = Y_ONE, next_x, next_y; /* 第 1 項から第 s-1 項までは出力せずに, 計算するだけ. */ for( i = 1; i < s; i++ ){ next_x = sin( B * y ) + C * sin( B * x ); next_y = sin( A * x ) + D * sin( A * y ); x = next_x; y = next_y; } /* 第 s 項から第 t 項までは, 出力してから次項の計算をする. */ for( i = s; i <= t; i++ ){ printf( "%d,%f,%f\n", i, x, y ); next_x = sin( B * y ) + C * sin( B * x ); next_y = sin( A * x ) + D * sin( A * y ); x = next_x; y = next_y; } }
1,0.100000,0.100000 ------------------------- 2,0.501343,-0.168438 ------------------------- 1,0.100000,0.100000 2,0.501343,-0.168438 3,0.292703,-0.345238 4,-0.267083,-0.035245 5,-0.633515,0.280762 ------------------------- 5,-0.633515,0.280762 6,-0.017369,0.375262 7,0.844034,-0.247538 8,-0.154760,-0.551935 9,-1.329664,0.527927 10,1.484401,0.595769
コメントをかく