|
これ実行すると画面全体がぐちゃぐちゃになっちゃうんですけど、
何ででしょうか。変数の桁あふれですか?
#include<stdio.h>
#include<math.h>
#include<glibw32.h>
double f1 (double);
int main(void){
double x,p,q,y1,y2,a;
double h=0.001;
ginit(); //グラフィック開始
printf("接線を描きます。");
GRAPH g;
g.window(-16,-10,16,10);
for(x=-16;x <= 16;x = x+0.01){
cls();
g.line(-16,0,16,0);
g.line(0,10,0,-10);
for(p=-16;p <= 16;p = p+0.01){
q = f1(p);
g.pset(p,q,RED);
}
y1 = f1(x);
y2 = f1(x+h);
a=(y2-y1)/h;
g.line(x+10,y1+10*a,x-10,y1-10*a,GREEN);
}
gend(); //グラフィック終わり
return 0;
}
double f1 (double x)
{
double y=pow(x,2);
return y;
}
|