package com.nevynslab.math; /* * Generated by www.nevyns-lab.com on 2019-08-23T08:52:53+10:00. * * MIT License * * Copyright (c) 2017 Nevyn's Lab * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ import java.util.List; import java.util.ArrayList; /** * This class contains inner classes that each provide methods for an equation. */ public class Equations { /** * This class provides methods for the Momentum equation. */ public static class Momentum { public static final String TYPE = "momentum"; public static final String VERSION = "1.0"; public static final String TITLE = "Momentum"; public static final String DESCRIPTION = "These calculators can be used to generate data using mass, velocity and momentum."; /** * Public method that calculates momentum. * You can reference it in your code as "Equations.Momentum.calcMomentum( ... )". */ public static double calcMomentum(double mass, double velocity) { // M = mv return mass*velocity; } /** * The public method to calculate a list of momentum values by varying the mass. * You can reference it in your code as "Equations.Momentum.calcMomentumVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each momentum value. */ public static List calcMomentumVsMass(double massMin, double massMax, double massStep, double velocity, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMomentum( value, velocity ) ); value += massStep; } return data; } /** * The public method to calculate a list of momentum values by varying the velocity. * You can reference it in your code as "Equations.Momentum.calcMomentumVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each momentum value. */ public static List calcMomentumVsVelocity(double velocityMin, double velocityMax, double velocityStep, double mass, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMomentum( mass, value ) ); value += velocityStep; } return data; } /** * Public method that calculates mass. * You can reference it in your code as "Equations.Momentum.calcMass( ... )". */ public static double calcMass(double velocity, double momentum) { // m = M/v return momentum / velocity; } /** * The public method to calculate a list of mass values by varying the velocity. * You can reference it in your code as "Equations.Momentum.calcMassVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each mass value. */ public static List calcMassVsVelocity(double velocityMin, double velocityMax, double velocityStep, double momentum, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( value, momentum ) ); value += velocityStep; } return data; } /** * The public method to calculate a list of mass values by varying the momentum. * You can reference it in your code as "Equations.Momentum.calcMassVsMomentum( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the momentum value for each mass value. */ public static List calcMassVsMomentum(double momentumMin, double momentumMax, double momentumStep, double velocity, List data, List labels) { double value = momentumMin; if( data == null ) { data = new ArrayList(); } while( value <= momentumMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( velocity, value ) ); value += momentumStep; } return data; } /** * Public method that calculates velocity. * You can reference it in your code as "Equations.Momentum.calcVelocity( ... )". */ public static double calcVelocity(double momentum, double mass) { // v = M/m return momentum/mass; } /** * The public method to calculate a list of velocity values by varying the momentum. * You can reference it in your code as "Equations.Momentum.calcVelocityVsMomentum( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the momentum value for each velocity value. */ public static List calcVelocityVsMomentum(double momentumMin, double momentumMax, double momentumStep, double mass, List data, List labels) { double value = momentumMin; if( data == null ) { data = new ArrayList(); } while( value <= momentumMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( value, mass ) ); value += momentumStep; } return data; } /** * The public method to calculate a list of velocity values by varying the mass. * You can reference it in your code as "Equations.Momentum.calcVelocityVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each velocity value. */ public static List calcVelocityVsMass(double massMin, double massMax, double massStep, double momentum, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( momentum, value ) ); value += massStep; } return data; } } /** * This class provides methods for the Force equation. */ public static class Force { public static final String TYPE = "force"; public static final String VERSION = "1.0"; public static final String TITLE = "Force"; public static final String DESCRIPTION = "These calculators can be used to generate data using mass, acceleration and force."; /** * Public method that calculates force. * You can reference it in your code as "Equations.Force.calcForce( ... )". */ public static double calcForce(double mass, double acceleration) { // f = ma return mass*acceleration; } /** * The public method to calculate a list of force values by varying the mass. * You can reference it in your code as "Equations.Force.calcForceVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each force value. */ public static List calcForceVsMass(double massMin, double massMax, double massStep, double acceleration, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcForce( value, acceleration ) ); value += massStep; } return data; } /** * The public method to calculate a list of force values by varying the acceleration. * You can reference it in your code as "Equations.Force.calcForceVsAcceleration( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the acceleration value for each force value. */ public static List calcForceVsAcceleration(double accelerationMin, double accelerationMax, double accelerationStep, double mass, List data, List labels) { double value = accelerationMin; if( data == null ) { data = new ArrayList(); } while( value <= accelerationMax ) { if( labels != null ) { labels.add( value ); } data.add( calcForce( mass, value ) ); value += accelerationStep; } return data; } /** * Public method that calculates mass. * You can reference it in your code as "Equations.Force.calcMass( ... )". */ public static double calcMass(double acceleration, double force) { // m = F/a return force / acceleration; } /** * The public method to calculate a list of mass values by varying the acceleration. * You can reference it in your code as "Equations.Force.calcMassVsAcceleration( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the acceleration value for each mass value. */ public static List calcMassVsAcceleration(double accelerationMin, double accelerationMax, double accelerationStep, double force, List data, List labels) { double value = accelerationMin; if( data == null ) { data = new ArrayList(); } while( value <= accelerationMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( value, force ) ); value += accelerationStep; } return data; } /** * The public method to calculate a list of mass values by varying the force. * You can reference it in your code as "Equations.Force.calcMassVsForce( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the force value for each mass value. */ public static List calcMassVsForce(double forceMin, double forceMax, double forceStep, double acceleration, List data, List labels) { double value = forceMin; if( data == null ) { data = new ArrayList(); } while( value <= forceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( acceleration, value ) ); value += forceStep; } return data; } /** * Public method that calculates acceleration. * You can reference it in your code as "Equations.Force.calcAcceleration( ... )". */ public static double calcAcceleration(double force, double mass) { // a = F/m return force/mass; } /** * The public method to calculate a list of acceleration values by varying the force. * You can reference it in your code as "Equations.Force.calcAccelerationVsForce( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the force value for each acceleration value. */ public static List calcAccelerationVsForce(double forceMin, double forceMax, double forceStep, double mass, List data, List labels) { double value = forceMin; if( data == null ) { data = new ArrayList(); } while( value <= forceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcAcceleration( value, mass ) ); value += forceStep; } return data; } /** * The public method to calculate a list of acceleration values by varying the mass. * You can reference it in your code as "Equations.Force.calcAccelerationVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each acceleration value. */ public static List calcAccelerationVsMass(double massMin, double massMax, double massStep, double force, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcAcceleration( force, value ) ); value += massStep; } return data; } } /** * This class provides methods for the Work equation. */ public static class Work { public static final String TYPE = "work"; public static final String VERSION = "1.0"; public static final String TITLE = "Work"; public static final String DESCRIPTION = "These calculators can be used to generate data using force, distance, angle and work."; /** * Public method that calculates work. * You can reference it in your code as "Equations.Work.calcWork( ... )". */ public static double calcWork(double force, double distance, double angle) { // W = Fdcos(A) return force*distance*Math.cos( angle ); } /** * The public method to calculate a list of work values by varying the force. * You can reference it in your code as "Equations.Work.calcWorkVsForce( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the force value for each work value. */ public static List calcWorkVsForce(double forceMin, double forceMax, double forceStep, double distance, double angle, List data, List labels) { double value = forceMin; if( data == null ) { data = new ArrayList(); } while( value <= forceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcWork( value, distance, angle ) ); value += forceStep; } return data; } /** * The public method to calculate a list of work values by varying the distance. * You can reference it in your code as "Equations.Work.calcWorkVsDistance( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the distance value for each work value. */ public static List calcWorkVsDistance(double distanceMin, double distanceMax, double distanceStep, double force, double angle, List data, List labels) { double value = distanceMin; if( data == null ) { data = new ArrayList(); } while( value <= distanceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcWork( force, value, angle ) ); value += distanceStep; } return data; } /** * The public method to calculate a list of work values by varying the angle. * You can reference it in your code as "Equations.Work.calcWorkVsAngle( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the angle value for each work value. */ public static List calcWorkVsAngle(double angleMin, double angleMax, double angleStep, double force, double distance, List data, List labels) { double value = angleMin; if( data == null ) { data = new ArrayList(); } while( value <= angleMax ) { if( labels != null ) { labels.add( value ); } data.add( calcWork( force, distance, value ) ); value += angleStep; } return data; } /** * Public method that calculates force. * You can reference it in your code as "Equations.Work.calcForce( ... )". */ public static double calcForce(double work, double distance, double angle) { // F = W/dcos(A) return work / ( distance * Math.cos( angle ) ); } /** * The public method to calculate a list of force values by varying the work. * You can reference it in your code as "Equations.Work.calcForceVsWork( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the work value for each force value. */ public static List calcForceVsWork(double workMin, double workMax, double workStep, double distance, double angle, List data, List labels) { double value = workMin; if( data == null ) { data = new ArrayList(); } while( value <= workMax ) { if( labels != null ) { labels.add( value ); } data.add( calcForce( value, distance, angle ) ); value += workStep; } return data; } /** * The public method to calculate a list of force values by varying the distance. * You can reference it in your code as "Equations.Work.calcForceVsDistance( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the distance value for each force value. */ public static List calcForceVsDistance(double distanceMin, double distanceMax, double distanceStep, double work, double angle, List data, List labels) { double value = distanceMin; if( data == null ) { data = new ArrayList(); } while( value <= distanceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcForce( work, value, angle ) ); value += distanceStep; } return data; } /** * The public method to calculate a list of force values by varying the angle. * You can reference it in your code as "Equations.Work.calcForceVsAngle( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the angle value for each force value. */ public static List calcForceVsAngle(double angleMin, double angleMax, double angleStep, double work, double distance, List data, List labels) { double value = angleMin; if( data == null ) { data = new ArrayList(); } while( value <= angleMax ) { if( labels != null ) { labels.add( value ); } data.add( calcForce( work, distance, value ) ); value += angleStep; } return data; } /** * Public method that calculates distance. * You can reference it in your code as "Equations.Work.calcDistance( ... )". */ public static double calcDistance(double work, double force, double angle) { // d = W/Fcos(A) return work / ( force*Math.cos( angle ) ); } /** * The public method to calculate a list of distance values by varying the work. * You can reference it in your code as "Equations.Work.calcDistanceVsWork( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the work value for each distance value. */ public static List calcDistanceVsWork(double workMin, double workMax, double workStep, double force, double angle, List data, List labels) { double value = workMin; if( data == null ) { data = new ArrayList(); } while( value <= workMax ) { if( labels != null ) { labels.add( value ); } data.add( calcDistance( value, force, angle ) ); value += workStep; } return data; } /** * The public method to calculate a list of distance values by varying the force. * You can reference it in your code as "Equations.Work.calcDistanceVsForce( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the force value for each distance value. */ public static List calcDistanceVsForce(double forceMin, double forceMax, double forceStep, double work, double angle, List data, List labels) { double value = forceMin; if( data == null ) { data = new ArrayList(); } while( value <= forceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcDistance( work, value, angle ) ); value += forceStep; } return data; } /** * The public method to calculate a list of distance values by varying the angle. * You can reference it in your code as "Equations.Work.calcDistanceVsAngle( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the angle value for each distance value. */ public static List calcDistanceVsAngle(double angleMin, double angleMax, double angleStep, double work, double force, List data, List labels) { double value = angleMin; if( data == null ) { data = new ArrayList(); } while( value <= angleMax ) { if( labels != null ) { labels.add( value ); } data.add( calcDistance( work, force, value ) ); value += angleStep; } return data; } /** * Public method that calculates angle. * You can reference it in your code as "Equations.Work.calcAngle( ... )". */ public static double calcAngle(double work, double force, double distance) { // A = arccos(W/Fd) return Math.arccos( work/( force*distance ) ); } /** * The public method to calculate a list of angle values by varying the work. * You can reference it in your code as "Equations.Work.calcAngleVsWork( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the work value for each angle value. */ public static List calcAngleVsWork(double workMin, double workMax, double workStep, double force, double distance, List data, List labels) { double value = workMin; if( data == null ) { data = new ArrayList(); } while( value <= workMax ) { if( labels != null ) { labels.add( value ); } data.add( calcAngle( value, force, distance ) ); value += workStep; } return data; } /** * The public method to calculate a list of angle values by varying the force. * You can reference it in your code as "Equations.Work.calcAngleVsForce( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the force value for each angle value. */ public static List calcAngleVsForce(double forceMin, double forceMax, double forceStep, double work, double distance, List data, List labels) { double value = forceMin; if( data == null ) { data = new ArrayList(); } while( value <= forceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcAngle( work, value, distance ) ); value += forceStep; } return data; } /** * The public method to calculate a list of angle values by varying the distance. * You can reference it in your code as "Equations.Work.calcAngleVsDistance( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the distance value for each angle value. */ public static List calcAngleVsDistance(double distanceMin, double distanceMax, double distanceStep, double work, double force, List data, List labels) { double value = distanceMin; if( data == null ) { data = new ArrayList(); } while( value <= distanceMax ) { if( labels != null ) { labels.add( value ); } data.add( calcAngle( work, force, value ) ); value += distanceStep; } return data; } } /** * This class provides methods for the Energy equation. */ public static class Energy { public static final String TYPE = "energy"; public static final String VERSION = "1.0"; public static final String TITLE = "Energy"; public static final String DESCRIPTION = "These calculators can be used to generate data using mass, velocity and energy."; /** * Public method that calculates energy. * You can reference it in your code as "Equations.Energy.calcEnergy( ... )". */ public static double calcEnergy(double mass, double velocity) { // e = mv^2 return mass*velocity*velocity; } /** * The public method to calculate a list of energy values by varying the mass. * You can reference it in your code as "Equations.Energy.calcEnergyVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each energy value. */ public static List calcEnergyVsMass(double massMin, double massMax, double massStep, double velocity, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcEnergy( value, velocity ) ); value += massStep; } return data; } /** * The public method to calculate a list of energy values by varying the velocity. * You can reference it in your code as "Equations.Energy.calcEnergyVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each energy value. */ public static List calcEnergyVsVelocity(double velocityMin, double velocityMax, double velocityStep, double mass, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcEnergy( mass, value ) ); value += velocityStep; } return data; } /** * Public method that calculates mass. * You can reference it in your code as "Equations.Energy.calcMass( ... )". */ public static double calcMass(double energy, double velocity) { // m = e/v^2 return energy / (velocity * velocity); } /** * The public method to calculate a list of mass values by varying the energy. * You can reference it in your code as "Equations.Energy.calcMassVsEnergy( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the energy value for each mass value. */ public static List calcMassVsEnergy(double energyMin, double energyMax, double energyStep, double velocity, List data, List labels) { double value = energyMin; if( data == null ) { data = new ArrayList(); } while( value <= energyMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( value, velocity ) ); value += energyStep; } return data; } /** * The public method to calculate a list of mass values by varying the velocity. * You can reference it in your code as "Equations.Energy.calcMassVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each mass value. */ public static List calcMassVsVelocity(double velocityMin, double velocityMax, double velocityStep, double energy, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( energy, value ) ); value += velocityStep; } return data; } /** * Public method that calculates velocity. * You can reference it in your code as "Equations.Energy.calcVelocity( ... )". */ public static double calcVelocity(double mass, double energy) { // v = sqrt(e/m) return Math.sqrt( energy / mass ); } /** * The public method to calculate a list of velocity values by varying the mass. * You can reference it in your code as "Equations.Energy.calcVelocityVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each velocity value. */ public static List calcVelocityVsMass(double massMin, double massMax, double massStep, double energy, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( value, energy ) ); value += massStep; } return data; } /** * The public method to calculate a list of velocity values by varying the energy. * You can reference it in your code as "Equations.Energy.calcVelocityVsEnergy( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the energy value for each velocity value. */ public static List calcVelocityVsEnergy(double energyMin, double energyMax, double energyStep, double mass, List data, List labels) { double value = energyMin; if( data == null ) { data = new ArrayList(); } while( value <= energyMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( mass, value ) ); value += energyStep; } return data; } } /** * This class provides methods for the Kinetic Energy equation. */ public static class KineticEnergy { public static final String TYPE = "kinetic_energy"; public static final String VERSION = "1.0"; public static final String TITLE = "Kinetic Energy"; public static final String DESCRIPTION = "These calculators can be used to generate data using mass, velocity and energy."; /** * Public method that calculates energy. * You can reference it in your code as "Equations.KineticEnergy.calcEnergy( ... )". */ public static double calcEnergy(double mass, double velocity) { // K = mv^2 / 2 return mass*velocity*velocity/2.0; } /** * The public method to calculate a list of energy values by varying the mass. * You can reference it in your code as "Equations.KineticEnergy.calcEnergyVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each energy value. */ public static List calcEnergyVsMass(double massMin, double massMax, double massStep, double velocity, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcEnergy( value, velocity ) ); value += massStep; } return data; } /** * The public method to calculate a list of energy values by varying the velocity. * You can reference it in your code as "Equations.KineticEnergy.calcEnergyVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each energy value. */ public static List calcEnergyVsVelocity(double velocityMin, double velocityMax, double velocityStep, double mass, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcEnergy( mass, value ) ); value += velocityStep; } return data; } /** * Public method that calculates mass. * You can reference it in your code as "Equations.KineticEnergy.calcMass( ... )". */ public static double calcMass(double energy, double velocity) { // m = 2K/v^2 return 2.0 * energy / (velocity * velocity); } /** * The public method to calculate a list of mass values by varying the energy. * You can reference it in your code as "Equations.KineticEnergy.calcMassVsEnergy( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the energy value for each mass value. */ public static List calcMassVsEnergy(double energyMin, double energyMax, double energyStep, double velocity, List data, List labels) { double value = energyMin; if( data == null ) { data = new ArrayList(); } while( value <= energyMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( value, velocity ) ); value += energyStep; } return data; } /** * The public method to calculate a list of mass values by varying the velocity. * You can reference it in your code as "Equations.KineticEnergy.calcMassVsVelocity( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the velocity value for each mass value. */ public static List calcMassVsVelocity(double velocityMin, double velocityMax, double velocityStep, double energy, List data, List labels) { double value = velocityMin; if( data == null ) { data = new ArrayList(); } while( value <= velocityMax ) { if( labels != null ) { labels.add( value ); } data.add( calcMass( energy, value ) ); value += velocityStep; } return data; } /** * Public method that calculates velocity. * You can reference it in your code as "Equations.KineticEnergy.calcVelocity( ... )". */ public static double calcVelocity(double mass, double energy) { // v = sqrt(2K/m) return Math.sqrt( 2.0 * energy / mass ); } /** * The public method to calculate a list of velocity values by varying the mass. * You can reference it in your code as "Equations.KineticEnergy.calcVelocityVsMass( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the mass value for each velocity value. */ public static List calcVelocityVsMass(double massMin, double massMax, double massStep, double energy, List data, List labels) { double value = massMin; if( data == null ) { data = new ArrayList(); } while( value <= massMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( value, energy ) ); value += massStep; } return data; } /** * The public method to calculate a list of velocity values by varying the energy. * You can reference it in your code as "Equations.KineticEnergy.calcVelocityVsEnergy( ... )". * The data parameter can be null and a new list will be created and returned. * The labels parameter can be null. If supplied, it will be populated with * the energy value for each velocity value. */ public static List calcVelocityVsEnergy(double energyMin, double energyMax, double energyStep, double mass, List data, List labels) { double value = energyMin; if( data == null ) { data = new ArrayList(); } while( value <= energyMax ) { if( labels != null ) { labels.add( value ); } data.add( calcVelocity( mass, value ) ); value += energyStep; } return data; } } }