List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:edu.packt.neuralnet.som.Kohonen2DTest.java
public static void main(String[] args) { RandomNumberGenerator.seed = System.currentTimeMillis(); int numberOfInputs = 2; int neuronsGridX = 12; int neuronsGridY = 12; int numberOfPoints = 1000; double[][] rndDataSet; rndDataSet = RandomNumberGenerator.GenerateMatrixGaussian(numberOfPoints, numberOfInputs, 100.0, 1.0); //rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, 100.0, 110.0); for (int i = 0; i < numberOfPoints; i++) { rndDataSet[i][0] *= Math.sin(i); rndDataSet[i][0] += RandomNumberGenerator.GenerateNext() * 50; rndDataSet[i][1] *= Math.cos(i); rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 50; }/*w w w . j a va 2 s. c o m*/ // for (int i=0;i<numberOfPoints;i++){ // rndDataSet[i][0]=i; // rndDataSet[i][0]+=RandomNumberGenerator.GenerateNext(); // rndDataSet[i][1]=Math.cos(i/100.0); // rndDataSet[i][1]+=RandomNumberGenerator.GenerateNext()*5; // } Kohonen kn2 = new Kohonen(numberOfInputs, neuronsGridX, neuronsGridY, new GaussianInitialization(500.0, 20.0)); NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2); CompetitiveLearning complrn = new CompetitiveLearning(kn2, neuralDataSet, LearningAlgorithm.LearningMode.ONLINE); complrn.show2DData = true; complrn.printTraining = true; complrn.setLearningRate(0.5); complrn.setMaxEpochs(1000); complrn.setReferenceEpoch(300); complrn.sleep = -1; try { String[] seriesNames = { "Training Data" }; Paint[] seriesColor = { Color.WHITE }; Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS); ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y")); frame.pack(); frame.setVisible(true); // //System.in.read(); complrn.setPlot2DFrame(frame); complrn.showPlot2DData(); //System.in.read(); complrn.train(); } catch (Exception ne) { } }
From source file:MainClass.java
public static void main(String args[]) { System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7)); System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0)); System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7)); System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2)); System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8)); System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0)); System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0)); System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0)); System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2)); System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8)); System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E)); System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E)); System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7)); System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7)); System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7)); System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7)); System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0)); System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5)); System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0)); System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0)); System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0)); System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0)); }
From source file:TrigonometricDemo.java
public static void main(String[] args) { double degrees = 45.0; double radians = Math.toRadians(degrees); System.out.format("The value of pi is %.4f%n", Math.PI); System.out.format("The sine of %.1f degrees is %.4f%n", degrees, Math.sin(radians)); System.out.format("The cosine of %.1f degrees is %.4f%n", degrees, Math.cos(radians)); System.out.format("The tangent of %.1f degrees is %.4f%n", degrees, Math.tan(radians)); System.out.format("The arcsine of %.4f is %.4f degrees %n", Math.sin(radians), Math.toDegrees(Math.asin(Math.sin(radians)))); System.out.format("The arccosine of %.4f is %.4f degrees %n", Math.cos(radians), Math.toDegrees(Math.acos(Math.cos(radians)))); System.out.format("The arctangent of %.4f is %.4f degrees %n", Math.tan(radians), Math.toDegrees(Math.atan(Math.tan(radians)))); }
From source file:TrigonometricDemo.java
public static void main(String[] args) { double degrees = 45.0; double radians = Math.toRadians(degrees); System.out.println("The value of pi is " + Math.PI); System.out.println("The sine of " + degrees + " is " + Math.sin(radians)); System.out.println("The cosine of " + degrees + " is " + Math.cos(radians)); System.out.println("The tangent of " + degrees + " is " + Math.tan(radians)); System.out.println("The arc sine of " + Math.sin(radians) + " is " + Math.toDegrees(Math.asin(Math.sin(radians))) + " degrees"); System.out.println("The arc cosine of " + Math.cos(radians) + " is " + Math.toDegrees(Math.acos(Math.cos(radians))) + " degrees"); System.out.println("The arc tangent of " + Math.tan(radians) + " is " + Math.toDegrees(Math.atan(Math.tan(radians))) + " degrees"); }
From source file:Rotate45Degrees.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);// w w w .jav a 2 s . co m gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Rotate by 45 degrees //float cos45 = (float)Math.cos(45); float cos45 = (float) Math.cos(Math.PI / 4); //float sin45 = (float)Math.sin(45); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc.setTransform(transform); gc.drawImage(image, 350, 100); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:net.liuxuan.temp.filterTest.java
public static void main(String[] args) { double constantVoltage = 10d; double measurementNoise = 0.1d; double processNoise = 1e-5d; // A = [ 1 ]/*w w w . j a v a 2 s .c o m*/ RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d }); // B = null RealMatrix B = null; // H = [ 1 ] RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d }); // x = [ 10 ] RealVector x = new ArrayRealVector(new double[] { constantVoltage }); // Q = [ 1e-5 ] RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise }); // P = [ 1 ] RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1d }); // R = [ 0.1 ] RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise }); ProcessModel pm = new DefaultProcessModel(A, B, Q, x, P0); MeasurementModel mm = new DefaultMeasurementModel(H, R); KalmanFilter filter = new KalmanFilter(pm, mm); // process and measurement noise vectors RealVector pNoise = new ArrayRealVector(1); RealVector mNoise = new ArrayRealVector(1); RandomGenerator rand = new JDKRandomGenerator(); // iterate 60 steps for (int i = 0; i < 60; i++) { filter.predict(); // simulate the process // pNoise.setEntry(0, processNoise * rand.nextGaussian()); pNoise.setEntry(0, Math.sin(Math.PI * 2 * i / 6)); // System.out.println("============"); // System.out.println(Math.sin(Math.PI*2*i/6)); // x = A * x + p_noise x = A.operate(x).add(pNoise); // simulate the measurement // mNoise.setEntry(0, measurementNoise * rand.nextGaussian()); mNoise.setEntry(0, 0); // z = H * x + m_noise RealVector z = H.operate(x).add(mNoise); filter.correct(z); double voltage = filter.getStateEstimation()[0]; System.out.println(voltage); // state estimate shouldn't be larger than the measurement noise double diff = Math.abs(x.getEntry(0) - filter.getStateEstimation()[0]); System.out.println("diff = " + diff); } }
From source file:jtrace.scenes.OneCubeAnimate.java
public static void main(String[] args) throws IOException { Scene scene = new Scene(); scene.addLightSource(new LightSource(new Vector3D(-3, 3, -3), 4)); scene.addLightSource(new LightSource(new Vector3D(6, 6, -3), 4)); FlatTexture cubeTexture = (new FlatTexture(new SolidPigment(new Colour(0, 0, 1)))); cubeTexture.addFinish(new DiffuseFinish(1.0)); cubeTexture.addFinish(new AmbientFinish(0.1)); cubeTexture.addFinish(new MirrorFinish(0.2)); Cube cube = new Cube(new Vector3D(0, 0, 0), 0.5); cube.addTexture(cubeTexture);//from w ww . ja va 2 s . c o m scene.addObject(cube); // FlatTexture floorTexture = new FlatTexture(new CheckeredPigment( // new Colour(.5,.5,.5), new Colour(1,1,1), 1)); FlatTexture floorTexture = new FlatTexture(new ImagePigment(new File("wood.jpg"), 1.0)); floorTexture.addFinish(new DiffuseFinish(1.0)); Plane plane = new Plane(new Vector3D(0, -0.25, 0), Vector3D.PLUS_J, Vector3D.PLUS_K); plane.addTexture(floorTexture); scene.addObject(plane); Vector3D pointAt = new Vector3D(0, 0, 0); int steps = 100; for (int i = 0; i < steps; i++) { double R = 2.0; double x = R * Math.sin(i * 2 * Math.PI / steps); double z = -R * Math.cos(i * 2 * Math.PI / steps); Camera camera = new Camera(new Vector3D(x, 1, z), pointAt, Vector3D.PLUS_J, 1.0, 800.0 / 600.0); scene.setCamera(camera); BufferedImage image = scene.render(800, 600, 10); ImageIO.write(image, "PNG", new File(String.format("out_%02d.png", i))); } }
From source file:info.financialecology.finance.utilities.sandbox.SimpleStrategyCOND.java
public static void main(String[] args) { SimpleStrategyCOND strategyCOND = new SimpleStrategyCOND(); int nTicks = 200; // Number of ticks double sinus_shift = 0.0; double sinus_amplitude = 10.0; double sinus_lambda = 50.0; double sinus_t_prev = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); for (int i = 1; i < nTicks; i++) { double sinus_t = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); logger.info("Tick: " + i + ", value: " + sinus_t + ", position: " + strategyCOND.newPosition(sinus_t, sinus_t_prev)); sinus_t_prev = sinus_t;/*from www . j a va 2s . co m*/ } }
From source file:org.eclipse.swt.snippets.Snippet207.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);// w w w. j ava2 s . c o m gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(e -> { GC gc1 = e.gc; gc1.setAdvanced(true); if (!gc1.getAdvanced()) { gc1.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc1.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Note that the tranform is applied to the whole GC therefore // the coordinates need to be adjusted too. // Reflect around the y axis. transform.setElements(-1, 0, 0, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, -1 * x - rect.width, y); x = 30; y += rect.height + 30; // Reflect around the x axis. transform.setElements(1, 0, 0, -1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, x, -1 * y - rect.height); x += rect.width + 30; // Reflect around the x and y axes transform.setElements(-1, 0, 0, -1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, -1 * x - rect.width, -1 * y - rect.height); x = 30; y += rect.height + 30; // Shear in the x-direction transform.setElements(1, 0, -1, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 300, y); // Shear in y-direction transform.setElements(1, -1, 0, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 150, 475); // Rotate by 45 degrees float cos45 = (float) Math.cos(Math.PI / 4); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 400, 60); transform.dispose(); }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet195.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;/*from w ww .j a va 2 s . c o m*/ final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); GL.createCapabilities(); canvas.addListener(SWT.Resize, event -> { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); GL.createCapabilities(); GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float near = 0.5f; float bottom = -near * (float) Math.tan(45.f / 2); float left = fAspect * bottom; GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); shell.setText("SWT/LWJGL Example"); shell.setSize(640, 480); shell.open(); final Runnable run = new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); GL.createCapabilities(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }; canvas.addListener(SWT.Paint, event -> run.run()); display.asyncExec(run); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }