###前提・実現したいこと
様々な意見ありがとうございます。
よくわかっていない状態で質問してしまいました。
改めて質問させてください。
以下のプログラムは質点の軌道を示す方程式を使って離心率eを0にした時に円軌道を示すプログラムを作成したいと思っています。
先ほど上に記載してあるプログラムから変更し、for文で5度ずつ計算させてx,yの値を出力するようにプログラムしたつもりでしたが、結果は円軌道をしませんでした。
どこがいけないのかわからないので、教えていただきたいです。
###該当のソースコード
C
1#include <stdio.h> 2#include <stdlib.h> //rand() 3#include <math.h> //sin(), cos(), M_PI 4#include <time.h> //time() 5int main(void){ 6float e, a, l, r, x, y, theta; 7scanf(" %f %f", &e, &a); 8theta = rand() % 360; 9l = a*(1.0-pow(x,2.0)); 10r = l/(1.0 + e*cos(theta * M_PI / 180.0)); 11x = r* cos(theta*M_PI/180.0); 12y = r* sin(theta*M_PI/180.0); 13printf ("x=%.3f y=%.3f",x,y); 14} 15---------------------------------------------- 16#include <stdio.h> 17#include <math.h> //sin(), cos(), M_PI 18#include <time.h> //time() 19int main(void){ 20float e, a, l, r, x, y, theta; 21 22printf("e a");scanf(" %f %f", &e, &a); 23 24 25for(theta=0;theta<360;theta+=5.0){ 26 27l = a*(1.0-pow(x,2.0)); 28r = l/(1.0 + e*cos(theta * M_PI / 180.0)); 29x = r* cos(theta*M_PI/180.0); 30y = r* sin(theta*M_PI/180.0); 31printf ("%.3f %.3f\n",x,y); 32} 33return 0; 34} 35
回答3件
あなたの回答
tips
プレビュー