You will have to create an animation of a square according to the directions bel
ID: 3556764 • Letter: Y
Question
You will have to create an animation of a square according to the directions below. Create a square with a side length of 4 centered on the origin. Translate this square along the parabola y=(1/4)*x^2 on the interval [0, 20]. Use the variables t and trajectory for your independent ( x ) and dependent ( y ) values, respectively. ( Hint: the first location of the square is (0,0) and the final point is (20, 100). ) Your square should scale linearly from 100% to 25% of its original size. ( Hint: in the first frame, your square will have sides of 4, and in the final frame, your square will have sides of 1. ) Your animation should have 500 frames. Use the variable square to represent the x and y coordinates of the square. The x coordinates and y coordinates should be represented in the first and second rows of square , respectively.
Explanation / Answer
% do not modify the function line below
function v = problem1
% coordinates of square under one variable
square = [-2 -2 2 2;-2 2 2 -2 ];
% generate animation window
figure
xmin = -5;
xmax = 25;
ymin = -5;
ymax = 125;
axis equal
axis([xmin xmax ymin ymax])
hold on
%setting your trajectory
t =linspace(0,20,500) ; % independent variable of your function
trajectory = 1/4*t.^2; % represents y in y = t^2
% all fill/drawing steps should occur in for loop
for i = 1:500
% fill in the appropriate inputs for fill
n=linspace(1,0.25,500);
h = fill(square(1,:)*n(i)+t(i),square(2,:)*n(i)+trajectory(i) ,'r');
% do not change below 2 lines, should follow your fill command
v.x(i,:)=get(h,'xdata')';
v.y(i,:)=get(h,'ydata')';
% add anything below
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.