0 ratings0% found this document useful (0 votes) 38 views11 pagesAsigniment 1 (Matlab)
this is the matlab code for the python solution
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Lab Session 1
Assignment 1
Problem: Write a Matlab program for the following problem: Use graphical method to
determine the approximate mass of the bungee jumper to have a velocity of 40 m/s after 3sec of
free fall taking a drag coefficient of 0.25 kg/m. ( The acceleration of gravity is 9.81 m/s*2. )
Title: Approximate Mass and Graphical Method
Objective: obtaining the estimate of the root of the equation f(x)=0 by using a plot of the
function and observe where it crosses the x-axis
Tools: MATLAB
Theo
Newton's Second Law of Motion to calculate the range of possible masses (mp) for a bungee
jumper (given a final velocity of v, time for free fall t, and drag coefficient cd) based on the
differential equation for the free fall under drag. The example plots the difference in final velocity
the bungee jumper might receive compared to the given final velocity, as a function of the
Possible masses mp.
To obtain the estimate of the root of the equation f(x)=0 by using a plot of the function and
observing where it crosses the x-axis.
© To obtain mass in terms of velocity (v), time of free fall (t), drag coefficient (cd), and
acceleration of gravity (g)
F(m)= Venvic * tanh((Vg.c/m)*t) — v(t}
Procedure:
1.Define constants for the final velocity (v), time of free fall (t), drag coefficient (cd), and
acceleration of gravity (g).
2.Create an array of possible masses (mp).
3.Create a function to calculate the difference between the final velocity and velocity that would
be reached by a bungee jumper of a given mass (fp).
4,Plot a graph of the mass of the person (mp) against the difference in velocities (fp).
5.Find the mass of the person that produces no difference in velocities. This is the optimal
mass.Trial (1) - estimated the value of mass to be between 50 and 200 kgs.
MATLAB code:
5 8|o # aas|B 2 | > OB
Nee open srw [cre SP ~ | acme eg Bo] min tinemcAoons | gee
| leaner section 1) Run Ena ]
SWS [Sr wos
Br tne
B| 2 ¥ = 0; % Final velocity in w/s
BI) = siete Sa
E| 5 = 9.1; X acceleration of gravity in m/s2
By S| ste» coy of pntba meee
2 | Srthscrece
3
x Function to calculate difference between finel velocity and velocity that would be rea
fo = sartlermo/ed).*tanh(sart(ered./mp)"®) ~ vi
WORKSPACE
2 plotenp.fp)-enid
“115
12
125
13
435
14
4145,
50 700 150 200Trial(2) - estimated the value of mass to be between 50 and 200 kgs.
MATLAB code:
EOTOR fa LE VERSIONS E
Fada? 2 gee ta |» oo
Qma ~ 18 Run and Advance
few Open sive | Goto eacor | Aun fun Step Se
Se Rasen | Minened -
BB o> marae pve
ig |! Assoomenttm = +
Bra |” x constants
3) 2 wo; % final velocity in 1/s
| 3 2) % tine of Free fall in seconds
al ¢ = 6.25; % drag coefficient in ke/e
Bl 5 | g-9.81; x acceleration of gravity in m/s?
3) 6
E) 7 | create » range of possible masses
Yl) 2 ap = Linspace (200,508);
£| 9
©) 20 G]_ x runction to coleuate difference between Final velocity
B) ix Tx locity thot wld be reached by 9 bmgce jomper of given mss
22 f= Santetep/ed) *tann(sart(ared./m)"t) — vs
23
34 ploténp, fp) eri
‘Output:
10.9
1
44
“11.2
“11.3
“11.4
“11.5
“116
AN,
200. 250 «300 350 400 450 500Trial(3) - estimated the value of mass to be between S00 and 1000 kgs.
MATLAB code:
= es
Fea. |B ass 2 acc.| & >
~ + ~ + BA Bookman + + = section tf) Run to Ene ~
ES [ao 1 > MATLAB Ove —
“Assianmenttim =
1 % Constants
2 10} % Final velocity in m/=
3 5° tine of Free fall in seconds
4 ed = 0.25; % drag coefficient in ke/m
7
@ - 9.81; % acceleration of gravity in m/=*2
(CURRENT FOLDER
% Create o range of possible masses
nip = Linspace (509,1008) ;
& Function to coleulate difference between final velocity and
velocity that would be reached by 2 bungee jumper of a given mass
12 ¥o = sart (ermp/ed).*tanh(sart(etcd./mp)*t) = vz
[woRKSPACE:
fl
u“ plot (ap, fp),ertd
10.75
10.8
10.85
10.9
10.95
-14
‘500 ‘600 700 800 900 1000,Conclusion: From the graph obtained, we can see that the line doesn’t cross the x-axis,
(root doesn't exist) in the given range of mass
Therefore, we conclude that the velocity diverges for any value of mass given
© Ifwe want to compute this analytically we figure out the same conclusion
F(m)= Vgm/e * tanh((Vg.c/m)*t) — v()=0
By direct substitution we get, m= 40.832 kg
By using the given time and different mass values, the following velocities are obtained
m= 10 kg V= 17.87 mis
40 kg 25 mis
70 kg 26.6 mis
100 kg 27 mis
130 kg 27.86 mis
160 kg 28.14 mis
190 kg 29 mis
From the analytic results, we can also observe that the velocity 40 m/s doesn't exist for
any value of mass in the given instant of time.Exercise 1.1
Problem : Make a new folder to save your files 2. Open a new script 3. Write a code to
draw graphs of the following functions and save it. - Generate x1 and x2 vectors each
containing 100 and 1000 elements respectively using built in functions for automatic.
initialization. (Use the “linspace” function which starts at 0, and ends at 4M) - y1 = cos
x1 -y2= sin x2 4, Customize your plots to identify the two functions.
Objective: The objective of this exercise is to practice creating and saving plots of the
cosine and sine functions using the “linspace” function to generate x-values, and
customizing the plots to distinguish the two functions.
MATLAB code:
eaoely, 2 gaa BS Dp |}
Q fing + 1 Run ana Advance
New Open Save | GoTo Refactor BB Run Run Step
SP oomrate = |e OD isn ig) nine =
FAB) a > arias drive
Resgrmenim = > °
1 xi = Linspace(®, 4%pi, 100); % Generate xi vector with 100 elements from 0 to pi @
2 x2 = linspace(@, 4*7i, 1000); % Generate x2 vector with 1000 clenents from 0 to 4pi
3 Vi = cos(xi); % Calculate yi
y2 = sin(x2); % Calculate y2
then custowizing the plot to ease the distinguishing
‘ by using the color code and to identify the functions in the graph using the “Legend”
plot(xt, yi, “blue"); % Plot yi in blue
hold on}
plot(2, y2, ‘red'); % Plot y2 in red
legend(y1 = cos(xl)", 'y2 = sin(x2)'); % Add legend to identify the tuo functions
title("Plot of yi and y2"); % Add titleOutput:
Plot of y1 and y2
Conclusion:
The code creates two vectors, x1 and x2, with 100 and 1000 elements respectively,
ranging from 0 to 4*pi. It then calculates y1 as the cosine of x1 and y2 as the sine of x2.
The code then plots y1 in blue and y2 in red on the same graph using the ‘hold on’
command. A legend is added to identify the two functions, and a title is added to the
graph. The overall result is a graph that shows the plotted y1 and y2 functions, and it's
easier to distinguish the two functions by using different colors, and the legend and title
make the graph more informative,Exercise 1.2
Proble:
1. Create two vectors “a” and “b” with 4 elements each.
2. Create a matrix “c” using the two row vectors.
3. Create another matrix “d” by replacing the last row of matrix “c" with a row vector
having all elements of value “3”.
4, Exercise by applying simple elementary operations (element-wise and standard
operations), on matrices you created,
Title: Matrices and Arrays
Objectives: Generating and entering Matrices and arrays and Applying Basic scalar
operations.
Tools: MATLAB.
MATLAB code:
$aalas
Rex Gee anes |(com
BBS > mason.
CURRENT FeuDeR
c= (es ons
; #5 Ces 3,3 3 ae
woRKSSHCEcreate two vectors a and b
0=[,2,3,4)
b=[5, 6,78]
%Create a matrix ‘c* using the two row vectors
c= [0:6
%Create another matrix “o" by replacing the last row of matrix “c" with a row vector having
all elements of value *3"
d= [ell 3, 3,3, 3}
% Element-wise addition of matrices ¢ and d
e=c+d:
% Standard matrix multiplication of matrices ¢ and d
feotd:
% Element-wise division of matrix d by scalar 2
gr d/2,
% Transpose of matrix ¢
h
%print the values
disp(d)
disple)
displf)
displ)
disp(h)
1015000 1'5000 15900 1/5000
eee Sm - aes 18) un ana avant &
Toe cine «| BEES, ance le fe
eeGeGloc ce rae .
Bb) 3 3G
Boiss?
5
Conclusion: The conclusion of this code is that it performed several operations on two
vectors, including creating a matrix, element-wise addition and multiplication, division,
and transposition.
"