Assignment 6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

EPF3109 LAB WEEK 7: Developing Program using User-Defined Functions and

Function Files

Question 1

Write a user-defined function that plots a circle given the coordinates of the center and the radius.
For the function name and arguments use circleplot(x,y,R). The input arguments are the x and y
coordinates of the center and the radius, R. This function has no output arguments. Use the function
to plot the following circles:

a) x = 3.5; y=2.0; R=8.5


b) x = 4.0; y=-1.5; R=10
Question 2

A two-dimensional state of stress at a point in a loaded material is defined by three


components of stress, σ xx , σ yy and τ xy (see Figure 1).

Figure 1.

The maximum and minimum normal stresses (principal stresses) at the point, σ max and σ min
, are calculated from the stress components by:

2
σ xx + σ yy  σ xx + σ yy 
σ max = +   + τ xy
2

2  2 

2
σ xx + σ yy  σ xx + σ yy 
σ min = −   + τ xy
2

2  2 

Write a user-defined MATLAB function that determines the principal stresses from the
stress components. For the function name and arguments use:

[Smax,Smin] = princstress(Sxx,Syy,Sxy).

The input arguments are the three stress components, and the output arguments are the
maximum and minimum stresses. Use the function to determine the principal stresses for
the following states of stress:

a) σ xx =
−190 MPa ; σ yy ==
145 MPa ; τ xy 110 MPa

b) σ xx =
200 MPa ; σ yy =
−50 MPa ; τ xy =
150 MPa
Question 3

You are trying to create bubbles inside a Swiss cheese for mathematical modelling purposes.
You are required to create five bubbles in a cheese by representing them in a graph form
(observed from microstructure image) as follows:

2.5

1.5
c
y

0.5

0
0 0.5 1 1.5 2 2.5 3 3.5
xc

Figure 2.

The centre coordinates and radius for each bubbles are: bubble1 (x=0.5, y=0.5, r=0.3);
bubble2 (x=2, y=1, r=0.4); bubble3 (x=3, y=1, r=0.4); bubble4 (x=1, y=2, r=0.5); bubble5
(x=2.5, y=2, r=0.4).

Re-create Figure 2 using function programming approach. The formula to create a circle
(bubble) is as follows:

x1 = r cos( θ );
y1 = r sin( θ );
0 ≤ θ ≤ 2π ( θ interval of 0.1 for smooth circle)
x=
c x1 + x;
y=
c y1 + y;

Where xc and yc are the coordinate of circle in graph shown in Figure 2.


Question 4

You are analysing shear flow of syrup produced with different emulsifier. When more than
one emulsifier are added to the syrup, the shear flow changes according to the following
conditions:

=τ 1 η1γ ; 0<x ≤ 2
τ 2 η1 ( γ )
n
= ; 2<x ≤ 4
τ 3 η1 ( γ ) + η2 ( γ )
2n
= ; x=5

where τ is the shear flow (in kPa), η is viscosity and n is the power law constant. The
maximum number of emulsifier allowed in the syrup is five. The variable in the limit, x
represents the number of additives added to the syrup. The values of the constants are as
follows:

=η1 10=
kPa-s; η 2 20
= kPa-s; γ 0.5 s −1 ; n=0.2

Write a MATLAB code for a main file using if-else is-else-end structure to solve the problem
described before. This can be done by first asking the user to input the number of emulsifier
added, x . After that create function files for each of the equation (τ 1 , τ 2 , τ 3 ) , before

connecting the function files to the main file.


Question 5

A cylindrical vertical fuel tank has hemispheric end caps as shown. The radius of the cylinder
and the caps is r=15 in and the height of the cylindrical middle section is 40 in. Write a user-
defined function (for the function name and arguments use V = Volfuel(h)) that gives
the volume of fuel in the tank (in gallons) as a function of the height h (measured from the bottom).
Use the function to make a plot of the volume as a function of h for 0 ≤ h ≤ 70 in .

You might also like