Sie sind auf Seite 1von 47

Engineering

often involves applying a consistent, structured approach to the solving of problems. A general problem-solving approach and method can be defined, although variations will be required for specific problems. Problems must be approached methodically, applying an algorithm, or step-by-step procedure by which one arrives at a solution.

1-2

The

problem-solving process for a computational problem can be outlined as follows:


Define the problem. Create a mathematical model. Develop a computational method for solving the problem. Implement the computational method. Test and assess the solution.

1-3

small object is launched into flight from the ground at a speed of 50 miles/hour at 30 degrees above the horizontal over level ground. Determine the time of flight and the distance traveled when the ball returns to the ground.

1-4

Problem

Definition:

Properties of the object and the flight medium could affect the flight trajectory. Acceleration of gravity also affects the flight The accuracy of the initial speed and angle of the object is needed to determine the necessary accuracy of the quantities to be computed.

Unit conversions needed:


1 mile = 5280 feet 1 hour = 60 minutes = 3600 seconds 360 degrees = 2 radians

1-5

Mathematical

Model:

Time: t (s), with t = 0 when the object is launched. Initial velocity magnitude: v = 50 miles/hour. Initial angle: = 30. Horizontal position of ball: x(t) (ft). Vertical position of ball: y(t) (ft). Acceleration of gravity: g = 32.2 ft/s2, directed in negative y direction.

1-6

The key step in developing a mathematical model is to divide the trajectory into its horizontal and vertical components. The initial velocity can be divided in this way, as shown in Figure

1-7

Given the horizontal and vertical components of the initial velocity, the horizontal and vertical positions can be determined as functions of time. Since there is no external force acting to retard the horizontal motion, the object will move at a constant speed of vh in the horizontal direction

In the vertical direction, the object motion is retarded by gravity and its position is

1-8

Computational

Method:

Using the model developed above, expressions for the desired results can be obtained. The object will hit the ground when its vertical position is zero

which can be solved to yield two values of time

1-9

The second of the two solutions indicates that the object will return to the ground at the time

The horizontal position (distance of travel) at this time is

1-10

Computational

Implementation:

The equations defined in the computational method can be readily implemented using Matlab. The commands used in the following solution will be discussed in detail later in the course, but observe that the Matlab steps match closely to the solution steps from the computational method.

1-11

% Flight trajectory computation % Initial values g = 32.2; v = 50 * 5280/3600; theta = 30 * pi/180;


Words following percent signs (%) are comments to help in reading the Matlab statements

% Compute and display results A word on the left of an equals sign is known disp(time of flight (s):) as a variable name and it will be assigned tg = 2 * v * sin(theta)/g If a the value or values on the right of to Matlab command assigns or computes disp(distance traveled (ft):)athe equalswill display the value on this value, it sign. Commands having the screenarethe statement does not end with xg = v * cos(theta) * tg form if known as assignment statements.
a semicolon (;).

% Compute and plot flight trajectory Thus, the values of v, g, and theta will The statement t = linspace(0,tg,256); t = linspace(0,tg,256); not be vector of creates adisplayed. length 256. x = v * cos(theta) * t; The values of tg and xg will be computed y = v * sin(theta) * t - g/2 * and displayed, t.^2; plot(x,y), axis equal, axis([ 0 150 0 30 ]),grid, ... xlabel(Distance (ft)), ylabel(Height(ft)), title(Flight Trajectory)

The expression t.^2 squares each element in t,making another vector. The plot statement generates the plot of height against The the x and (...) at More than one statement withbe title and labels on three dots y axes. the end of a line mean distance, complete can a entered that the statement continues on the next line. on the same line if the statements are separated by commas.
1-12

Testing

and Assessing the Solution:

1-13

Command: A user-written statement in a computer language that provides instructions to the computer.
Variable: The name given to a quantity that can assume a value,. Default: The action taken or value chosen if none has been specified. Toggle: To change the value of a variable that can have one of two states or values. For example, if a variable may be on or off and the current value is on, to toggle would change the value to off.
1-14

Arguments: The values provided as inputs to a command. Returns: The results provided by the computer in response to a command.
Execute: To run a program or carry out the instructions specified in a command. Display: Provide a listing of text information on the computer monitor or screen. Echo: To display commands or other input typed by the user. Print: To output information on a computer printer (often confused with display in the text- book).
1-15

Elementary

math functions (enter help elfun for a more complete list):

1-16

Information

about these functions is displayed by the command help function. For example:

>> help sqrt SQRT Square root. SQRT(X) is the square root of the elements of X. Complex results are produced if X is not positive.

1-17

1-18

Problem:

Solve for s: 2s2 + 10s + 12 = 0 Derive and apply the quadratic equation by first expressing the quadratic polynomial in parametric form
as2 + bs + c = 0 Assuming a 0, rewrite the equation as

Analysis:

1-19

1-20

Assuming

a=12 b=10 c=12 Calculate the value of x, y, s1 and s2 in matlab

1-21

1-22

By

entering the variable name at the Matlab prompt, without a semicolon.


By use of the command disp. use of the command fprintf.

By

1-23

From

the prompt:

1-24

disp:

There are two general forms of the command disp that are useful in displaying results and annotating them with units or other information:

disp(variable): Displays value of variable without displaying the variable name. disp(string): Displays string by stripping off the single
quotes and echoing the characters between the quotes.
1-25

String: A group of keyboard characters enclosed in single quote marks (). The quote marks indicate that the enclosed characters are to represent ASCII text.

Note that the two disp commands were entered on the same line so that they would be executed together.

1-26

fprintf

One of the weaknesses of Matlab is its lack of good facilities for formatting output for display or printing. A function providing some of the needed capability is fprintf. The fprintf function provides more control over the display than is provided with disp. In addition to providing the display of variable values and text, it can be used to control the format to be used in the display, including the specification to skip to a new line
1-27

The general form of this command is:

The format specifiers include:

w.d%f: Display as fixed point or decimal notation (defaults to short), with a width of w characters (including the decimal point and possible minus sign, with d decimal places. Spaces are filled in from the left if necessary. Set d to 0 if you dont want any decimal places, for example %5.0f
w.d%e :Display using scientific notation (defaults to short e), with a width of w characters (including the decimal point, a possible minus sign, and five for the exponent), with d digits in the mantissa after the decimal point. The mantissa is always adjusted to be less than 1.
1-28

w.d%g: Display using the shorter of tt short or short e format, with width w and d decimal places.
\n: Newline (skip to beginning of next line)

1-29

The

plot command can be used to plot complex variables in the complex plane. For example
>> z = 1 + 0.5j; >> plot(z,.)

This creates a graphics window, called a Figure window, named by default Figure No. 1, which becomes the active (top) window
1-30

The plot produced, with z plotted as a point (due to the command .) in the complex plane, with the real value (1.0) on the horizontal (x) axis and the imaginary value (0.5) on the vertical (y) axis. The axes have been scaled automatically, with a range of 0.0 to 2.0 on the horizontal axis and a range of -0.5 to 1.5 on the vertical axis.

Numerical scales and tick marks have been added


automatically.

1-31

Color and markers can be specified by giving plot an additional argument following the complex variable name.

1-32

Examples:

1-33

1-34

1-35

1-36

>> print

% prints the current plot to the system printer

1-37

1-38

Rectangular

Form Plot

1-39

z1 = 1.5 + 0.5j; x-axis=1.5, y=0.5 x-axis=0.5, y=1.5 z2 = 0.5 + 1.5j; z3=(1.5 + 0.5j)+(0.5 + 1.5j) z3 = z1 + z2; =2.0+ 2.0j z4=(1.5 + 0.5j)*(0.5 + 1.5j) z4 = z1 * z2; x-axis=2, y=axis=2 =[(1.5)(0.5)-(0.5)(1.5)]+j[(1.5)(1.5)z5 = conj(z1); (0.5)(0.5)] z6 = j * z2; Conjugate =0+2.5j z1= 1.5+0.5i z7 = z2/z1; x-axis=0.5, y-axis=1.5 x-axis=0, y=axis=2.5 axis([-3 3 -3 3]); axis square; Produce a square plot instead of rectangular j*z2= -0.5-1.5i grid on; adds dashed grid lines at the tick x-axis=-1.5, y-axis=-0.5 hold on; Retain existing axes, add new curves to current axes marks z7=(0.5 + 1.5j)/(1.5 plot(z1,b.); when new plot commands are issued. + 0.5j) =0.33+0.3j plot(z2,go); x-axis= 0.33,y-axis=0.3 plot(z3,rx); Define minimum and maximum values of the axes plot(z4,m*); Plotting the points z1,z2,z3,z4,z5,z6 and plot(z5,c+); z7 plot(z6,kd); Adds text in quotes to location (x,y) on the plot(z7,kp); current axes, where (x,y) is in units from text(real(z1)+0.1,imag(z1),z1); the current plot text(real(z2)+0.1,imag(z2),z2); text(real(z3)+0.1,imag(z3),z1+z2); text(real(z4)+0.1,imag(z4),z1*z2); text(real(z5)+0.1,imag(z5),z1*); text(real(z6)+0.1,imag(z6),j*z2); Labels horizontal (x) axis with text in quotes text(real(z7)+0.1,imag(z7),z2/z1); xlabel(Real Part); Labels vertical (y) axis with text in quotes ylabel(Imaginary Part); Labels top of plot with text in quotes 1-40 title(Complex Numbers);

1-41

matrix is a two-dimensional array.


Scalar: A matrix with one row and one column.

Vector: A matrix with one row (a row vector) or one column, ( a column vector).

Matrix: An example of a matrix with four rows and three columns:

1-42

1-43

Example:

1-44

In

Matlab matrix multiplication is denoted by an asterisk(*).

1-45

1-46

1-47

Das könnte Ihnen auch gefallen