/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH, 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. Support by National Science Foundation */ // ProjectileAir.java: Calculate projectile motion import ptolemy.plot.*; public class ProjectileAir { // Static class variables, accessible to all methods (constants) static final double v0 = 22., angle = 34., g = 9.8, kf=0.8; static final int N = 25; public static void main(String[] args) { double v0x,v0y, T, H, R; // Initial constants v0x = v0 * Math.cos(angle*Math.PI/180.); v0y = v0 * Math.sin(angle*Math.PI/180.); T = 2 * v0y / g; H = v0y * v0y / (2 * g); R = 2 * v0x * v0y / g; System.out.println("Frictionless T,H,R = " +T+ ", " +H+ ", " +R); // Create Plot object (from ptplot) Plot myPlot = new Plot(); myPlot.setTitle("Projectile without/with Air Resistance"); myPlot.setXLabel("x"); myPlot.setYLabel("y)"); myPlot.setXRange(-R/20, R); plotAnalytic (myPlot, 0); // Plot, no friction, analytic plotNumeric (myPlot, 2, kf); // Plot, friction, numeric // PlotApplication display Plot object PlotApplication app = new PlotApplication(myPlot); } // end main public static void plotNumeric (Plot myPlot, int set, double k) { // Plot, friction, numeric double x, y, vx, vy, dt; vx = v0 * Math.cos(angle*Math.PI/180.); vy = v0 * Math.sin(angle*Math.PI/180.); x = 0; y = 0; dt = 2 * vy / g /N; for (int i = 0; i