I am using JAVA to generate a graph of the E field close to a conducting plane. The result which I want to graph is $$E_z (x)= \frac{Q}{2\pi \epsilon_o} \left(\frac{d}{(x^2+d^2)^{3/2}} - \frac{h}{(x^2+h^2)^{3/2}}\right).$$(adsbygoogle = window.adsbygoogle || []).push({});

The code is below:

Could somebody check that I have entered the eqn in correctly? The program runs fine and I have a graph, but it doesn't agree at particular values of x. For example, for E=0, x approx. 30 in the graph, but it should be about 50. I realize that what I have is more complicated than it should be - I have tried many different ways to express the same thing.Code (Text):

import java.io.Console;

import java.io.*;

import java.lang.Math;

import java.lang.Boolean;

import ptolemy.plot.*;

public class Edipole {

public static void main (String args[]) {

Console myConsole = System.console();

Plot disc = new Plot();

disc.setTitle("Graph of the field component near the conducting plane for all x");

disc.setXLabel("distance along x");

disc.setYLabel("E field");

PlotFrame myFrame = new PlotFrame("E vs x", disc);

myFrame.setSize(10,20);

int dataSet = 0;

double q = 4;

double d = 10;

double h = 1;

double eps = 8.85e-12;

int points = 500;

double E[] = new double[points];

double x[] = new double[points];

for(int i = 0; i < (points-1); i++) {

x[i] = (100*(int)i/points);

double Eqn = (q/(2*(Math.PI)*eps))*(d/Math.pow((Math.sqrt(x[i]*x[i]+d*d)),3) - h/((Math.pow((Math.sqrt(x[i]*x[i]+h*h)),3)));

disc.addPoint(dataSet, x[i], Eqn, true);

}

System.out.println("Graph created");

myFrame.setVisible(true);

//System.exit(0);

}

}

After a while, I obtained the same expression over and over again no matter what change I made to it. So, for fun, I deleted the whole eqn and wrote double Eqn = 3xin its place. What I got was the exact same graph, which makes absolutely no sense.

Can anyone explain this bizarre occurrence?

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Java Very strange occurence in Java

**Physics Forums | Science Articles, Homework Help, Discussion**