Project 1: >> g=9.81; v0=100; theta1=pi/4; tmax=(2*v0*sin(theta1))/g; t=0:0.1:tmax; x1=t.*v0.*cos(theta1); y1=(t.*v0.*si

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Project 1: >> g=9.81; v0=100; theta1=pi/4; tmax=(2*v0*sin(theta1))/g; t=0:0.1:tmax; x1=t.*v0.*cos(theta1); y1=(t.*v0.*si

Post by answerhappygod »

Project 1:
>> g=9.81;
v0=100;
theta1=pi/4;
tmax=(2*v0*sin(theta1))/g;
t=0:0.1:tmax;
x1=t.*v0.*cos(theta1);
y1=(t.*v0.*sin(theta1))-(0.5.*g.*t.^2);
figure
plot(t,x1)
title('Horizontal Distance vs. Time')
xlabel('Time (sec)')
ylabel('Horizontal Distance (m)')
figure
plot(t,y1)
title('Vertical Distance vs. Time')
xlabel('Time (sec)')
ylabel('Vertical Distance (m)')
figure
comet(x1,y1)
title('Horizontal Distance vs. Vertical Distance')
xlabel('Horizontal Distance')
ylabel('Vertical Distance')
%-----------------------------------
g=9.81;
v0=100;
theta2=pi/2;
tmax=(2*v0*sin(theta2))/g;
t=0:0.1:tmax;
x2=t.*v0.*cos(theta2);
y2=(t.*v0.*sin(theta2))-(0.5.*g.*t.^2);
theta3=pi/6;
tmax=(2*v0*sin(theta3))/g;
t=0:0.1:tmax;
x3=t.*v0.*cos(theta3);
y3=(t.*v0.*sin(theta3))-(0.5.*g.*t.^2);
figure
plot(x1,y1)
hold on
plot(x2,y2,'--')
plot(x3,y3,':')
title('Horizontal Distance vs. Vetical Distance')
xlabel('Horizontal Distance (m)')
ylabel('Vertical Distance')
legend('Pi/4','Pi/2','Pi/6')
A=[15 3 -7 3 0;
0 4 -4 -6 7;
2 5 -2 5 -8;
6 -3 -5 0 2;
-5 -6 0 17 12];
X=[x(1); x(2); x(3); x(4); x(5)];
R=[4 27 -6 5 -2];
X1=A.*R.^-1;
Check=A*X;
Project 2:
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 1
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 1 (66.1 KiB) Viewed 54 times
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 2
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 2 (59.57 KiB) Viewed 54 times
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 3
Project 1 G 9 81 V0 100 Theta1 Pi 4 Tmax 2 V0 Sin Theta1 G T 0 0 1 Tmax X1 T V0 Cos Theta1 Y1 T V0 Si 3 (55.75 KiB) Viewed 54 times
Project 2 is a continuation of Project 1, code for Project
1 is given. Please complete all 4 parts of Project 2 in
MATLAB. Thanks!!
The question is listed as computer science, but it's a
MATLAB project.
ECIV 202 MATLAB Project 2 Due: See D2L Assignments Tab This homework builds off of Project 1, so make sure you have everything working from that project. For all plots, make sure you label your axis and provide a title, a plot without labels is useless. 1. Create a function called projectile Motion that takes as arguments initial velocity (vo), and initial angle (theta) and then plots the vertical distance (vertical) versus the horizontal distance (horizontal), labels the plot, and then returns the horizontal and vertical distances and time (1), as shown in Equation 1. [horizontal, vertical, 1 = projectile Motion(vo, theta) (1) Also, include in your code a line that prints the maximum height on the plot using the MATLAB commands max(). text(), and num2str(), as seen in Figure 1 below. Use MATLAB's help to look up how to use these functions. Note: function has 3 outputs. Function Name Note: function has 2 inputs function (horizontal, vertical. t) projectileno con vo. theta) wint: The first 4 steps are essentially the same process we went through in part 1 but now incorporated into a function. This function should use the 4 inputs to: * 1) Calculate a tmax * 2) Create a t - 0:0.01: tmax vector * 3) create a horizontal and vertical vector (these are the same as the x and y en in part 1) * 4) plot vertical (on y axis) vs horizontal (on x axis). ??????? *Steps 1-4 here * 5) This is the new part. At the top of the arc in your plot, you want Matlab to display the exact value of the maximum height the projectile reaches (see Figure 1 below). The max() function returns a single value (a number) that is the maximum value in a vector or matrix. To print this number on the plot you will need to convert a value to a label (matlab calls labels strings). To do this use nunstro. Finally, you can use the text() function to print this label/string on your plot. 27272727 muse maxO to find maximum number in the vertical vector 27777777 xuse nun str to convert the maximum value to a label/string 77777777 Xuse text to print the max height Tabel to the plot. end 4500 Vertical Distance Horostre 4000 No Height: 4077 7500 3000 2500 Mag 2294 2000 vorca 1500 1000 -MHg 1019mbers 500 Ater Height: 251 2000 4000 00030000 10000 12000 14000 18000 18000 Hortance Figure 1. Your final plot should look like this. Don't forget the height label at the top of each arc, 2. Now create a script that uses a for loop and the function defined above to plot the projectile motion for the initial velocities of [100, 200, 300, 400) ms and 8. =TA. When finished, your figure should look like Figure 1.

X Hint: This is a script (not a function): save this file as projectilemotionTest. To perform step 2 WITHOUT a 1oop. you would simply call the * projectile notion 4 times, providing the input arguments specified. For example, try typing in the following lines and running your script: Chorizontal, vertical, t] - projectileMotion ( 100, pi/4): (horizontal, vertical, t) - projectileMotion( 200, pi/4); Chorizontal, vertical, t) - projectileMotion 300. pi/4): (horizontal, vertical, t] - projectilemotion ( 400, pi/4): * Ok, now your goal is to do this same process as a loop (delete the stuff above and let't try it as a loop). * You'll need to define a launch angle (scalar value), vector of velocity values, and a vector of line types. theta - pi/4: The given launch angle. V - [?????) vector of your 4 launch velocities. Xasic loop syntax: for 1 - 1:4 says loop through me four times. A better solution would be 1 - 1:length(x). Why? ?????? call your projectilemotion function and pass in V and it. If I typed VC1) what value would I Xget? What if I typed lt{3}? end 3. Create another user-defined function called derivative that when given two vectors (x and f(x)) it returns the derivative of the function Rx) as shown in Equation 2. (dfx] = derivative (x,x) (2) Recall from our Excel derivative HW (it might be helpful to look back at it) that the derivative of a function can be approximated by (3-1)-f(xi) where i = 0, 1, 2, ... (n-1) (3) (*+1x That is, the approximate derivative is simply the change in fx divided by the change in x where, since it is approximate, we don't need to use the limit. We simply need to make our change in x reasonably small. What does this mean for our Matlab code? It means we need to incorporate equation 3 into a loop that performs the following operation: dfx(1) 2-fr) (4) X(2)-(1) x(3)-x2) dfx(2) *(3)-(2) dfx(3) = X(4-11) *(4)-(3) 1 continue to length of fx-1 Keep in mind that your numeric derivative (Af(x)/Ax) will have one less element in it than your original x, so when plotting you might use a command similar to the following: plotx(1 :end - 1), dfx). This uses a handy little trick in MATLAB that enables you to index the last element in a list or matrix by just indexing end. The plot command above indexes the end of the list minus one, or all but the last element in the list; therefore, if you go to plot the dtx versus x, they will have the same number of elements and you will not get an error. Recall that the length command in MATLAB provides the number of elements in a vector.

function (dfx] - derivative( x, fx ) shint: If you were doing this by hand, how would you get the derivative of fx at the point where x = 1? You would probably do something like: dfx(1) - (fx(2)-fx(1))/(x(2)-x(1)): Dow about at x - 27 And so on? dfx(2) - (fx(3) - fx(2)/(x(3)-x(2)): dfx(3) - (fx(9)-fx(3))/(x(4)-(3)): dfx(4) = (fx(5)-fx(4))/(x(5)-(49): * I see a pattern. Now all you need to do is incorporate this into a forloop that loops through 1-1: length(x)-1 times end 4. Using the functions created in Problems 1 and 3 above, plot the vertical distance, vertical velocity, and vertical acceleration as functions of time. For this problem, use @ = pi and V = 400 m's Comment within your code on whether or not this plot makes sense (0.9. do the velocities seem reasonable, what about accelerations) Hint: This code can be added to the bottom of the script you created above. Notice that that projectileMotion function you created earlier Xreturns t and vertical(t). That is, it returns two vectors of the sane length just like the two columns Your Excel derivítive homework-go look at it). These vectors can be passed to your derivitive function, which will perform the same steps as your excel Hadid. It will output a vector (dfx) that is one value shorter in length than fx (this is easy to see in the Excel Hw-go look). *1) First run your projectilenotion function with the input arguments theta - pi/4 and vo = 400. 7777777 2) Use the t and vertical outputs fron step 1 as inputs to your derivitive function. The output from this Kopperatio will be a velocity vector (that is the derivitive of position with respect to time is velocity) ???????? x3) Now passt and dfx into your derivitive function. The output will be ddfx (change in velocity with respect xto tine), aka acceleration. ???????? *A) Plot fx, dfx, ddfx (aka position, velocity, and acceleration) all on the same plot (don't worry about a y Kaxil label). 77777777 Your finished plot should look like: 4500 Position. Velocity and Acceleration in Vertical Direction Vert. Position Vert Velocity Vert Acceleration 1000 3500 3100 2500 Eppp 2000 1500 1000 500 0 -500 10 20 40 50 60 30 time (5) Figure 2: Your finished derivative plot should look like this. Don't forget the legend:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply