你好,复变函数2.0

2024-06-22 18:20
文章标签 函数 你好 2.0 复变

本文主要是介绍你好,复变函数2.0,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

 第一行:0 或 1

 第二行:(空格)+函数(后缀)

#pragma warning(disable:4996)
#include <easyx.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define E  2.718281828459045
#define K  (1.0 / 256.0)
#define K_1 256.0
struct C {double i;double r;C operator = (C n) {i = n.i; r = n.r;return C({ i, r });}C operator + (C n) {return C({ i + n.i, r + n.r });}C operator - (C n) {return C({ i - n.i, r - n.r });}C operator * (C n) {return C({ r * n.i + i * n.r, r * n.r - i * n.i});}C operator / (C n) {return C({(i * n.r - r * n.i) / (n.i * n.i + n.r * n.r),(i * n.i + r * n.r) / (n.i * n.i + n.r * n.r)});}void print() {printf("%lfi%+lf", i, r);}
};
int top = 0;
int len = 0;
int _line;
int p[4096][2];
char str[512];
C stack[512];
void getnum(int l) {bool k = false;double x = 1.0;stack[top] = C({ 0, 0 });for (int i = l; str[i] != ' ' && str[i] != '\0'; i++) {if (k) x *= 10;if (str[i] != '.')stack[top] = stack[top] * C({ 0, 10 }) + C({ 0, double(str[i] - '0') });else k = true;}stack[top] = stack[top] / C({ 0, x });top++;
}
void del(C c) {for (int i = 0; str[i] != '\0'; i++) {if (str[i] == ' ') {i++;if (str[i] >= '0' && str[i] <= '9')getnum(i);if (str[i] == 'e')stack[top++] = C({ 0, E });if (str[i] == 'x')stack[top++] = c;if (str[i] == '+') {top--;stack[top - 1] = stack[top - 1] + stack[top];}if (str[i] == '-') {top--;stack[top - 1] = stack[top - 1] - stack[top];}if (str[i] == '*') {top--;stack[top - 1] = stack[top - 1] * stack[top];}if (str[i] == '/') {top--;stack[top - 1] = stack[top - 1] / stack[top];}if (str[i] == '^') {top--;if (stack[top - 1].i == 0) {C c;c.r = cos(log(pow(stack[top - 1].r, stack[top].i))) * pow(stack[top - 1].r, stack[top].r);c.i = sin(log(pow(stack[top - 1].r, stack[top].i)));stack[top - 1] = c;}else if (stack[top].i == 0) {
#define A(x, y) (sqrt((x) * (x) + (y) * (y)))C c;c.r = pow(A(stack[top - 1].i, stack[top - 1].r), stack[top].r) * cos(stack[top].r * asin(stack[top - 1].i / A(stack[top - 1].i, stack[top - 1].r)));c.i = pow(A(stack[top - 1].i, stack[top - 1].r), stack[top].r) * sin(stack[top].r * asin(stack[top - 1].i / A(stack[top - 1].i, stack[top - 1].r)));stack[top - 1] = c;
#undef A}else {MessageBox(NULL,L"暂不支持此运算",  L"Error", MB_OK);}}}}p[len][0] = 512 + int(stack[0].r * K_1 + 0.5);p[len][1] = 512 - int(stack[0].i * K_1 + 0.5);if (_line == 0)putpixel(p[len][0], p[len][1], RGB(0, 255, 255));len++;
}
int main() {initgraph(1024, 1024, EX_SHOWCONSOLE);setlinecolor(RGB(0, 255, 255));scanf("%d", &_line);getchar();gets_s<512>(str);for (int y = -1024; y < 1024; y += 16) {len = 0;for (int x = -1024; x < 1024; x += 1) {top = 0;C c = { y * K, x * K };del(c);}if (_line == 1)for (int i = 0; i < len - 1; i++) {line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);}}for (int y = -1024; y < 1024; y += 16) {len = 0;for (int x = -1024; x < 1024; x += 1) {top = 0;C c = { x * K, y * K };del(c);}if (_line == 1)for (int i = 0; i < len - 1; i++) {line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);}}saveimage(L"1.jpg");printf("--------\n");getchar();closegraph();
}

这篇关于你好,复变函数2.0的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1085060

相关文章

Python函数作用域与闭包举例深度解析

《Python函数作用域与闭包举例深度解析》Python函数的作用域规则和闭包是编程中的关键概念,它们决定了变量的访问和生命周期,:本文主要介绍Python函数作用域与闭包的相关资料,文中通过代码... 目录1. 基础作用域访问示例1:访问全局变量示例2:访问外层函数变量2. 闭包基础示例3:简单闭包示例4

Python中isinstance()函数原理解释及详细用法示例

《Python中isinstance()函数原理解释及详细用法示例》isinstance()是Python内置的一个非常有用的函数,用于检查一个对象是否属于指定的类型或类型元组中的某一个类型,它是Py... 目录python中isinstance()函数原理解释及详细用法指南一、isinstance()函数

python中的高阶函数示例详解

《python中的高阶函数示例详解》在Python中,高阶函数是指接受函数作为参数或返回函数作为结果的函数,下面:本文主要介绍python中高阶函数的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录1.定义2.map函数3.filter函数4.reduce函数5.sorted函数6.自定义高阶函数

Python中的sort方法、sorted函数与lambda表达式及用法详解

《Python中的sort方法、sorted函数与lambda表达式及用法详解》文章对比了Python中list.sort()与sorted()函数的区别,指出sort()原地排序返回None,sor... 目录1. sort()方法1.1 sort()方法1.2 基本语法和参数A. reverse参数B.

Python函数的基本用法、返回值特性、全局变量修改及异常处理技巧

《Python函数的基本用法、返回值特性、全局变量修改及异常处理技巧》本文将通过实际代码示例,深入讲解Python函数的基本用法、返回值特性、全局变量修改以及异常处理技巧,感兴趣的朋友跟随小编一起看看... 目录一、python函数定义与调用1.1 基本函数定义1.2 函数调用二、函数返回值详解2.1 有返

Python Excel 通用筛选函数的实现

《PythonExcel通用筛选函数的实现》本文主要介绍了PythonExcel通用筛选函数的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录案例目的示例数据假定数据来源是字典优化:通用CSV数据处理函数使用说明使用示例注意事项案例目的第一

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

GO语言中函数命名返回值的使用

《GO语言中函数命名返回值的使用》在Go语言中,函数可以为其返回值指定名称,这被称为命名返回值或命名返回参数,这种特性可以使代码更清晰,特别是在返回多个值时,感兴趣的可以了解一下... 目录基本语法函数命名返回特点代码示例命名特点基本语法func functionName(parameters) (nam

Python Counter 函数使用案例

《PythonCounter函数使用案例》Counter是collections模块中的一个类,专门用于对可迭代对象中的元素进行计数,接下来通过本文给大家介绍PythonCounter函数使用案例... 目录一、Counter函数概述二、基本使用案例(一)列表元素计数(二)字符串字符计数(三)元组计数三、C

Python中的filter() 函数的工作原理及应用技巧

《Python中的filter()函数的工作原理及应用技巧》Python的filter()函数用于筛选序列元素,返回迭代器,适合函数式编程,相比列表推导式,内存更优,尤其适用于大数据集,结合lamb... 目录前言一、基本概念基本语法二、使用方式1. 使用 lambda 函数2. 使用普通函数3. 使用 N