97#include "ramCanvas.hpp"
100enum class whyStopNV { DIVZERO,
107enum class solMethNV { NEWTON,
114 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
115 const double escapeMod = -32.0;
116 const int MaxCount = 64;
117 const double Tol = 0.0001;
118 const int numToKeep = 1;
120 mjr::ramCanvas3c8b theRamCanvas(3840, 2160, -1.5, 1.5, -1.5, 1.5);
121 std::vector<solMethNV> methodsToDo({solMethNV::NEWTON, solMethNV::HALLEY, solMethNV::LAGUERRE});
123 for(
auto method : methodsToDo) {
124 mjr::ramCanvas3c8b::colorType aColor(255, 255, 255);
126 for(
int y=0;y<theRamCanvas.getNumPixY();y++) {
128 std::cout <<
"Case: " << (int)method <<
" Line: " << y << std::endl;
129 for(
int x=0;x<theRamCanvas.getNumPixX();x++) {
130 std::complex<double> z = theRamCanvas.int2real(x, y);
132 std::vector<std::complex<double>> lastZs(numToKeep);
133 mjr::ramCanvas3c8b::csIntType count = 0;
136 if (count >= MaxCount) {
137 why = whyStopNV::TOOLONG;
141 std::complex<double> f0v=sin(cos(z));
142 std::complex<double> f1v=-sin(z)*cos(cos(z));
143 std::complex<double> f2v=(-sin(z)*sin(z)*sin(cos(z)))-cos(z)*cos(cos(z));
146 case solMethNV::NEWTON : {
148 why = whyStopNV::DIVZERO;
154 case solMethNV::HALLEY : {
156 why = whyStopNV::DIVZERO;
159 std::complex<double> G=f0v/f1v;
160 std::complex<double> b=1.0-G*f2v/f1v;
162 why = whyStopNV::DIVZERO;
165 std::complex<double> a=G/b;
169 case solMethNV::LAGUERRE : {
170 std::complex<double> pdeg = 4.0;
174 std::complex<double> G=f1v/f0v;
175 std::complex<double> G2=G*G;
176 std::complex<double> H=G2-f2v/f0v;
177 std::complex<double> sqr=(pdeg-1.0)*(pdeg*H-G2);
178 std::complex<double> sq=sqrt(sqr);
179 std::complex<double> b1=G+sq;
180 std::complex<double> b2=G-sq;
181 std::complex<double> b=b2;
185 why = whyStopNV::DIVZERO;
188 std::complex<double> a=pdeg/b;
194 double modz = abs(z);
195 lastZs[count%numToKeep] = z;
199 if(count >= numToKeep) {
200 bool allEqual =
true;
201 for(
int i=1; i<numToKeep; i++)
202 if(abs(lastZs[0]-lastZs[i])>Tol) {
208 why = whyStopNV::CONVERGEU;
210 why = whyStopNV::CONVERGEL;
215 if((escapeMod>0) && (modz>escapeMod)) {
216 why = whyStopNV::TOOBIG;
222 mjr::ramCanvas3c8b::csIntType ccol = (2*4*count);
223 mjr::ramCanvas3c8b::csIntType mcol = ( mjr::ramCanvas3c8b::csIntType )(2*8*maxMod);
225 case whyStopNV::TOOLONG : theRamCanvas.drawPoint(x, y, aColor.cmpRGBcornerDGradiant((mcol)%(2*256),
"MWM"));
break;
226 case whyStopNV::CONVERGEU : theRamCanvas.drawPoint(x, y, aColor.cmpRGBcornerDGradiant((mcol+ccol)%(2*256),
"BWB"));
break;
227 case whyStopNV::CONVERGEL : theRamCanvas.drawPoint(x, y, aColor.cmpRGBcornerDGradiant((mcol+ccol)%(2*256),
"RWR"));
break;
228 case whyStopNV::TOOBIG : theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType(0, 0, 0));
break;
229 case whyStopNV::DIVZERO : theRamCanvas.drawPoint(x, y, aColor.cmpRGBcornerDGradiant((mcol+ccol)%(2*256),
"CWC"));
break;
235 case solMethNV::NEWTON : theRamCanvas.writeTIFFfile(
"newton_vs_newton.tiff" );
break;
236 case solMethNV::HALLEY : theRamCanvas.writeTIFFfile(
"newton_vs_halley.tiff" );
break;
237 case solMethNV::LAGUERRE : theRamCanvas.writeTIFFfile(
"newton_vs_laguerre.tiff");
break;
240 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
241 std::cout <<
"Total Runtime " << runTime.count() <<
" sec" << std::endl;
int main(int argc, char *argv[])