More Features of Matlab Ver. 6: 1. Suppose: Y (X) X + 2E - 3 Plot This Function, Find The Roots and Find The Minimum
More Features of Matlab Ver. 6: 1. Suppose: Y (X) X + 2E - 3 Plot This Function, Find The Roots and Find The Minimum
Engr 10
In this assignment you will experiment with MatLab to solve engineering problems.
%Define the function y(x) above by defining a function first. To do this you
must create an M-file:
Doing this defines what y is and gives it the function name of f(x)
1
Now type the following into the command window:
>> x = [0:0.01:1];
>> f(x);
>> plot(x,f(x))
function y = f2(x)
y = x + 2*exp(-x) – 3
Save this file as f2.m
2
Note that f2(x) has two roots (has two zero crossings) and has a minimum
between x=0 and x=1.
x=
0.6931
ans =
-1.3069
fval =
0
Note that this command only found the first zero-crossing. To find the other:
>> [x,fval] = fzero('f2', 3) %Use the plot to find the “ball park” value 3
x=
2.8887
fval =
0
>> x=[-1:.1:5];
>> f2(x);
3
2. Solving for Simultaneous Equations:
6x + 12y + 4z = 70
7x – 2y + 3z = 5
2x + 8y – 9z = 64
Note that:
Matrix * Vector1
6 12 4 x
7 -2 3 y
2 8 -9 z
= Vector2
70
5
64
>> SOLN = A\B this is B/A – note the direction of the slash
SOLN =
3
5
-2
3. Plotting in 3-D:
4
Recall the following problem from the last lab:
You are to build a fence enclosure. The Area of the enclosure is 1600 ft2. The
cost for the fence is $40/foot for the curved section and $30/foot for the
straight section.
L
R
2R
We will now plot cost vs. L and R, and then hone in on the right answer:
>> R = [10:1:30];
>> L = 800./R - 0.25*pi.*R;
>> c1 = (2*R + 2*L)*30;
>> c2 = 40*pi*R;
>> cost = c1+c2;
>> plot3(R, L, cost),grid, xlabel('R'), ylabel('L'), zlabel('Cost')
5
ans =
19
Note the steps from the previous lab. Are your results now different than what you
found for R and L in the previous lab?
An amusement park ride called the “Corkscrew” has a helical shape. The
following equations govern the rides motion in 3-dimensions:
X = a cos(t)
Y = a sin(t)
Z = bt
Where a is the radius of the corkscrew, and b is the tightness of the path. Use
a = 1 with t = [0: 10*pi]
Try:
b = 0.1, 0.2, and -0.1
>> a=1;
>> t = [0: pi/50 :10*pi];
>> b = 0.1;
>> x = a*cos(t);
>> y = a*sin(t);
>> z = b*t;
>> plot3(x, y, z), grid, xlabel('x'), ylabel('y'), zlabel('z')
6
5. Analysis of the Drag Force and Terminal Speed
D = ½ C A v2
Often drag forces are considered bad because the drag forces slow objects
down, e.g. skiers, swimmers, cars, airplanes, cyclists. However sometimes we
want to take advantage of drag, e.g. sky divers use a parachute to reverse the
downward forces to slow them down in order to safely land. Divers use a
swimming pool to counteract their acceleration to earth.
In the final project, your team must think about how to use drag to increase
the time it takes your object to fall.
a. Weigh your cup to get the downward force acting on the cup
b. Estimate the weight of the object holding the cup
c. Estimate the cross sectional area for the cup and holder
d. Find at what velocity does Drag = weight (this is terminal velocity)
e. Calculate the fall time assuming there is Drag
f. How does this compare with what you calculated in last class when
no air resistance was considered?
g. How can you design for more drag on the cup, or how can you
lower the terminal velocity?
7
(When Drag = Weight, the object no longer accelerates towards the
earth, and a terminal velocity is reached. Use C = 0.6
If the objects weighs about 10 Newtons (2.2 lbs.) , and the Area is about 2
feet wide, the terminal speed should be around 9.8 m/s
>> C = 0.6
>> rho = 1.2
>> wt = 10 %newtons
>> r = [8:1:24]
>> r = r.*0.0254
>> A = pi*r.^2
>> vterm = sqrt((2*wt)./(C*rho.*A))
>> t1 = vterm./9.8
>> x1 = 0.5*9.8*t1.^2
>> t2 = (38/3.28 - x1)./vterm
>> tot = t1+t2
>> plot(r,tot), grid, xlabel('radius'), ylabel('time to fall')