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 - The Fusion of Science and Community**

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

# Very strange occurence in Java

Loading...

Similar Threads - Very strange occurence | Date |
---|---|

Struggling with a strange on screen format issue | Jan 9, 2018 |

Which programming language would you want to teach to a very young person (5-7 y/o) | Nov 14, 2017 |

Reading a lot of data very quickly with Arduino? | May 14, 2017 |

Java Probably very easy question about isNaN() java | Jan 10, 2017 |

Python Adding very small values to very large numbers | Jun 9, 2016 |

**Physics Forums - The Fusion of Science and Community**