Transcribed TextTranscribed Text

1. Write MATLAB script that animates two different color points (i=1,2), each starting at a user-defined and each moves incrementally in a different direction [0xi, byil The Start and increment should be assigned at the beginning of the code. The animation should last for 0 < ( < 4g, where the final time 4 and a time increment de are also assigned at the beginning of the code. To animate the point at time 2 + de, i=1,2 where Xdir¿ and Ydir¿ are values (either -1 or +1) that specify the current direction of the point. Keep the points within -2 < x 2 and -1 < y <1, appearing as if they bounce off the border. That is, change its direction component normal to the border. Additionally, the balls should bounce off each other if they collide. That is, exchange their directions. Include an goal at an original position from [1.50,-0.25] to [1.50,0.25]. Then oscillate the position of the goal with amplitude a. The animated points should bounce off the obstruction similarly to the border. Lastly, include a timer and score board for each point that tracks each time a point hits the front of the obstruction. Time: 3.54 Score. c Seare. 0 For an initial run, use 4 = 20 sec, at = 0.02 sec, a = 0.25, x1(0) =-0.5,y1(0) = -0.25, Ox, = 0.08, ay, = 0.02, x2(0) = 0.5,y2(0) = -0.5, x2 = 0.05, Jy2 = -0.05.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function balls()

% Set the parameters of the system being simulated. We use global
% variables on parameters that need to be plotted by this function and used
% by other functions for computing the motion.
% Positions are given in meters, and velocities are given in meters per
% second. The first element is the x-component, and the second is the
% y-component. This convention is used throughout the code.

tfinal = input(' Simulation ending time, in seconds (say 100): ');
tstepmaxode = input(' Maximum time step that ode45 is allowed to take, in seconds. (0.02) : ');
bluex = input(' Initial x coordinate blue ball : ');
bluey = input(' Initial y coordinate blue ball : ');
bluevx= input(' Initial x velocity coordinate blue ball : ');
bluevy= input(' Initial y velocity coordinate blue ball : ');
redx = input(' Initial x coordinate red ball : ');
redy = input(' Initial y coordinate red ball : ');
redvx= input(' Initial x velocity coordinate red ball : ');
redvy= input(' Initial y velocity coordinate red ball : ');
% Set the locations for the walls; these are global.
global leftWallX rightWallX lowerWallY upperWallY goalX goalY_low goalY_hi goal_amp
leftWallX = -2.0; % Horizontal position of the left wall of the table.
rightWallX = 2.0; % Horizontal position of the right wall of the table.
lowerWallY = -1.0; % Vertical position of the lower wall of the table.
upperWallY = 1.0; % Vertical position of the upper wall of the table.
goalX = 1.5;

ballDensity = 1000;      % Ball density, in kilograms per meter cubed.

% blue BALL
% The blue ball is modeled as a circular particle with a fixed mass;
% radius is global.
global blueBallRadius
blueBallWallE = 1.;   % blue ball coefficient of restitution with the walls, unitless.
blueBallRadius = 0.10; % blue ball radius, in meters.
blueBallMass = ballDensity*0.01*pi*blueBallRadius^2;    % blue ball mass, in kilograms.
blueBallInitialPosition = [bluex, bluey]; % Initial blue ball position, in meters.
blueBallInitialVelocity = [bluevx, bluevy]; % Initial blue ball velocity, in meters per second....
$33.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available MATLAB for Mathematics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats