Question: I'm trying to write out this code in C++ to graph the Bat-Curve function. However, I am having trouble with imaginary numbers. This is my

I'm trying to write out this code in C++ to graph the Bat-Curve function. However, I am having trouble with imaginary numbers. This is my code:
#include "std_lib_facilities.h" #include "Simple_window.h" #include "Graph.h" #include "FL/Fl_JPEG_Image.H" #include
double H_step(double x) { if(x >= 0) x = 1; else x = 0; return x; }
double sgn(double x) { if (x > 0) return 1; if (x
double f(double x) { double w = 3*sqrt(1 - pow(x/7,2)); double l = (6/7)*sqrt(10) + (3 + x)/2 - (3/7)*sqrt(10)*sqrt(4 - pow(x+1,2)); double h = (3*(abs(x - 1/2) + abs(x + 1/2) + 6) - 11*(abs(x - 3/4) + abs(x + 3/4)))/2; double r = (1/2)*(3-x) - (3/7)*sqrt(10)*sqrt(4 - pow(x-1,2)) + (6/7)*sqrt(10); double top_bat = (h - l)*H_step(x+1) + (r - h)*H_step(x-1) + (l - w)*H_step(x+3)+(w - r)*H_step(x-3) + w; return top_bat; }
double g(double x) { double bottom_bat = (abs((1/2)*x) + sqrt(1-pow(abs(abs(x)-2)-1,2)) - (1/112)*(3*sqrt(33) - 7)*pow(x,2) + 3*sqrt(1-pow((1/7)*x,2)) - 3)/2 * (sgn(x+4) - sgn(x-4)) - 3*sqrt(1 - pow((1/7)*x,2)); return bottom_bat; }
int main() try { if(H112 != 201708L)error("Error: incorrect std_lib_facilities_5.h version ",H112);
Simple_window win(Point(100,100),800,800,"Grid"); Function top (f,-7,7,Point(win.x_max()/2,win.y_max()/2),1024,50,50);
Function bottom (g,-7,7,Point(win.x_max()/2,win.y_max()/2),1024,50,50); //add points in order Closed_polyline bat; for(int i = 0; i 0; --i) { bat.add(bottom.point(i)); } //create color batman yellow Color batman_yellow(fl_rgb_color(255, 208, 70)); //draw a thick black ellipse Ellipse body(Point(400,400),400,200); body.set_style(Line_style{Line_style::solid,5}); bat.set_style(Line_style{Line_style::solid,5}); bat.set_fill_color(Color::black); body.set_fill_color(batman_yellow); //Create function object with win.attach(body); win.attach(bat); win.wait_for_button(); return 0; }
And here is what I am getting:

Please let me know if you can help. Thank you
f(x)-(h-DH(1) -h) H (x-1)+-w)H(3)+(w-)H x-3)+ w where H (r) is the Heaviside step function and (from http://mathworld.wolfram.com/BatmanCurve.html) as follows a) Draw a thick black ellipse with radii 200 and 400 in the center of the window and fill it with batman_yellow (see problem 1) b) Create a Function object with the Cartesian coordinate origin in the center of the window, 1024 points, and both scale factors at 50, plotting the real part of f(x) for xfrom-7to7 c) Create a Function object with the Cartesian coordinate origin in the center of the window, 1024 points, and both scale factors at 50, plotting the real part of g(x) for xfrom-7to7 d) Create a Closed_polyline and add the points from (b) to it in order, followed by the points from (c) n reverse order. Hint: Use the point(i) and number of point ions in a for loop to access the points in the two Function objects e) Attach the ClosedPolyline to the window and fill it with black. (Note: Do not attach the Function obiects; they were just used to generate the points.) f) Draw the window and its attached Batman logo! Hints The square roots in the formulas (other than square root of a positive integer) need to be complex, so #nclude
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
