复牛顿迭代法
绘图库:Easy Graphics Engine (EGE)
编程语言:c++
z=z^3-1
z=z^4-1
z=sin(z)
z=z^6-1
代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <windows.h>
#include <graphics.h>
#include <conio.h>
#include <graphics.h>
#include <complex.h>
#define pi 3.1415926
#define H 600.0
#define W 600.0
const int NUM_ITER = 1000; // 迭代次数
const int N = 500;
#ifndef SWAP
#define SWAP(a, b, t) {
t = a; a = b; b = t;}
#endif // ! SWAP
void color(short x)//设置字体颜色的自定义函数
{
if((x>=0)&&(x<=15))
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
}
//0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色
//6=黄色 7=白色 8=灰色 9=淡蓝色 10=淡绿色 11=淡浅绿色
//12=淡红色 13=淡紫色 14=淡黄色 15=亮白色
struct Complex
{
double re, im;
Complex() :re(0.0), im(0.0) {
}
Complex(double real, double imag) : re(real), im(imag) {
}
//重载运算符
Complex operator * (Complex c) {
return Complex(re * c.re - im * c.im, im * c.re + re * c.im); }
//Complex operator / (Complex c) { if(c.re==0&&c.im==0){return Complex(0,0);}else {return Complex((re*c.re+im*c.im)/(c.re*c.re+c.im*c.im),(im*c.re-re*c.im)/(c.re*c.re+c.im*c.im))}};
Complex operator + (Complex c) {
return Complex(re + c.re, im + c.im); }
Complex operator - (Complex c) {
return Complex(re - c.re, im - c.im); }
//Complex operator ^ (double n) { return Complex(pow(sqrt(re*re+im*im),n)*cos(n*atan(im/re)),pow(sqrt(re*re+im*im),n)*sin(n*atan(im/re))); }
};
Complex operator / (Complex a, Complex b)
{
Complex c;
if(b.re==0&&b.im==0)
{
c.re = 0;
c