Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

A Guide to MATLAB for Beginners and Experienced Users - Brian R.H.

Brian R.H., Roland L.L. A Guide to MATLAB for Beginners and Experienced Users - Cambrige, 2001. - 346 p.
Download (direct link): beginnersandex2001.pdf
Previous << 1 .. 51 52 53 54 55 56 < 57 > 58 59 60 61 62 63 .. 91 >> Next


* + + < 75 * > 0, > 0, > 0.

The problem is solved with simlp as follows:

clear f A b; f = [-143 -60 -195]; A = [120 210 150.75; 110 30 125; 1 1 1;... Linear Programming

179

-1 0 0; 0 -1 0; 0 0 -1];

b = [15000; 4000; 75; 0; 0; 0];

simlp(f, A, b)

ans =

0.0000 56.5789 18.4211

So the farmer should ditch the wheat and plant 56.5789 acres of barley and 18.4211 acres of corn.

There is no practical limit on the number of variables and constraints that MATLAB can handle certainly none that the relatively unsophisticated user will encounter. Indeed, in many true applications of the technique of linear programming, one needs to deal with many variables and constraints. The solution of such a problem by hand is not feasible, and software such as MATLAB is crucial to success. For example, in the farming problem with which we have been working, one could have more than two or three crops. (Think agribusiness instead of family farmer.) And one could have constraints that arise from other things besides expenses, storage, and acreage limitations, for example:

Availability of seed. This might lead to constraint inequalities such as

Xj < k.

Personal preferences. Thus the farmer's spouse might have a preference for one variety or group of varieties over another, and insist on a corresponding planting, thus leading to constraint inequalities such as Xi < Xj or X1 + X2 > X3.

Government subsidies. It may take a moment's reflection on the reader's part, but this could lead to inequalities such as X j > k.

Below is a sequence of commands that solves exactly such a problem. You should be able to recognize the objective expression and the constraints from the data that are entered. But as an aid, you might answer the following questions:

How many crops are under consideration?

What are the corresponding expenses? How much money is available for expenses?

What are the yields in each case? What is the storage capacity?

How many acres are available? 180 Chapter 9: Applications

What crops are constrained by seed limitations? To what extent?

What about preferences?

What are the minimum acreages for each crop?

clear f A b

f = [-110*1.3 -30*2.0 -125*1.56 -75*1.8 -95*.95 -100*2.25 -

50*1.35];

A = [120 210 150.75 115 186 140 85; 110 30 125 75 95 100 50; 1111111; 100000 0; 001000 0; 0000010;

1 -1 0 0 0 0 0; 0 0 1 0 -2 0 0; 0 0 0 -1 0 -1 1;

-100000 0; 0-1 0000 0; 00 -1000 0; 000 -100 0; 0000 -10 0; 00000 -10;

0 0 0 0 0 0 -1];

b = [55000;40000;400;100;50;250;0;0;0;-10;-10;-10;

-10;-20;-20;-20];

simlp(f, A, b)

ans =

10.0000 10.0000 40.0000 45.6522 20.0000 250.0000 20.0000

Note that despite the complexity of the problem, MATLAB solves it almost instantaneously. It seems the farmer should bet the farm on crop number 6. We suggest you alter the expense and/or the storage limit in the problem and see what effect that has on the answer.

The 360 Pendulum

Normally we think of a pendulum as a weight suspended by a flexible string or cable, so that it may swing back and forth. Another type of pendulum consists of a weight attached by a light (but inflexible) rod to an axle, so that The 360 Pendulum 181

it can swing through larger angles, even making a 360 rotation if given enough velocity.

Though it is not precisely correct in practice, we often assume that the magnitude of the frictional forces that eventually slow the pendulum to a halt is proportional to the velocity of the pendulum. Assume also that the length of the pendulum is 1 meter, the weight at the end of the pendulum has mass 1 kg, and the coefficient of friction is 0.5. In that case, the equations of motion for the pendulum are

x'(t) = y(t), y'(t) = -0.5y(t) - 9.81 sin(x(t)),

where t represents time in seconds, x represents the angle of the pendulum from the vertical in radians (so that x = 0 is the rest position), y represents the velocity of the pendulum in radians per second, and 9.81 is approximately the acceleration due to gravity in meters per second squared. Here is a phase portrait of the solution with initial position x(0) = 0 and initial velocity y(0) = 5. This is a graph of x versus y as a function of t, on the time interval 0 < t < 20.

g = inline('[x(2); -0.5*x(2) - 9.81*sin(x(1))]', 't', 'x'); [t, xa] = ode45(g, [0 20], [0 5]); plot(xa(:, 1), xa(:, 2))

Recall that the x coordinate corresponds to the angle of the pendulum and the y coordinate corresponds to its velocity. Starting at (0, 5), as t increases we follow the curve as it spirals clockwise toward (0, 0). The angle oscillates back and forth, but with each swing it gets smaller until the pendulum is virtually at rest by the time t = 20. Meanwhile the velocity oscillates as well, taking its maximum value during each oscillation when the pendulum is in 182 Chapter 9: Applications

the middle of its swing (the angle is near zero) and crossing zero when the pendulum is at the end of its swing.
Previous << 1 .. 51 52 53 54 55 56 < 57 > 58 59 60 61 62 63 .. 91 >> Next