日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言 单词变复数_一些复数运算的C语言实现

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言 单词变复数_一些复数运算的C语言实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 /*file ComplexCalculation.c2 *author Vincent Cui3 *e-mail whcui1987@163.com4 *version 0.15 *data 20-Oct-20146 *brief 用于復數運算的一些函數7 */

8

9

10 #include "ComplexCalculation.h"

11 #include "math.h"

12 #include "stdio.h"

13

14

15 /*函數名:complexAdd16 *說明:復數加法17 *輸入:a,b兩個復數18 *輸出:19 *返回:a + b20 *調用:21 *其它:22 */

23 complexType complexAdd(complexType a, complexType b)24 {25 complexType result;26

27 result.Real = a.Real +b.Real;28 result.Imag = a.Imag +b.Imag;29

30 returnresult;31 }32

33 /*函數名:complexSubtract34 *說明:復數減法35 *輸入:minuend被減數,subtrahend減數36 *輸出:37 *返回:a - b38 *調用:39 *其它:40 */

41 complexType complexSubtract(complexType minuend, complexType subtrahend)42 {43 complexType result;44

45 result.Real = minuend.Real -subtrahend.Real;46 result.Imag = minuend.Imag -subtrahend.Imag;47

48 returnresult;49 }50

51 /*函數名:complexMultiply52 *說明:復數乘法53 *輸入:a,b兩個復數54 *輸出:55 *返回:a * b56 *調用:57 *其它:58 */

59 complexType complexMultiply(complexType a, complexType b)60 {61 complexType result;62

63 result.Real = a.Real * b.Real - a.Imag *b.Imag;64 result.Imag = a.Imag * b.Real + a.Real *b.Imag;65

66 returnresult;67 }68

69

70 /*函數名:complexDivision71 *說明:復數除法72 *輸入:dividend被除數,divisor除數73 *輸出:74 *返回:a / b75 *調用:76 *其它:divisor的實部和虛部不能同時為077 */

78 complexType complexDivision(complexType dividend, complexType divisor)79 {80 complexType result;81

82 /*斷言,被除數的實部和虛部不能同時為零*/

83 assert_param(IS_COMPLEX_DIVISOR_CORRENT(divisor.Real, divisor.Imag));84

85 result.Real = (mathDouble)(dividend.Real * divisor.Real + dividend.Imag * divisor.Imag) /\86 (divisor.Real * divisor.Real + divisor.Imag *divisor.Imag);87 result.Imag = (mathDouble)(dividend.Imag * divisor.Real - dividend.Real * divisor.Imag) /\88 (divisor.Real * divisor.Real + divisor.Imag *divisor.Imag);89 returnresult;90 }91

92 /*函數名:complexAbs93 *說明:復數取模94 *輸入:a復數95 *輸出:96 *返回:復數的模97 *調用:98 *其它:99 */

100 mathDouble complexAbs(complexType a)101 {102 return (sqrt( pow(a.Real,2) + pow(a.Imag,2) ));103 }104

105

106 /*函數名:complexAngle107 *說明:復數取相角108 *輸入:a復數109 *輸出:110 *返回:復數的相角111 *調用:112 *其它:113 */

114 mathDouble complexAngle(complexType a)115 {116 /*是atan2而非atan,(-PI,PI]*/

117 return(atan2(a.Imag, a.Real));118 }119

120 /*函數名:complexByAbsAngle121 *說明:通過模和相角合成復數122 *輸入:r 模, theta 相角123 *輸出:124 *返回:復數125 *調用:126 *其它:127 */

128 complexType complexByAbsAngle(mathDouble r, mathDouble theta)129 {130 complexType tmp_1,tmp_2;131

132 tmp_1.Real = 0;133 tmp_1.Imag =theta;134 tmp_2 =complexExp(tmp_1);135 tmp_2.Real *=r;136 tmp_2.Imag *=r;137

138 returntmp_2;139 }140

141 /*函數名:complexExp142 *說明:復指數運算143 *輸入:a 復指數144 *輸出:145 *返回:e的a次方146 *調用:147 *其它:使用歐拉公式 e^(jw) = cos(w) + j * sin(w)148 */

149 complexType complexExp(complexType a)150 {151 complexType result;152

153 result.Real = exp(a.Real) *cos(a.Imag);154 result.Imag = exp(a.Real) *sin(a.Imag);155

156 returnresult;157 }158

159

160 #if ASSERT_ENABLE

161 /*函數名:assert_failed162 *說明:斷言函數163 *輸入:164 *輸出:打印出錯的位置165 *返回:166 *調用:167 *其它:168 */

169 void assert_failed(mathUint_8*file, mathUint_32 line)170 {171 printf("Assert Error in File: %s \r\nLine: %d \r\n",file,line);172 }173

174 #endif

總結

以上是生活随笔為你收集整理的c语言 单词变复数_一些复数运算的C语言实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。