Matlab Programming Assignment 2014 Civil Engineering

download Matlab Programming Assignment 2014 Civil Engineering

of 9

Transcript of Matlab Programming Assignment 2014 Civil Engineering

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    1/9

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    2/9

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    3/9

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    4/9

    • The equations need to be converted into matrix format first. (See example in LN P14, S54‐55. )

    • The variable stuid should be loaded from the data file saved in P1. • This problem should be completed in a single MATLAB program (script file).

    Start with this structure

    2

    1 0 0 0 0 0 0 1 0 0 0* * * * * * * * * * *0 1 0 3 / 5 0 0 0 0 0 0* * * * * * * * * * ** * * * * * * * * ** * * * * * * * * ** * * * * * * * * ** * * * * * * * * ** * * * * * * * * ** * * * * * * * * *

    ab

    bc

    ad

    bd

    ce

    de

    ce

    x

    y

    y

    F

    F

    F F F

    F

    F

    F

    A

    A

    E

    − =

    ******

    P3 : Use MATLAB to solve constraint optimization problem ( Estimate time required

    30 minutes, )

    The optimal design of a three-bar truss shown in Fig.P3 is considered. The vertical deflection of itsoaded joint gives the objective function to be minimized.l

    1 2

    12

    =+

    Ph f

    E x x where 25(1 0.1 )P stuid = + , 2= E and .2=h

    where the cross-sectional areas of its members are 1 1= A x and 2 2= A x ; here x1 and x2 are the designvariables. Load P is applied in the direction shown in Fig.P3.

    The constraints are the applicable stresses on the three members and lower and upper bounds on theesign variables as follows.d

    2 1

    21 1 2

    2 17.52 2 x x

    P x x x

    + ≤+

    (maximum permissible stress in tension)

    1 2

    1 17.5(1 0.1 )2

    P stuid x x

    ≤ ++

    (maximum permissible stress in tension)

    221 1 2

    1.22 2 x

    P x x x− + ≥ − (maximum permissible stress in compression)

    10.2 6(1 0.2 ) x stuid ≤ ≤ + 20.2(1 0.1 ) 6stuid x− ≤ ≤

    Use f mi ncon( ) to obtain the optimized value for the cross-sectional areas and the minimumvertical deflection.

    • See example in LN P38 ‐39, S150 ‐155. • To solve a constraint optimization problem, you need to define TWO functions, one

    function for the cost (objective), another for describing constraints. Both functions can be defined as “in program” anonymous functions or by separate function files. You must convert all constraints to the standard format so that they can be described.

    • All commands should be in script or/and function files. • The variable st ui d should be loaded from the data file saved in P1.

    4

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    5/9

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    6/9

    (3) Find the estimation of a using the least square formula. For the calculation of sum, see Workshop 3 W3P3. (4) Determine s using a. (use the variable s1 to store the value of s in order to differentiate with the following part).

    P4.2 Model Identification Method 2 : Due to a special property of the Gaussian function, the

    following relation can be used to find the value of s using data loaded.

    ( )

    ( )

    22 2 2

    2

    22 2

    2

    3 2

    1( ) exp22

    1 1exp22 2

    12

    zs z f z dz z dz

    z z dz z c dz

    c dz

    σ σ π

    σ σ π σ π

    +∞ +∞

    −∞ −∞

    +∞ +∞

    −∞ −∞

    −= = −= =

    ∫ ∫

    ∫ ∫

    s zπ

    +∞

    −∞ = ∫

    Use “t rapz( ) ” command to calculate the integration, the estimate (s2) of the parameter sis then determined. (The integration range from ‐∞ to +∞ simply means that the integration is for the whole range of z.)

    P4.3 Model Identification Method 3 : The model identification problem is an optimization problem which is to find the optimal parameters to make the sum of square of predictionerrors minimum. Use a MATLAB’s optimization command (e.g. “ f mi nsear ch ”) to findthe parameter s to minimize the following cost function.

    22251

    21

    ( )( ) exp 2k

    z k J c k s=

    −= − ∑ J is a function of s.

    The estimate (s3) of the parameter s is determined by minimizing the above cost function.(For minimization see Workshop 2 W2P1 & W2P2, LN P34 ‐P35, S135 ‐137 ).

    P4.4 To check the goodness of the models identified, the identified parameters (s1, s2, and s3) will be used to determine the predicted model outputs according to the following equations.

    2

    1 2

    1

    exp2 z

    cs

    −=

    2

    2 2

    2

    exp2 z

    cs

    −=

    2

    3 2

    3

    exp2 z

    cs

    −=

    Use subpl ot command to plot four graphs (c versus z, c1 versus z, c2 versus z, c3 versus z)on the same figure window. (For using subplot see LN P21, S81‐82. )

    P5 : Solving Differential Equation and Using Data Interpretation ( Estimate timerequired 45 minutes )

    The oscillations caused by a suddenly released fluid from a height difference Z that separates thefluid levels in two rectangular prismatic reservoirs connected by a long pipeline of length L, asshown in Fig. P5 can be determined from

    6

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    7/9

    22

    2( ) ( ) ( ) ( ) 0

    d Z t dZ t dZ t signum p qZ t

    dt dt dt

    + + =

    1 20.375 0.00074 p m q− −= = s

    P5.1 Use a differential equation solver in MATLAB (i.e. ode45 , ode23 or ode15s ) to solve

    the above equation for the time interval [0, 300 ] and initial conditions (0) 0m/sdZ and

    . Plot

    dt =

    (0) 20m Z = ( ) Z t and ( )dZ t dt

    against time t . (Note that si and

    this is implemented in MATLAB by si gn( x) )

    1 0( ) 0 0

    1 0

    x

    gnum x x

    x

    >= =

    − <

    For solving higher order differential equations see Workshop 2 W2P4 and LN P44, S 173 ‐174.

    P5.2 Set the initial conditions as (0) 0m/sdZ anddt

    = (0) n Z Z = , determine the value of the first

    occurrence of t n for which Z t ( ) 0n = when 5 ,10 ,15 , 50n Z m m m m= . Plot t n vs Z n. (Thevalue of t can be found in many ways. The easiest way is to simulate (solve) thedifferential equation for a longer period time and then use “ i nt er p1 ” to find t for

    .)

    n

    0n

    ( )n Z t =

    Basically, you need to repeat the work of P5.1 with all initial conditions Zn=5, 10, 15, …, 50. To do this repeated action, you need to use loop operation, f or - end l oop or whi l e- endl oop (LN48‐53) . The main task for this part is to find the time of t n for when Z(tn)=0 (see graph on the right). This can be done by the find command (LN P53, S212 ‐213) and the interpretation (LN P54, S 214 ‐216).

    0 50 100 150 200 250 300-5

    0

    5

    10

    15

    20Position Z(t)Velocity dZ(t)/dt

    t n when Z(t n)=0

    It can be seen that no data point at exactly Z(t)=0, so that some approximations must be made. We just need to find the first data point when Z(t)0.

    7

    Method 1: Very rough approximation Pi ndex=f i nd( Z

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    8/9

    P6 : MATLAB loops, conditional and logic operations, formatted text, findsolutions for nonl inear equations ( Maximum expected time 45 minutes )

    The bisection method can be used to solve a single variable equation when a unique solution existswithin an interval [ , ] L R x x . See Fig.P6.

    ( ) 0 y f x= = When ( ) L f x and ( ) R f x have opposite signs (i.e. ( ) ( ) 0 L R f x f x < ), a solution exists within interval[ , L ] R x x . The middle point C x can be chosen as a trail solution. It is unlikely that this trail solutionis the true solution i.e. . However, the solution interval can be narrowed as either [( )C ≠ 0 f x , ] L C x x or [ , ]C R x x (depends on the signs of ( ), ( L C ), ( ) R f x f x f x ). Repeat this process until the interval isufficiently small or the solution has been found.s

    x

    y

    x L x R xC

    f(x R)

    f(x L)

    f(xC ) f(x L)f(x R)

  • 8/9/2019 Matlab Programming Assignment 2014 Civil Engineering

    9/9

    Note 1: For programming idea, especially the ways of presented information on the screen using formatted text, please see example in LN P59, S 235. Note 2

    : More detailed description and the program example for Bisection method can be found in

    https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/10RootFinding/bisection/ Note 3: If you write a function m‐file to define the function, you need to declare stuid as a global variable by adding a line “gl obal s tui d ” in the beginning of your main script file and also in the function file immediately after function statement. A function m ‐file is independent of MATLAB's main workspace (including command window & script file).

    P6.3 To improve the Bisection method, the golden ratio is used to determine the “middle” point.Find the solution using the following “middle” point. The tabular information same as P3.2are also required for this task.

    3 5( ) | ( ) | | ( ) |2

    5 1 ( ) | ( ) | | ( )2

    L R L L

    C

    L R L L |

    R

    R

    x x x if f x f x x

    x x x if f x f x

    −+ − <

    = −+ − >

    ( 5 12−

    the “golden ratio”).

    P6.4 Use the MATLAB’s build-in function “ f zer o ” to find the solution and compare it withresults obtained in P4.2 and P4.3.

    P7 MATLAB program branches ( Estimate time required 20 minutes, example see Workshop 3 W3P4 )

    Write a MATLAB program to call all programs written for all problems for this assignment. Whenthis program is run, a selection menu similar to the following one should be presented.

    Sel ect Pr obl em t o sol ve:1: Pr obl em P12: Pr obl em P2

    …………………………………… 6: Pr obl em 6

    Once the selection is made, the relevant program should be executed to solve the problem selected.(Use MATLAB command “ swi t ch- case- end ”). The program should be able to return to theselection menu before all problems have been solved.

    9

    https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/10RootFinding/bisection/https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/10RootFinding/bisection/https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/10RootFinding/bisection/