如何用单片机C语言进行三角函数运算?最好给出代码! 请问C语言中怎么计算三角函数?要全部的程序代码!谢谢!
\u5982\u4f55\u7528C\u8bed\u8a00\u5b9e\u73b0\u4e09\u89d2\u51fd\u6570\u7684\u8ba1\u7b97math.h\u91cc\u7684\u4e09\u89d2\u51fd\u6570\u7528\u7684\u5355\u4f4d\u662f\u5f27\u5ea6\uff0c\u4f60\u8c8c\u4f3c\u9519\u5728\u8fd9\u91cc\u3002 \u7b54\u6848\u8865\u5145 Example
/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/
#include
#include
void main( void )
{
double pi = 3.1415926535;
double x, y;
x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} \u7b54\u6848\u8865\u5145 Output
sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178
Parameter
x
Angle in radians
\u5e93\u51fd\u6570\u5c31\u6709\u554a\uff01
#include
#include
void main()
{
float a,Sin,Cos,Tan,Cot;
printf("\u8bf7\u8f93\u5165\u4f60\u8981\u6c42\u4e09\u89d2\u51fd\u6570\u7684\u53d8\u91cf");
scanf("%f" ,&a);
Sin=sin(a); //\u8c03\u7528\u5e93\u51fd\u6570\uff0c\u8c2d\u6d69\u5f3a\u4e66\u540e\u9762\u6709
Cos=sqrt(1-Sin*Sin);
tan=Sin/Cos;
cot=1/Tan;// \u5176\u4ed6\u7684\u53cd\u4e09\u89d2\u51fd\u6570\u4e5f\u662f\u8c03\u7528\u5e93\u51fd\u6570\u7684\u3002\u4f60\u81ea\u5df1\u641e\u5b9a\u5427\uff01
printf("%f,%f,%f,%f" ,Sin,Cos,Tan,Cot);
}
#include<math.h>中有。sin();cos();函数名给数学上的一样
/*--------------------------------------------------------------------------
MATH.H
Prototypes for mathematic functions.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __MATH_H__
#define __MATH_H__
#pragma SAVE
#pragma REGPARMS
extern char cabs (char val);
extern int abs (int val);
extern long labs (long val);
extern float fabs (float val);
extern float sqrt (float val);
extern float exp (float val);
extern float log (float val);
extern float log10 (float val);
extern float sin (float val);
extern float cos (float val);
extern float tan (float val);
extern float asin (float val);
extern float acos (float val);
extern float atan (float val);
extern float sinh (float val);
extern float cosh (float val);
extern float tanh (float val);
extern float atan2 (float y, float x);
extern float ceil (float val);
extern float floor (float val);
extern float modf (float val, float *n);
extern float fmod (float x, float y);
extern float pow (float x, float y);
#pragma RESTORE
#endif
使用数学头文件math.h,然后调用函数既要可以了。
绛旓細浣跨敤鏁板澶存枃浠秏ath.h锛岄噷闈㈡湁浣犻渶瑕佺殑涓夎鍑芥暟锛屼笉杩囪娉ㄦ剰浣跨敤鐨勮搴﹂兘鏄互寮у害涓哄崟浣嶇殑銆
绛旓細鍙互鐨勶紝鍦ㄧ紪璇戝櫒閲#include "math.h"鐒跺悗鐩存帴鐢ㄥ氨鍙互浜嗐
绛旓細int main(){float b, h, s;printf("璇疯緭鍏涓夎褰㈢殑 搴 楂榎n");scanf("%f %f", &b, &h);s=0.5*b*h;printf("涓夎褰㈢殑闈㈢Н涓猴細 %f\n", s);return 0;}
绛旓細杩欓噷娌℃湁鐜版垚鐨涓夎鍑芥暟锛屼綘浠诲姟瑕佹眰鐨勭簿搴︽槸澶氬皯锛熸妸鎵鏈夊彲鑳界殑胃鍊间唬鍏ワ紝鍦ㄧ數鑴戦噷绠楀嚭杩欎釜寮忓瓙鐨勬墍鏈夌粨鏋滐紝鐒跺悗鎶婄粨鏋滃仛鎴愭暟鎹〃锛屽湪绋嬪簭閲屽仛涓瓙绋嬪簭鏌ヨ〃灏卞彲浠ヤ簡锛岄熷害姣旂畻涓箻娉曢兘蹇
绛旓細杩欎釜澶存枃浠讹紝鏄暟瀛﹀嚱鏁伴泦鍚堬紝涓昏鏄涓夎鍑芥暟鍜屽鏁般佹寚鏁扮瓑鍑芥暟銆/*--- MATH.H Prototypes for mathematic functions.Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.All rights reserved.---*/ ifndef __MATH_H__define __MATH_H__pragma SAVE pragma REGPARMS extern cha...
绛旓細鍙兘鏄綘瀹氫箟鐨勬暟鎹被鍨嬩笉瀵癸紝浣犲鐓鍑芥暟鍘熷瀷鐪嬬湅銆傝繕鏈塻in锛坸锛夐噷闈㈢殑x鏄姬搴︿笉鏄搴︼紝鎵浠30搴﹀簲璇ユ崲绠楁垚寮у害=30*蟺/180
绛旓細KEIL C51 鏈変釜鏁板鍑芥暟搴擄紙鍜C璇█鐨 鏁板鍑芥暟搴撶被浼硷級鎸囨暟锛涓夎鍑芥暟锛屽钩鏂癸紝寮鏂癸紝绔嬫柟閮芥湁鐨勩傚叿浣撳彲浠ョ湅 鐩稿叧鐨勮祫鏂欍傛暟瀛﹀嚱鏁板簱 闇瑕佺湅澶存枃浠禡ATH.H 渚嬪锛1.鎸囨暟鍑芥暟 float exp(float x)2.瀵规暟鍑芥暟 float log(float x) 锛宖loat log10(float x)3.骞虫柟鏍癸細float sqrt(float x)3.涓夎鍑芥暟...
绛旓細鑳借绠楁诞鐐,涓嶈繃杩愮畻姣旇緝楹荤儲.涔熻兘璁$畻涓夎鍑芥暟,鍘熸潵鐢ㄨ繃涓涓猼an鍑芥暟鏄鐢╟杞繃鏉ョ殑涓涓煡琛.浠栫殑璁$畻鏂规硶涓昏鏄睍寮澶氶」寮忚绠.杩愮畻姣旇緝鑰楁椂.濡傛灉鏁版嵁瑕佹眰涓嶆槸寰堢簿纭殑璇,寤鸿杩樻槸鐢ㄦ煡琛ㄧ殑鏂规硶,鏁堢巼浼氭洿楂.
绛旓細杩欏彧璺熺紪璇戝櫒鏈夊叧绯汇傚畠鏄敮鎸佺殑锛屽彧鏄繍琛岃捣鏉ユ參浜嗐傚叾瀹炵敤娉板嫆绾ф暟灞曞紑锛屽彇鍓嶄袱椤瑰氨瀹屽叏澶熶簡銆
绛旓細濂借薄搴旇杩欐牱闂C璇█涓夎鍑芥暟绠楁硶绮惧害 鍗曠墖鏈杩愮畻鍜屽彴寮忔満杩愮畻绮惧害搴旇鏄浉鍛ㄧ殑锛屾暟鎹牸寮忎负DOUBLE,绮惧害寰堥珮锛屽彧涓嶈繃鍗曠墖鏈虹殑棰戠巼浣庯紝澶勭悊鍣ㄤ綅瀹藉皬锛屾墍浠ヨ繍绠楅熷害瑕佹參寰堝 鍏蜂綋鎬庝箞绠楃殑锛屽洜鏄疌璇█鐨勫簱鍑芥暟锛屾墍浠ユ病鏈変汉鍘诲叧蹇