ご覧いただきありがとうございます。
C
1#include <stdio.h> 2#include <math.h> 3 4 double f(double x); 5 double df(double x); 6 7 8int main(){ 9 double f(x); 10 double df(x); 11 double x; 12 int i; 13 14 x = 1.0; 15 for (i = 1; i <= 100;i++){ 16 x = x-f(x)/df(x); 17 if(fabs(f(x)) <= exp(-6)); 18 printf("x=%f.\n",x); 19 break; 20 }} 21 22 double f(double x){ 23 return x - cos(x); 24 } 25 26double df(double x){ 27 return 1.0 + sin(x); 28 } 29
cosx-x = 0 をニュートン法を用いて解くプログラムを作っています。
kadai11_1.c: In function ‘main’: kadai11_1.c:9:5: warning: parameter names (without types) in function declaration double f(x); ^~~~~~ kadai11_1.c:10:5: warning: parameter names (without types) in function declaration double df(x); ^~~~~~ /tmp/ccz1nyOW.o: In function `f': kadai11_1.c:(.text+0xbd): undefined reference to `cos' /tmp/ccz1nyOW.o: In function `df': kadai11_1.c:(.text+0xeb): undefined reference to `sin' collect2: error: ld returned 1 exit status
上のようなエラーが出てますがどのように直せばよいのかわからないです。
こちらの質問が複数のユーザーから「過去に投稿した質問と同じ内容の質問」という指摘を受けました。
https://teratail.com/questions/l758krnbl8vcea
重複質問のため低評価します。

回答4件
あなたの回答
tips
プレビュー