QuestionQuestion

Objective
Your task for this par of the homework is to complete a MATLAB simulation of a puck sliding on a flat surface and int­eracting with five different zones: wind, sun, water1 mud, and wall. The code for the graphics and the surrounding simulation have been written for you so that you can focus on the dynamics. The attached plot shows he starting configuration for the sys em you are simulating.

The puck can be modeled as a particle, and it is drawn on the graph as a small black circle. It has a mass of PuckMass, measured in kilograms.

The puck lives in a flat planar world that extends forever in all directions and has no gravity. The graph shows you a top view of the part of the world where everything interesting will happen. This viewing rectangle starts at the origin (0 m, 0 m) and extends 2 meters in the positive horizontal direction and 1 meter in the positive vertical direction. You will not need to change this.

You set the puck’s initial position and velocity at the top of the given simulation code via the variables x0, y0, vx0, and vy0. It should start somewhere at the left side of the world, moving to the right, possibly with some vertical velocity as well. In this simulation, all positions are in meters, and all velocities are in meters per second.

The world contains a wind zone, which is drawn as an gray-colored vertical strip in the graph. Thewind zone extends from WindStartX to WindEndX. When the puck is in the wind zone, it should experience a vertical force of WindStrength, measured in newtons, with positive up. The arrows in the wind zone show you the current wind direction. The wind zone disappears when its strength is set to zero, as do all the other zones. You may modify the strength of each zone as you wish.

The sun zone is drawn as a gold circle on the graph. The sun is centered at (SunCenterX, SunCenterY), and it has a radius of SunR. When the puck is in the sun zone, it should experience a constant forward force of SunStrength, which speeds it up but does not change its direction.

The water zone is drawn as a light blue circle on the graph. The water is centered at (WaterCenterX, WaterCenterY), and it has a radius of WaterR. When the puck is in the water zone, it should maintain its speed but feel a constant force to its right of WaterStrength. For example, this means that the force should be in the negative y direction if the puck is moving purely in the positive x direction.

The mud zone is drawn as a brown rectangle on the graph. The mud extends from MudStartX to MudEndX and from MudStartyY to MudEndY. When in the mud, the puck should experience a drag force that has a magnitude equal to the product of the puck’s current speed and MudStrength, which is measured in newton-seconds per meter. The mud should slow the puck down but not make it turn.

The wall zone at the far right side of the puck’s world is drawn as a magenta region on the graph. This springy wall extends forever in the y direction, so its location can be defined by only WallStartX. This wall acts like a frictionless one-sided linear elastic spring. It pushes the puck to the left with a force proportional to the puck’s penetration distance; it does not apply any forces to the puck tangential to its surface. Use WallStrength as the stiffness of the wall’s spring in newtons per meter.

When the puck is not in any of the interaction zones (wind, sun, water, mud, or wall), it should not feel any forces, i.e., it should continue straight without speeding up, slowing down, or turning.

Task List
As mentioned above, the graphics and the simulation engine have already been programmed for you so that you can focus on the dynamics. Your tasks are:

1. For each of the zones described above, draw a diagram and write out the force equations (Fx = ..., Fy = ...) that define the zone’s effect on the puck. Also briefly describe and draw a top view of the way in which you expect the puck to move when it enters each zone. This step should be done on paper before you sit down to program anything.

9. Look at your - compute puck derivatives function. Your task is to calculate the first time derivative of each of the puck’s states given the current time t and the current puck state vector X. As noted in the code, the state vector is defined to be X = [x ; y ; vx ; vy], and you need to put the derivatives of these states in the output variable Xdot. Note that you should not program integration over time; you should just calculate the derivatives and let ode45 do the integration.

10. Fill in the Matlab compute puck derivatives function to implement the dynamic relationships for all of the zones. Do this zone by zone, rather than all at once. You should consider using if statements to determine which zone the puck is in. Include comments to explain what your code is doing. Remember to factor in the effect of the puck’s mass.

11. Test your code by running the simulation script, which uses ode45 to call the derivative computation function you are writing. Change around the initial conditions and test each part of the environment separately to ensure it behaves as it should. If you cannot get a certain zone to work correctly, turn it off by setting its strength to zero.

12. Find a set of initial conditions and simulation duration that cause the puck to pass through all of the active zones before coming to rest in the mud. If you cannot get the mud to work, then just make the puck go through all available zones.

Explanation of Global Variables Notice that all of the environment parameters, such as WindStrength and MudEndX, are defined as global variables and set to their chosen values at the top of the simulation code. (You can change around the environment somewhat if you want, but you should not make the zones overlap.)
The compute derivatives code declares these variables as global too, which enables it to access these values even though it is a separate function. The code is set up like this so that changing the configuration of the environment, such as moving the sun, will automatically propagate to both the graphics and the dynamics.
Thus, your compute derivatives function should not have any magic numbers in it — only references to the puck’s current state and all of the global environment parameters.

Simulation and Animation Details Running simulate_puck. starter .m will do the simulation and then plot an animation of the resulting motion in figure 1. You can speed up or slow down this animation by changing the graphical_tstep variable in the simulation code. If you don’t want to see the animation, set pause off. Similarly, you can change the starting and ending time of the simulation by modifying tstart and tfinal. If the simulation or the plotting is taking an excessively long time, click in the command window and press control-c. This will halt your code so that you can go fix your bug or speed up the plotting process. When your code executes successfully, it will also print the puck’s final position and velocity on the command line for you to see. You should look at how all of this additional functionality was programmed, but you are not expected to fully understand it, and you should not need to change it to complete this assignment.

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.

% INITIAL CONDITIONS
% Set initial conditions for the puck.
x0 = 0.15; % Initial horizontal position of the puck, in meters.
y0 = 0.10; % Initial vertical position of the puck, in meters.
vx0 = 0.2; % Initial horizontal velocity of the puck, in m/s.
vy0 = 0.0; % Initial vertical velocity of the puck, in m/s

% Put initial conditions together into a column vector.
X0 = [x0; y0; vx0; vy0];

%% DEFINE PUCK AND ENVIRONMENT

% Set the parameters of the puck and the environment as global variables,
% so that this function can plot them and the state_eq function can access
% them for computing the motion. Whenever you refer to any of these values,
% you should use the variable names, not the hard-coded numbers, so that
% changing them here changes them everywhere.

% PUCK
% The puck is modeled as a particle with a fixed mass.
global PuckMass;
PuckMass = 0.155;    % Puck mass, in kilograms.

% WIND
% The wind is a vertical stripe that always pushes the puck in the
% vertical direction.
global WindStartX WindEndX WindStrength;
WindStartX = 0.3;    % Horizontal position of the start of the wind zone, in meters.
WindEndX = 0.5;      % Horizontal position of the end of the wind zone, in meters.
WindStrength = 0.02; % Vertical strength of the wind, in newtons.

% SUN
% The sun is a circular zone that applies thrust to the puck.
global SunCenterX SunCenterY SunR SunStrength;
SunCenterX = 0.75; % Horizontal position of the sun's center, in meters.
SunCenterY = 0.4;   % Vertical position of the sun's center, in meters.
SunR = 0.15;       % Radius of the sun, in meters.
SunStrength = 0.03; % Strength of the sun, in newtons.

% WATER
% The water is a circular zone that makes the puck turn to the right.
global WaterCenterX WaterCenterY WaterR WaterStrength;
WaterCenterX = 1.2;   % Horizontal position of the water's center, in meters.
WaterCenterY = 0.7;   % Vertical position of the water's center, in meters.
WaterR = 0.2;         % Radius of the water, in meters.
WaterStrength = 0.05; % Strength of the water, in newtons....
$30.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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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