balle program to compute the trajectory of a projectile in

%balle - program to compute the trajectory of a projectile in the pre

%presence of air resistance.The drag force is given by:

% F_drag = 0.5*Cd*density of medium* Area* norm(velocity)* velocity/mass

% using the Euler method.

clear

(help balle)

r=[0,0] %input(\'Enter initial position r=[x,y] \'); %(meters)

v=[30,30] %input(\'Enter initial velocity v=[vx,vy] \'); %(meters/second)

dt=0.1 %input(\'Enter time step dt \'); %(second)

cd=0.35; %drag coef (dimensionless)

rho=1.2; %density of air (kg/m^3)

area=4.3e-3; %cross-sectional area of projectile (m^2)

grav=9.81; % gravitational acceleration (m/s^2)

mass=0.145;%Mass of projectile (kg)

air_const=0 %-0.5*cd*rho*area/mass; % air resistance const

n=100; %maximum steps

% Main Loop %

for i = 1:n

xp(i)=r(1); %record trajectory for plot

yp(i)=r(2);

accel=air_const*norm(v)*v; %air resistance

accel(2)=accel(2)-grav; %gravity

r = r + dt*v; %Euler step

v = v + dt*accel;

if (r(2) < 0) %Break out of loop when ball hits ground

break;

   end

end

xp(i+1)= r(1);

yp(i+1)=r(2);

fprintf(\'Maximum range is %g meters\ \',r(1))

fprintf(\'Time of flight is %g seconds\ \', i*dt)

%Mark the location of the ground by a staight line

xground = [0 xp(i+1)];

yground = [0 0];

%Graph trajectory of the base ball

plot(xp, yp,\'+\',xground,yground,\'-\');

xlabel(\'Range (m)\')

ylabel(\'Height (m)\')

title(\'Projectile motio

THIS IS THE CODE

7· The drag coefficient is really not a constant but rather varies with velocity. Modify alle to use the values e (mph)050 75 00 25 Ca 0.5 0.5 0.4 0.28 0.23 using quadratic interpolation to estimate Cv). Test your program for a variety of initial conditions and comment on the results. Does the range increase or decrease as compared to using a constant Ca?

Solution

import java.awt.*;
import java.applet.*;

public category Tank extends applications programme
purpose target;
   public int x, y, w, h;
   public int maxX=400,maxY=360,minX=0,minY=0;
   public int maxFire;   // the utmost quantity of shots allowed for the tank to fireside promptly
   public int gamma hydroxybutyrateShells;   // The max range of shells allowed to be pink-slipped
   public Boolean isMoving, isAlive, exploded;
   Graphics g;

   Tank()

   public Tank(int xpos, int ypos, Color c, int speed, int newDirection, int maxFire)

   public void move() else break;
       case EAST:   if( (x+tankWidth()+moveBy)&gt;maxX) else break;
case SOUTH: if( (y+tankHeight()+moveBy)&gt;maxY ) else break;
case WEST: if( (x-moveBy&lt;minX) ) else break;
}
   }

   public void turn(int newDirection)

   public void turnAround()

   void explode()

   public void paint(Graphics gr)

       //polygon canon wheels
       int x11[] = ;
       int y11[] = ;

       int x12[] = ;
       int y12[] = ;

       int x13[] = x11;
       int y13[] = ;

       int x14[] = ;
       int y14[] = y12;

       int x1[][] = ;
       int y1[][] = ;

       //roundrect canon compartment
       int x2[] = ;
       int y2[] = ;

       //rect canon case
       int x3[] = ;
       int y3[] = ;
       int x3w[] = ;
       int y3h[] = ;

       //oval canon cap
       int x4[] = ;
       int y4[] = ;

       //canon
       int x5[] = ;
       int y5[] = ;
       int x5w[] = ;
       int y5h[] = ;

       int d = direction - 1;

       //draw wheels
       g.setColor(Color.black);
       g.fillPolygon(x1[d], y1[d] ,8);

       //draw compartment
       g.setColor(color);
       g.fillRoundRect(x2[d],y2[d],25,25,5,5);

       //draw canon
       g.setColor(Color.black);
       g.fillRect(x5[d],y5[d],x5w[d],y5h[d]);


       //draw canon case
       g.setColor(new Color(47,79,79));
       g.fillRect(x3[d],y3[d],x3w[d],y3h[d]);

       //draw canon cap      
       g.setColor(Color.black);
       g.fillOval(x4[d],y4[d],15,15);

   }

   int tankWidth()direction==3)return 35;
       else {return 40;
   }

   int tankHeight()come 35;
   }

}

%balle - program to compute the trajectory of a projectile in the pre %presence of air resistance.The drag force is given by: % F_drag = 0.5*Cd*density of mediu
%balle - program to compute the trajectory of a projectile in the pre %presence of air resistance.The drag force is given by: % F_drag = 0.5*Cd*density of mediu
%balle - program to compute the trajectory of a projectile in the pre %presence of air resistance.The drag force is given by: % F_drag = 0.5*Cd*density of mediu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site