How to use Maple to solve a war-related math problem

November 05 2012 Douglas Lewit 5
Maple 15
1

restart;

with(DETools):

with(plots):

with(LinearAlgebra):

A:=<,>;

A := Matrix(2, 2, {(1, 1) = 0, (1, 2) = -4, (2, 1) = -1, (2, 2) = 0})

(1)

alpha:=A-lambda*IdentityMatrix(2);

alpha := Matrix(2, 2, {(1, 1) = -lambda, (1, 2) = -4, (2, 1) = -1, (2, 2) = -lambda})

(2)

Determinant(alpha);

lambda^2-4

(3)

lambda1:=2;

2

(4)

lambda2:=-2;

-2

(5)

beta:=>;

beta := Matrix(2, 3, {(1, 1) = -lambda, (1, 2) = -4, (1, 3) = 0, (2, 1) = -1, (2, 2) = -lambda, (2, 3) = 0})

(6)

ReducedRowEchelonForm(subs(lambda=lambda1,beta));

Matrix(2, 3, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0})

(7)

V1:=;

V1 := Vector(2, {(1) = -2, (2) = 1})

(8)

ReducedRowEchelonForm(subs(lambda=lambda2,beta));

Matrix(2, 3, {(1, 1) = 1, (1, 2) = -2, (1, 3) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0})

(9)

V2:=;

V2 := Vector(2, {(1) = 2, (2) = 1})

(10)

A.V1-lambda1*V1;

Vector(2, {(1) = 0, (2) = 0})

(11)

A.V2-lambda2*V2;

Vector(2, {(1) = 0, (2) = 0})

(12)

sols:=c1*V1*exp(lambda1*t)+c2*V2*exp(lambda2*t);

sols := Vector(2, {(1) = -2*c1*exp(2*t)+2*c2*exp(-2*t), (2) = c1*exp(2*t)+c2*exp(-2*t)})

(13)

whattype(sols);

Vector[column]

(14)

convert(sols,Matrix);

Matrix(2, 1, {(1, 1) = -2*c1*exp(2*t)+2*c2*exp(-2*t), (2, 1) = c1*exp(2*t)+c2*exp(-2*t)})

(15)

Dimensions(%);

2, 1

(16)

sols:=convert(sols,Matrix);

sols := Matrix(2, 1, {(1, 1) = -2*c1*exp(2*t)+2*c2*exp(-2*t), (2, 1) = c1*exp(2*t)+c2*exp(-2*t)})

(17)

sols[1,1];

-2*c1*exp(2*t)+2*c2*exp(-2*t)

(18)

x:=t-> (18);

proc (t) options operator, arrow; -2*c1*exp(2*t)+2*c2*exp(-2*t) end proc

(19)

sols[2,1];

c1*exp(2*t)+c2*exp(-2*t)

(20)

y:=t-> (20);

proc (t) options operator, arrow; c1*exp(2*t)+c2*exp(-2*t) end proc

(21)

solve({x(0)=300,y(0)=100},{c1,c2});

{c1 = -25, c2 = 125}

(22)

assign(%);

R:=t-> x(t);

proc (t) options operator, arrow; x(t) end proc

(23)

G:=t-> y(t);

proc (t) options operator, arrow; y(t) end proc

(24)

R(0);

300

(25)

G(0);

100

(26)

diff(R(t),t)+4*G(t);

0

(27)

diff(G(t),t)+R(t);

0

(28)

display(plot([R(t),G(t)],t=0..1,color=[red,green],thickness=[3,3],gridlines=true,axis=[gridlines=[10,color=COLOR(RGB,0,0.7,0.7)]],font=["Copperplate",Bold,12],labels=["Time in
Hours","No. of
Soldiers"],labelfont=[Verdana,Bold,12]),plottools[line]([0.4,0],[0.4,225],linestyle=dash,color=COLOR(RGB,0,0,0.6),thickness=2));

 

fsolve(G(t)=0,t=0.4);

.40235947810852509365

(29)

R((29));

223.60679774997896964

(30)

display(dfieldplot([diff(r(t),t)=-4*g(t),diff(g(t),t)=-r(t)],[r(t),g(t)],t=0..0.4023594781,r=0..300,g=0..100,dirfield=[10,10],arrows=smalltwo,font=["Copperplate",Bold,12],labelfont=["Copperplate",Bold,12],color=COLOR(RGB,0.5,0.5,0.85),labels=["Red
Army","Green
Army"]),pointplot([[300,100]],symbol=solidcircle,color=black,symbolsize=17,gridlines=true,view=[0..300,0..100],axis[1]=[color=red],axis[2]=[color=green]));

 

data:=[seq([R(t),G(t)],t=0..0.42,.01)];

[[300, 100], [296.05973532802661607, 97.019800662675517525], [292.23789849770021370, 94.078410539230695510], [288.53296072333015849, 91.174653034397098135], [284.94343998040687344, 88.307366606455509000], [281.46790041277227452, 85.475404302603756020], [278.10495175825816246, 82.677633300160297652], [274.85324879256281832, 79.912934453420045758], [271.71149079114334637, 77.180201845981161435], [268.67842100890851356, 74.478342348363748538], [265.75282617750395636, 71.806275180743486482], [262.93353601998866172, 69.162931480625289882], [260.21942278270858688, 66.547253875284058862], [257.60940078418016082, 63.958196058801490508], [255.10242598080321482, 61.394722373529760628], [252.69749554922962172, 58.855807395814655659], [250.39364748522058544, 56.340435525812438496], [248.18996021883211861, 53.847600581236369465], [246.08555224577477719, 51.376305394870375706], [244.07958177480019115, 48.925561415688868994], [242.17124639097334107, 46.494388313423154647], [240.35978273469588520, 44.081813586416252802], [238.64446619635214173, 41.686872172609268764], [237.02461062645558106, 39.308606063503701790], [235.49956806117988232, 36.946063920945272058], [234.06872846316476324, 34.598300696575974280], [232.73151947749290208, 32.264377253802133700], [231.48740620274033925, 29.943359992127246622], [230.33589097700877553, 27.634320473699333636], [229.27651317885417725, 25.336335051923419506], [228.30884904303205690, 23.048484501990579707], [227.43251149098572515, 20.769853653175760367], [226.64714997600970697, 18.499531022757285823], [225.95245034302638548, 16.236608451411616656], [225.34813470291978206, 13.980180739937511349], [224.83396132137620476, 11.729345287164276298], [224.40972452218729967, 9.483201728899262683], [224.07525460497682513, 7.240851577770184408], [223.83041777731823860, 5.001397863818189180], [223.67511610121594211, 2.763944775697915225], [223.60928745392877809, .527597302341008814], [223.63290550312010468, -1.708539125060236699], [223.74597969632450992, -3.945358990892331716]]

(31)

plot1:=display(dfieldplot([diff(r(t),t)=-4*g(t),diff(g(t),t)=-r(t)],[r(t),g(t)],t=0..0.4023594781,r=0..300,g=0..100,dirfield=[10,10],arrows=smalltwo,font=["Copperplate",Bold,12],labelfont=["Copperplate",Bold,13],color=COLOR(RGB,0.5,0.5,0.85),labels=["Red
Army","Green
Army"],axesfont=["Copperplate",Bold,10]),pointplot([[300,100]],symbol=solidcircle,color=black,symbolsize=17,gridlines=true,view=[0..300,0..100],axis[1]=[color=red],axis[2]=[color=green]),plot(1/2*t,t=0..300,color=black,thickness=3)):

nops(data);

43

(32)

animate(listplot,[data[1..round(k)],color=black,thickness=3,title="The Red Army Wins!!!",titlefont=["Verdana",Bold,14]],k=1..43,frames=43,background=plot1,paraminfo=false);

 

From the plot above it can be seen that the population of the Green Army is driven to extinction (i.e. becomes zero) first.  The army that's driven to extinction first is the losing army in the conflict.  The other army is thus victorious by default.

 

 

 

 

   

Download Example_of_Lancheste.mw


Please Wait...