Question
This is the problem i am working on: Graphing functions with Java graphics library: Create an applet/GUI to draw a graph of a function sine
This is the problem i am working on:
Graphing functions with Java graphics library:
Create an applet/GUI to draw a graph of a function sine in cartesian or parametric coordinates. You need to draw n line segments joining the successive points (x, f(x)) and (x + d, f(x + d)) (or two points (x(t), y(t)) and (x(t + d)y(t + d)) if using parametric coordinates). Experiment with values of n = 10, 25, 50, 100, 200 to make the best choice.
Draw the graphics of the following three functiions:
a) f(x) = x^3 + x - 3 on the interval [0, 4]
b) g(x) = x^3/100 - x + 10 on the interval [-10, 10]
c) "The four-leaved rose" whose equation in polar coordinates is r = cos2 with 0 2
This is the code that i have:
package JavaApplication8;
import java.awt.*; import java.applet.*;
public class JavaApplication8 extends Applet { int txmi, tymi, txma, tyma; double xmi, ymi, xma, yma; double deltax; double x1, x2, y1, y2;
public void init(){ xmi = -8; xma = 8; ymi = -5; yma = 5; txmi = 0; txma = 500; tymi = 0; tyma = 500; deltax = 0 * 1; }
public void paint(Graphics g1) { double a, b, c, d; g1.setColor(Color.green); Line(g1, 0, ymi, 0, yma); Line(g1, xmi, 0, xma, 0); g1.setColor(Color.black); x2 = xmi; y2 = funct(x2); for(x1 = xmi; x1 <= xma; x1 = x1 + deltax) { y1 = funct(x1); Line(g1, x1, y1, x2, y2); x2 = x1; y2 = y1; } } public int createmapX(double x) { int sx; sx = txmi + (int)((x - xmi)/(xma - xmi)*(double)(txma - txmi)); return sx; } public int createmapY(double y){ int sy; sy = tymi + (int)((yma - y)/(yma - ymi)*(double)(tyma - tymi)); return sy; } public void Line(Graphics g1, double x1, double y1, double x2, double y2) { g1.drawLine(createmapX(x1), createmapY(y1), createmapX(x2),createmapY(y2)); } public double funct(double x){ double y; y = x*x; return y; } }
I need help debugging the program to show the curves of the graph. When i run the program it says the applet is started but it doesn't show the graph. Please give the typed debugged code and post screenshots of the graph. Also please explain what each part of the program is doing in comments as i was given this code and do not understand it completely. Thanks in advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started