Board logo

标题: [其他] 复变函数表达式计算器zi [打印本页]

作者: slimay    时间: 2021-5-12 17:35     标题: 复变函数表达式计算器zi

本帖最后由 slimay 于 2021-5-12 20:35 编辑
复变函数表达式计算器,支持多重复变函数混合嵌套计算。是实数表达式计算器的升级版, 打通了冥数的计算,所有函数均推广至复域.
第三方进化路线,后者均是前者在多维空间, 多维数域,多维度矩阵 上 的升级.后者在输入降维数据后运行的结果与前者一致.保证了多维度向下兼容性.
REVPOLISH -> ZI  //多维表达式计算
FPLOT -> FP3       //多维绘图
I -> MAT               //多维综合工具
示例:
> zi sin(5+7i)*cos(6-3i)+sin(5+7i)*i
/***
  = -28817/6 + 4899/2(i)   //渐进分数表示
  = -4802.848508148568 + 2449.503431876684(i)   //浮点表示
  =  5391.421042267110 * exp[(i)2.669968709666] //极坐标表示
***/
支持实数同名的复变函数:
  +, -, *, /, , ^, pi=3.1415926536, e=2.71828182846
  rand, round, int, ceil, floor, sqrt, lg, ln, exp, abs, arg
  torad, sin, cos, tan, arcsin, arccos, arctan
  sinh, cosh, tanh, arcsinh, arccosh, arctanh


存为a.txt,  解码base92格式  : bse -d92 a.txt a.zip
  1. >7Ct'f!!!!'[!.:F?//?_!cs'[!_!2!!%r!!!_4QyyjApeJMHLV;<D\m4<-HI#>,g_Ago)/+%\<Q9*+8X_$-M/LHFZjY>x:vV)iq7kC!3@Gy@9di+*nkz,yi:QM7Sv)9//vN==A0.HM.EN>^)'dbt|lc!:JPxYr@)ycONmF)YK:tu*jpZ<@mL9@8?\QG$0YK)5[$O\_@xdMilvKj{6|S8GxI/Vb;Eh()J{eXX*V*,P<k13GQ%wxS0|{OWXYM#K2%S1m=ZeKy+eMP6Qdy03xyqHUipf]sLj57W:fG$Izl5E&Dc?$GCi^*[5O8@>qHbOv:$.;<+d|U.FV(nR#Xo?&LAYLE,e=J.F928WnJZP3hGDee]-8RIJQ}N8;,<wN]p,!,8h789RGLajgJTN>xt>OluV,^2jHB|u4I&r]41^V8?9Lk=#0-FU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

实现的复变函数库, 可推广至四元数域
  1. /*
  2. COMPLEX MATHLIB &COPYRIGHT@2021~2023 BY SLIMAY
  3. 复变函数库
  4. */
  5. #include <math.h>
  6. //定义复数类型
  7. typedef double Complex;
  8. #define _REZ 0
  9. #define _IMZ 1
  10. #define MATH_PI 3.1415926535897932
  11. #define MATH_E  2.7182818284590452
  12. ////////////////////////////////// 定义复恒量
  13. static const Complex Z_0 [2] = {0,       0};
  14. static const Complex Z_1 [2] = {1,       0};
  15. static const Complex Z_i [2] = {0,       1};
  16. static const Complex Z__i[2] = {0,      -1};
  17. static const Complex Z_pi[2] = {0, MATH_PI};
  18. static const Complex Z_e [2] = {0, MATH_E };
  19. ////////////////////////////////// 定义复数 模 加、减、乘、除
  20. //实例化一个复数
  21. Complex* Z_init(double x, double y)
  22. {
  23. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  24. *(Z_RET + _REZ) = x;
  25. *(Z_RET + _IMZ) = y;
  26. return Z_RET;
  27. }
  28. //复数的模长, (一维函数)
  29. Complex* Z_abs(Complex* x)
  30. {
  31. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  32. Complex* Z_RET = Z_init(r, 0);
  33. return Z_RET;
  34. }
  35. //角度转弧度, (一维函数,只对实部运算, 虚部归零)
  36. Complex* Z_torad(Complex* x)
  37. {
  38. Complex* Z_RET = Z_init((*(x+_REZ)) / 180.0 * MATH_PI, 0);
  39. return Z_RET;
  40. }
  41. //复数的辐角 (一维函数, 只返回0到2*PI范围内的辐角弧度, 虚部归零)
  42. Complex* Z_arg(Complex* x)
  43. {
  44. double arg = 0;
  45. if((*(x+_REZ)) == 0)
  46. {
  47. if((*(x+_IMZ)) != 0)
  48. {
  49. arg = ((*(x+_IMZ)) > 0) ?(MATH_PI/2.0) :(-MATH_PI/2.0);
  50. }
  51. }
  52. else
  53. {
  54. arg = atan( (*(x+_IMZ)) / (*(x+_REZ)) );
  55. if((*(x+_REZ)) < 0)
  56. {
  57. arg += ((*(x+_IMZ)) > 0) ?(MATH_PI) :(-MATH_PI);
  58. }
  59. }
  60. Complex* Z_RET = Z_init(arg, 0);
  61. return Z_RET;
  62. }
  63. //随机一个复数, 辐角不超过 x的辐角,模长为x的模长.
  64. Complex* Z_rand(Complex* x)
  65. {
  66. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  67. double s = (r < 2) ?(rand() % 8192/8192.0) :(rand() % ((int)r));
  68. Complex* Z_RET = Z_init(s, 0);
  69. return Z_RET;
  70. }
  71. //复数加
  72. Complex* Z_add(Complex* x, Complex* y)
  73. {
  74. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  75. *(Z_RET + _REZ) = (*(x+_REZ)) + (*(y+_REZ));
  76. *(Z_RET + _IMZ) = (*(x+_IMZ)) + (*(y+_IMZ));
  77. return Z_RET;
  78. }
  79. //复数减
  80. Complex* Z_sub(Complex* x, Complex* y)
  81. {
  82. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  83. *(Z_RET + _REZ) = (*(x+_REZ)) - (*(y+_REZ));
  84. *(Z_RET + _IMZ) = (*(x+_IMZ)) - (*(y+_IMZ));
  85. return Z_RET;
  86. }
  87. //复数乘
  88. Complex* Z_mul(Complex* x, Complex* y)
  89. {
  90. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  91. *(Z_RET + _REZ) = (*(x+_REZ))*(*(y+_REZ)) - (*(x+_IMZ))*(*(y+_IMZ));
  92. *(Z_RET + _IMZ) = (*(x+_REZ))*(*(y+_IMZ)) + (*(x+_IMZ))*(*(y+_REZ));
  93. return Z_RET;
  94. }
  95. //复数除
  96. Complex* Z_div(Complex* x, Complex* y)
  97. {
  98. double r2 = (*(y+_REZ))*(*(y+_REZ)) + (*(y+_IMZ))*(*(y+_IMZ));
  99. if(r2 == 0)
  100. {
  101. printf("Cannot div 0.\n");
  102. exit(1);
  103. }
  104. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  105. *(Z_RET + _REZ) = ((*(x+_REZ))*(*(y+_REZ)) + (*(x+_IMZ))*(*(y+_IMZ))) / r2;
  106. *(Z_RET + _IMZ) = ((*(x+_IMZ))*(*(y+_REZ)) - (*(x+_REZ))*(*(y+_IMZ))) / r2;
  107. return Z_RET;
  108. }
  109. //复取余
  110. Complex* Z_rest(Complex* x, Complex* y)
  111. {
  112. if((*(y+_REZ)) == 0)
  113. {
  114. printf("Can't % 0.\n");
  115. exit(1);
  116. }
  117. Complex* Z_RET  = Z_init((double)(((int)(*(x+_REZ))) % ((int)(*(y+_REZ)))), 0);
  118. return Z_RET;
  119. }
  120. ////////////////////////////////// 定义复变函数 (即实变函数在复域上的推广)
  121. //EXP函数
  122. Complex* Z_exp(Complex* x)
  123. {
  124. Complex* Z_RET  = (Complex*) malloc (2 * sizeof(double));
  125. *(Z_RET + _REZ) = exp(*(x+_REZ)) * cos(*(x+_IMZ));
  126. *(Z_RET + _IMZ) = exp(*(x+_REZ)) * sin(*(x+_IMZ));
  127. return Z_RET;
  128. }
  129. //自然对数 (旧版),0无辐角
  130. Complex* Z_log2(Complex* x)
  131. {                    
  132. if( (*(x+_REZ)) == 0 )
  133. {
  134. printf("Can't ln(0+bi).\n");
  135. exit(1);
  136. }
  137. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));                  
  138. Complex* Z_RET = Z_init(log(r), atan((*(x+_IMZ))/(*(x+_REZ))));
  139. return Z_RET;
  140. }
  141. //自然对数
  142. Complex* Z_ln(Complex* x)
  143. {
  144. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  145. if(r ==0)
  146. {
  147. printf("Can't ln(0).\n");
  148. exit(1);
  149. }
  150. double arg = (*(Z_arg(x)+_REZ));                 
  151. Complex* Z_RET = Z_init(log(r), arg);
  152. return Z_RET;
  153. }
  154. //常用对数
  155. Complex* Z_log10(Complex* x)
  156. {
  157. Complex* lnx = Z_ln(x);                  
  158. Complex* Z_RET = Z_init((*(lnx+_REZ))/log(10), (*(lnx+_IMZ))/log(10));
  159. return Z_RET;
  160. }
  161. //次方函数
  162. Complex* Z_pow(Complex* x, Complex* y)
  163. {
  164. Complex* lnx = Z_ln(x);
  165. Complex* Z_RET = Z_exp(Z_mul(y, lnx));
  166. return Z_RET;
  167. }
  168. //开方函数
  169. Complex* Z_sqrt(Complex* x)
  170. {                     
  171. Complex* Z_RET = Z_pow(x, Z_init(0.5, 0));
  172. return Z_RET;
  173. }
  174. //四舍五入
  175. Complex* Z_round(Complex* x)
  176. {
  177. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  178. Complex* Z_RET = Z_init((*(x+_REZ))/r * (double)((int)r),  (*(x+_IMZ))/r * (double)((int)r));
  179. return Z_RET;
  180. }
  181. //向下取整
  182. Complex* Z_floor(Complex* x)
  183. {
  184. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  185. Complex* Z_RET = Z_init((*(x+_REZ))/r * (double)(floor(r)),  (*(x+_IMZ))/r * (double)((int)r));
  186. return Z_RET;
  187. }
  188. //向上取整
  189. Complex* Z_ceil(Complex* x)
  190. {
  191. double r = sqrt((*(x+_REZ))*(*(x+_REZ))+(*(x+_IMZ))*(*(x+_IMZ)));
  192. Complex* Z_RET = Z_init((*(x+_REZ))/r * (double)(ceil(r)),  (*(x+_IMZ))/r * (double)((int)r));
  193. return Z_RET;
  194. }
  195. ////////////////////////////////// 定义复变三角函数
  196. //正弦函数
  197. Complex* Z_sin(Complex* x)
  198. {
  199. Complex*  ix = Z_mul( Z_i, x);
  200. Complex* _ix = Z_mul(Z__i, x);
  201. Complex* Z_RET = Z_mul(Z_init(0, -0.5), Z_sub(Z_exp(ix),Z_exp(_ix)));
  202. return Z_RET;
  203. }
  204. //余弦函数
  205. Complex* Z_cos(Complex* x)
  206. {   
  207. Complex*  ix = Z_mul( Z_i, x);
  208. Complex* _ix = Z_mul(Z__i, x);
  209. Complex* Z_RET = Z_mul(Z_init(0.5, 0), Z_add(Z_exp(ix),Z_exp(_ix)));
  210. return Z_RET;
  211. }
  212. //正切函数
  213. Complex* Z_tan(Complex* x)
  214. {                     
  215. Complex* Z_RET = Z_div(Z_sin(x), Z_cos(x));
  216. return Z_RET;
  217. }
  218. //反正弦函数
  219. Complex* Z_asin(Complex* x)
  220. {
  221. Complex*  sqrt1subz2 = Z_sqrt(Z_sub(Z_1, Z_mul(x, x)));
  222. Complex* Z_RET = Z_mul(Z_i, Z_ln(Z_sub(Z_mul(Z_i, x), sqrt1subz2)));
  223. return Z_RET;
  224. }
  225. //反余弦函数
  226. Complex* Z_acos(Complex* x)
  227. {                    
  228. Complex*  sqrt1subz2 = Z_sqrt(Z_sub(Z_1, Z_mul(x, x)));
  229. Complex* Z_RET = Z_mul(Z__i, Z_ln(Z_sub(x, Z_mul(Z_i, sqrt1subz2))));
  230. }
  231. //反正切函数
  232. Complex* Z_atan(Complex* x)
  233. {      
  234. Complex*  s = Z_init(0,-0.5);                              
  235. Complex* Z_RET = Z_mul(s, Z_ln(Z_div(Z_sub(Z_i, x), Z_add(Z_i, x))));
  236. return Z_RET;
  237. }
  238. ////////////////////////////////// 定义复变双曲函数
  239. //双曲正弦函数
  240. Complex* Z_sinh(Complex* x)
  241. {
  242. Complex* _x = Z_init(-(*(x+_REZ)), -(*(x+_IMZ)));
  243. Complex* Z_RET = Z_mul(Z_init(0.5, 0), Z_sub(Z_exp(x), Z_exp(_x)));
  244. return Z_RET;
  245. }
  246. //双曲余弦函数
  247. Complex* Z_cosh(Complex* x)
  248. {                    
  249. Complex* _x = Z_init(-(*(x+_REZ)), -(*(x+_IMZ)));
  250. Complex* Z_RET = Z_mul(Z_init(0.5, 0), Z_add(Z_exp(x), Z_exp(_x)));
  251. return Z_RET;
  252. }
  253. //双曲正切函数
  254. Complex* Z_tanh(Complex* x)
  255. {                     
  256. Complex* Z_RET = Z_div(Z_sinh(x), Z_cosh(x));
  257. return Z_RET;
  258. }
  259. //反双曲正弦函数
  260. Complex* Z_asinh(Complex* x)
  261. {
  262. Complex*  sqrtz2add1 = Z_sqrt(Z_add(Z_init(1,0), Z_mul(x, x)));
  263. Complex* Z_RET = Z_ln(Z_sub(x, sqrtz2add1));
  264. return Z_RET;
  265. }
  266. //反双曲余弦函数
  267. Complex* Z_acosh(Complex* x)
  268. {
  269. Complex*  sqrtz2sub1 = Z_sqrt(Z_sub(Z_init(1,0), Z_mul(x, x)));
  270. Complex* Z_RET = Z_ln(Z_sub(x, sqrtz2sub1));
  271. return Z_RET;
  272. }
  273. //反双曲正切函数
  274. Complex* Z_atanh(Complex* x)
  275. {
  276. Complex*  s1 = Z_init(1, 0);
  277. Complex*  halfs1 = Z_init(0.5, 0);              
  278. Complex* Z_RET = Z_mul(halfs1, Z_ln(Z_div(Z_add(s1, x), Z_sub(s1, x))));
  279. return Z_RET;
  280. }
复制代码
新第三方预告,升级版的mat加入了矩阵表达式计算器,类似matlab
mat
格式:
mat "[expression1] [expression2] [expression3] [.] ..."

示例:
mat "[A=1,0;1,1]  [B=A^(2)]  [C=A^(-1)+B]  [(A^(-1))-C]  [det(A)]  [tr(A)]  [A^(50)]"

输入格式:
    {E = en(2)}      <==>   [1   0]
                            [0   1]
    {A = 1,,2;3,8,7} <==>   [1   0   2]
                            [3   8   7]

矩阵函数:
    +, -, *, ^, A^(-1), A^(n), cp(A), rot(A), en(A)
    gs(A), diag(A), lad(A), tri(A)
    tr(A), r(A), det(A)
    lf(n): 控制精度

example:
    mat "[A=1,0;1,1] [B=A^(2)] [C=A^(-1)+B] [(A^(-1))-C] [det(A
    You can use the letters A to O to name the matrix
    {E = en(2)}      <==>   [1   0]
                            [0   1]
    {A = 1,,2;3,8,7} <==>   [1   0   2]
                            [3   8   7]
matrix functions:
    +, -, *, ^, A^(-1), A^(n), cp(A), rot(A), en(A)
    gs(A), diag(A), lad(A), tri(A)
    tr(A), r(A), det(A)
    lf(n): control print precision

作者: Byaidu    时间: 2021-5-24 00:32

大佬太厉害了




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2