2.1MATLABMATLAB Matrix Laboratory , MathWorks 20 80 , , MATLAB Simulink .MATLAB1) , ;2) , ;3) , ;4) ( ), .2.1.1MATLABMATLAB , , . , MATLAB , 2.1.1 .MATLAB “>>” , MATLAB . , Enter ,MATLAB .·8· 2̽ ԯ2.1.1MATLAB1.help, help . polyfit .help polyfitPOLYFIT Fit polynomial to data..P=POLYFIT(X,Y,N)finds the coeffici-ents of a polynomial P(X)of degree N that fits the data Y best in a least-squares sense.P is a row vector of length N+1containing the polynomial coefficients in descending powers,P(1)*X^N+P(2)*X^(N-1) +···+P(N)*X+P(N+1)., MATLAB Help . Help Product Help , ( 2.1.2)2.1.2Help2.1MATLAB ·9·Seach , .2.clearclear . “a=1”, >>a=1. 1 a. a , clear .>>clear a???Undefined function or variable a .3.formatMATLAB format . format short , 5 ; format rational ; format long g 15 ;>>format short>>pi ans=3.1416;>>format rational>>pi ans=355/113;>>format long g>>pi ans=3.141592653589792.1.2MATLAB1.2.1.1 MATLAB .MATLAB 1 , .MATLAB , B b .2.1.1MATLABpii,jinf . n/0 inf, n 0ans , .,MATLABansNaN , . 0/0 inf/inf2.MATLAB , . . MATLAB , , , .A=[1−256−49] A=[1,−2,5,6,−4,9] 6 A.·10· 23 5 C=[279−186;112382017;4−2660924];,MATLAB , 2.1.2 .2.1.2MATLABones(i,j) i j 1zeros(i,j) i j 0eye(i,j) i j 1, 0randn(i,j) i j , diagmagic(n) n , , MATLAB , . A ,A(i,j) A i j .A(:,j) A j ,A(i,:) A i .A(i,k1:k2) A i k1 k2 .A(k1:k2,j) A j k1 k2 .>>A=magic(4)A=[162313;511108;97612;414151];>>A(3,2)ans=7;>>A(2,:)ans=[511108]>>A(2,2:4)ans=[11108]. [] . D=[A B] A B, A B ; D=[A;B] A B, AB .2.1.3MATLABMATLAB , MATLAB , 2.1.3 .2.1.3MATLAB’A’+A+B−A−B+s+B s B−s−B s B*A*B.* A.*B.*s.*A s A2.1MATLAB ·11·inv inv(A)\A\B A B inv(A)*B, AX=B /B/A A B B*inv(A), XA=B ∧A∧n A n./ A./B A B.\ A.\B B B./s./B s B.A∧n A n>>A=magic(3);B=[1:3;4:6;7:9];>>A=[816;357;492];>>B=[123;456;789];>>A*B=[546984;7287102;546984];>>A\B=[0.01670.08330.1500;0.76670.83330.9000;0.01670.08330.1500];>>B/A=[-0.03330.4667-0.0333;0.16670.66670.1667;0.36670.86670.3667];>>A.*B=[8218;122542;287218];>>A.\B=[0.12502.00000.5000;1.33331.00000.8571;1.75000.88894.5000];>>B./A=[0.12502.00000.5000;1.33331.00000.8571;1.75000.88894.5000];,MATLAB , 2.1.4 .2.1.4MATLABlog(A)Asqrt(A) Acond(A) ( , )det(A) Arank(A) Anorm(A) Aeig(A) Atrace(A) Aexpm(A) A>>A=magic(5);d=det(A),t=trace(A),rk=rank(A),c=cond(A),·12· 2n2=norm(A),e=eig(A);d=5.0700e+006;t=65;rk=5;c=5.4618;n2=65.0000;e=[65.0000-21.2768-13.126321.276813.1263]T2.1.4MATLABMATLAB plot, .plot x X , y Y , plot(x,y), x y .2.1.1 [0,2π] y=sin x, 2.1.3 .>>x=0:pi/100:2*pi;y=sin(x);plot(x,y)plot(x,y1,x,y2,x,y3,···) x X , y1,y2,y3,··· Y .2.1.3[0,2π] 2.1.4[0,2π]2.1.2 [0,2π] y=sin(x) y=cos(x), 2.1.4 .>>x=0:pi/100:2*pi;y1=sin(x);y2=cos(x);plot(x,y1, k: ,x,y2, b- )title( sine and cosine curves );xlabel( independent variable X );ylabel( dependent variable Y );text(2.8,0.5, sin(x) );text(1.4,0.3, cos(x) );legend( sin(x) , cos(x) );MATLAB , . plot3. plot . plot .2.1MATLAB ·13·plot3(x1,y1,z1,c1,x2,y2,z2,c2,···), x1,y1,z1··· c1,c2··· , x,y,z .2.1.3 .t=0:pi/50:10*pi;y1=sin(t);y2=cos(t);plot3(y1,y2,t), 2.1.5 .title(’helix’),text(0,0,0,’origin’);xlabel(’sin(t)’),ylabel(’cos(t)’),zlabel(’t’);grid;,mesh , . mesh(x, y,z,c), x,y X Y ,z (x,y) Z ,x,y,z ,c , 2.1.6 .>>x=0:0.15:2*pi;y=0:0.15:2*pi;z=sin(y’)*cos(x);mesh(x,y,z);title(’ ’);2.1.5 2.1.6mesh 2.1.5MATLAB1.MMATLAB , , , .m M , . M , .MATLAB M . M , File | New | M-File . MATLAB File New , M-file M , M M , File save as , File .M, OK M . M , File | Open .·14· 2M ; H1 , , , , .function y=myfun(x)%y=x^2+x;%2.MATLAB if switch , .if 31 if end2 if 1else; 2end3 if 1 1elseif 2 2······elseif m m else m+1endswitch ,case 1 1case 2 2······case m m otherwise m+1end2.1.4 score m+1 . score −1 I am a teacher. 0 I am a student. 1 You are a teacher. You are a student.score=input( );switch score;case−1;disp ( I am a teacher. );case0;disp( I am a student. );case1;disp( You are a teacher. ); otherwise;disp( You are a student. );end3., . .MATLAB for while .for for = 1 2 3 end1 ,2 ,3 . 1 , 2 .2.1.5 y=1+1/3+1/5+···+1/(2n−1), n=100 , y .y=0;n=100;for i=1:n;y=y+1/(2*i−1);end;y=3.2843while :while end, , , , .2.2LINGO ·15·2.2LINGOLINGO Linear Interactive and General Optimizer( ) , LINDO (LINDO Systems Inc.) , LINDO(Linear Interactive and Discrete Optimizer, ), , , . LINGO , , , , ( Excel ), .2.2.1LINGOLINGO 13.0, , Demo , LINDO .LINGO13.0 Win32 Win64 , 35M , , , , . , Windows LINGO .LINGO , ( 2.2.1), , , , “OK” , ( ), “Demo”, LINGO ( 2.2.2). “OK”, ID , , “Do Not Create User ID File”, ( 2.2.3), LINGO .2.2.1·16· 22.2.2LINGO 2.2.3LINGO2.2.2LINGOLINGO , ( 2.2.3), , , , , LINGO .2.2.1 , 2.2.1 . , , 50% ,(1) 400 ;(2) 1.4( , );(3) 5 .1000 ,2.2.1(%)A 29 4.3B 215 5.4C 14 5.0D 13 4.4E 52 4.5A,B,C,D,E x1,x2,x3,x4,x5( ),max z=0.043x1+0.027x2+0.025x3+0.022x4+0.045x5., x2+x3+x4 4;2x1+2x2+x3+x4+5x5x1+x2+x3+x4+x5 1.4,6x1+6x2−4x3−4x4+36x5 0;2.2LINGO ·17·9x1+15x2+4x3+3x4+2x5x1+x2+x3+x4+x5 5,4x1+10x2−x3−2x4−3x5 0;x1+x2+x3+x4+x5 10; x1,x2,x3,x4,x5 0.Lingo Modelmax=0.043*x1+0.027*x2+0.025*x3+0.022*x4+0.045*x5;x2+x3+x4>4;6*x1+6*x2-4*x3-4*x4+36*x5<0;4*x1+10*x2-x3-2*x4-3*x5<0;x1+x2+x3+x4+x5<10;File|Save “Ctrl+S” , .lg4, LINGO , . , .lg4 ,LINGO .lng,.ldt,.ltf,.lgr , .lng , ; .ldt LINGO , ; .ltf LINGO ; .lgr , LINGO .LINGO(1) “model ” , “end” , , ;(2) “;” , , , , , , ;(3)LINGO , , , 8 , 32 ;(4) “MAX=” “MIN=” ;(5) “ ” , “;” , ;(6) , “[]” , ,[OBJ]max=0.043*x1+0.027*x2+0.025*x3+0.022*x4+0.045*x5;(7) , , , LINGO “MAX=” “MIN=” , ( );(8)LINGO , , , x1 , @free, @free(x1);(9) ,·18· 2, LINGO , , , ;(10)LINGO “>=” “>” ,“<=”“<” ;(11) , “model ” “end” “max” “min” , ;(12) , , , . , “max=” “max”, LINGO .11 “Help” , .LINGO|Generate|Display model “Ctrl+G” , . ,[1]MAX=0.043*X1+0.027*X2+0.025*X3+0.022*X4+0.045*X5;[2]X2+X3+X4>=4;[3]6*X1+6*X2-4*X3-4*X4+36*X5<=0;[4]4*X1+10*X2-X3-2*X4-3*X5<=0;[5]X1+X2+X3+X4+X5<=10;, . LINGO|Solve “Ctrl+U” , . .LINGO ,Solver Status( ) (Model Class) (State) (Objective) (Infeasibility) (Iterations). , LP( ) NLP( ) IP( ) QP( ) ILP( ) PILP( ) PIP( ) INLP( ) IQP( ) PIQP( ) MIP( ). Global Optimum( ) Local Optimum( ) Feasible( ) Infeasible( ) Unbounded ( ) Interrupted( ) Undetermined( ). , , N/A.Extended Solver Status( ) (Solver Type) (Best Obj) (Obj Bound) (Steps) (Active). ,2.2LINGO ·19· B-and-B( ) Global( ) Multistart().Variables( ) (Total) (Nonlinear)(Integer).Constraints( ) (Total) (Nonlinear).Nonzeros( ) (Total) (Nonlinear).Generator Memory Used(K)( ) (K).Elapsed Runtime(hh mm ss)( ) “ ”.LINGO , 3 , , 0.2983636. , . x1=0.181818,x2=0,x3=7.363636,x4=0,x5=0.4545455.Reduced Cost( ) ,. Reduced Cost 0, x j, Reduced Cost x j ( Max ). x2 Reduced Cost 0.03018182, x2 0 1 , 0.03018182, 0.2983636−0.03018182=0.26818178.Row , , .Slack or Surplus , . “<=” , (Slack), “>=” , (Surplus), , 0, , , . , 1000 , 0, 1000 , .Dual Price , , ,. , a0, , a0 ( Max ). ( ), 0.0 , . , 3∼5 , 5 , 0.02983636,x1+x2+x3+x4+x5 10 x1+x2+x3+x4+x5 11, 100 , 0.02983636, 0.2983636+0.02983636=0.32819996(·20· 2 ).2.2.3LINGO2.2.2 LINGO , , , , . , , . ,LINGO , . , LINGO .2.2.2 3 , 5 . , .3 2.2.2 .2.2.2123 ( )6004005005 2.2.3 .2.2.312345 ( )200250300550200( / ) 2.2.4 ., ,2.2.4 /X X X X X X X X X X 12345 121312242131321134 x ij i j , c ij i j ,i =1,2,3;j =1,2,3,4,5; a i i ,i =1,2,3; b j j ,j =1,2,3,4,5.,2.2LINGO ·21·min z=3i=15j=1c ij x ij=2x11+x12+3x13+x14+2x15+4x21+2x22+x23+3x24+x25+2x31+x32+x33+3x34+4x35..(1) ,x11+x12+x13+x14+x15 600,x21+x22+x23+x24+x25 400,x31+x32+x33+x34+x35 500.,5j=1x ij a i,i=1,2,3.(2) ,x11+x21+x31=200,x12+x22+x32=250,x13+x23+x33=300, x14+x24+x34=550,x15+x25+x35=200.,3i=1x ij=b j,j=1,2,3,4,5.(3) , x ij 0, x ij ,i=1,2,3;j=1,2,3,4,5. LINGO .1., LINGO . ,LINGO .LINGO , , , “SETS ” , “ENDSETS” , ,setname/member/:attribute;setname ,member ,attribute . , ;“/” ,“:” , , . , a1,a2,a3,factory/1,2,3/:a;factory ,a , a , 1,2,3, a1,a2,a3. LINGO ,·22· 2a1,a2,a3 , a(1),a(2),a(3). , “..” , factory/1..3/:a;, , . , , , . , a1,a2,a3 d1,d2,d3,factory/1..3/:a,d;a d , .LINGO . ,factory/p1,p2,p3/:a;a(p1),a(p2),a(p3), a(1),a(2),a(3) .factory:a;a , a 3 , a . a(1),a(2),a(3) , ,factory/1,2,3/:;5 , b j(j=1,2,3,4,5), warehouse/1. .5/:b;( ), x ij c ij, , setname(parentset list) attribute; setname ( ), parentset , parentset .parentset list ,attribute , . , ( ). x ij c ij link(factory,warehouse):x,c; link, factory warehouse , x c, factory , warehouse 5 , x c 3×5 , x ij c ij(i=1,2,3;j=1,2,3,4,5). , , . 5×3 , , link(warehouse,factory):x,c; x ij c ij(i=1,2,3,4,5;j=1,2,3), 5×5 , link(warehouse,warehouse):x,c; x ij c ij(i=1,2,3,4,5;j= 1,2,3,4,5).2.2LINGO ·23·sets:factory/1,2,3/:a;warehouse/1..5/:b;link(factory,warehouse):x,c;endsets2.x ij , , LINGO , , “DATA ” , “ENDDATA” .a i , a=600,400,500; a(1)=600,a(2)=400,a(3)= 500. . , a(1)=600,a(2)= 400,a(3)=500; ,b j b=200,250,300,550,200;, , . a(1)= 20,a(2)=30,b(1)=15,b(2)=25, a,b=20,15,30,25; a,b= 20,30,15,25;c , , , , ,data:a=600,400,500;b=200,250,300,550,200;c=21312;42131;21134;enddata3., . LINGO , “@”.min z=3i=15j=1c ij x ij, LINGOmin=@sum(link(i,j):c(i,j)*x(i,j));,min , max .@sum , , , ,(i,j) ( ), i j ,(i,j) , ; , . @sum link(i,j), link , 2 , 3×5=15 ,·24· 2, 15 c (i,j )∗x (i,j ), , 3i =15 j =1c ij x ij ., ( ) . , i j , c (i,j )∗x (i,j ) , (i,j ) ,min=@sum(link:c*x); 5 j =1x ij a i ,i =1,2,3.3 , LINGO , @for ,@for(factory(i):@sum(warehouse(j):x(i,j))<a(i));@for , , , i , ; . factory i 3 , 3 . , j .@for @sum , x (i,j ) , i j , i j , x (i,j ) x (j,i ),@for (factory(j):@sum(warehouse(i):x(j,i))<a(j));, LINGO , , , . , i,j , @for @sum , i,j . , 3 i =1x ij =b j ,j =1,2,3,4,5 LINGO@for (warehouse(j):@sum(factory(i):x(i,j))=b(j)); x ij ,i =1,2,3;j =1,2,3,4,5 , @gin(x); i j , @for ,@for(link(i,j):@gin(x(i,j)););, LINGO , x ij 0 . x ij <0, @for , x ij , x ij , @free, @gin .4., LINGOmodel:! ;2.3R ·25·sets:factory/1,2,3/:a;warehouse/1..5/:b;link(factory,warehouse):x,c;endsets;! ;data:a=600,400,500;b=200,250,300,550,200;c=21312;42131;21134;enddata;min=@sum(link(i,j):c(i,j)*x(i,j));! ;@for(factory(i):@sum(warehouse(j):x(i,j))<a(i));! ;@for(warehouse(j):@sum(factory(i):x(i,j))=b(j));! ;@for(link(i,j):@gin(x(i,j)););! ;endLINGO , . , . Solve, Solution Report ., , 1700, 2.2.5 . 2.2.5````````````` 12345 1500055002002000200320020010000 @sum @for , , , . , , , .2.3RR , , .1976 , AT&T( ) Rick Becker,John Chambers Allan Wilks S , .R S , ,.R , ,R, .R , . , , . , R , , ,R .·26· 22.3.1R(/bin/windows/base/) R Windows , 2012 8 1 R version2.15.1(2012 6 22 ). (/) CRAN, CRAN Mirrors , (/CRAN/).R Windows2003 Windows2007 Windows .R , , R-2.15.1-win.exe, , ,R . R , R , 2.3.1 . R ,R Console , ( ) .R Console , R , “>” R , “>” .R , , , .2.3.1RR2.3.1 , 20 , 2.3.1 ( cm, kg).2.3.11117.519.58116191512123 211820.5911417.51611519 312020.51012526.517130.527 41252211117201811819.55117231211520.51912522 6119.52213116.5192011518 7120.528.51410917.5R Console#X1<-c(117.5,118,120,125,117,119.5,120.5,116,114,125,117,115,116.5, 109,121,115,130.5,118,125,115)X2<-c(19.5,20.5,20.5,22,23,22,28.5,19,17.5,26.5,20,20.5,19,17.5,23, 19,27,19.5,22,18)mean(X1)# ;mean(X2)# ;sd(X1)# ;plot(X1,X2)# ;hist(X1)# X1118.72521.2254.848969., 20 , 2.3.2 , 20 , 2.3.3 .2.3.2202.3.320,R . ,“#” , ,R . , . 2.3.1 ,“<-” ,c() ,X1<-c() X1;mean ,mean(X1) X1 ; sd ,sd(X1) X1 ;plot(X1,X2) X1 X2 ;hist(X1) X1 ., . R “ ” “ ” , R R , , , exam1.R. “ ” “ ” .R , “ ” , .2.3.2R , . x , 8,9,10.5,102 0.5,(1) x<-c(8,9,10.5,102,0.5)(2) assign assign( x ,c(8,9,10.5,102,0.5));(3)c(8,9,10.5,102,0.5)->x, y assign( y ,c(32,x,11.5)), y[1]32.08.09.010.5102.00.511.5R , (+) (-) (*) (/) (ˆ) , , .>x<−c(2,3,−4,0)>y<−c(5,10,10.5,9)>x−y[1]−3.0−7.0−14.5−9.0>x^2[1]49160>x*y[1]1030−420>x/y[1]0.40000000.3000000−0.38095240.0000000>x+y[1]7.013.06.59.0, 2.3.2 .R , , TRUE, , FALSE.>x<-c(2,3,-4,0);>x>2[1]FALSE TRUE FALSE FALSE,R , x i , x[i] .>x<-c(2,3,-4,0)>x[3][1]−4>x[2]<-100>x[1]2100−40>x[c(1,3)]<-c(100,200)# x 1 3 100 200 >x[1]1001002000>x[2:4]<-c(2,4,6)# x 2 4 2,4 6>x[1]1002462.3.2min(x) x length(x) xmax(x) x median(x) xrange(x) x mean(x) xsum(x) x var(x) xprod(x) x sd() x2.3.3(array) , , . , , , , ( ). , 1.(dim ) ,>x<-c(3,14,23,2,4,54,76,5,425,52,66,−4,−2,124,3);>dim(x)<−c(3,5) >x. . .1. arrayarray(data=NA,dim=length(data),dimnames=NULL),data ,dim ,dimnames , . >array(1:4,dim=c(3,3))2. matrix()matrix(data=NA,nrow=1,ncol=1,byrow=FALSE,dimnames= NULL) ,data ,nrow ,ncol ,by-row=TRUE , , byrow=FALSE, ,dimnames , .>mdat<-matrix(c(1,2,3,11,12,13),nrow=2,ncol=3,byrow=TRUE, dimnames=list(c("row1","row2"),c("C.1","C.2","C.3")))>mdatR , (+ − * /), , , dim . . , 2.3.3 .>A<-matrix(c(1,2,3,4),nrow=2)>B<-matrix(c(3,4,5,6),nrow=2,byrow=T)>t(A)# A>det(A)# A>A*B;A%*%B# A B>diag(A)# A>solve(A)# A>cbind(A,B)# A B>rbind(A,B)# A B>eigen(A)# A>svd(A)# A SVD2.3.41., , , . list(),>LIST<-list(name= ,age=17,score=c(90,88,70.5)), [[ ]], [[“”]], $ . , , , . . , >LIST[[1]]# LIST 1>LIST[[3]][3]# LIST 3 3>LIST[[ name ]]# LIST name, , “ ”,>LIST$name<-2.R , , . , . , . data.frame() , >dataframe<-data.frame(Name=c( , , ,, ),Sex=c( , , , , ),Age=c(12,13,14,12,13),Height=c(140,140.5,138.3,135.7,139));dataframe Name Sex Age Height Name Sex Age Height1 12140.04 12135.72 13140.55 13139.03 14138.3, .R . . , “ $ ” . ,R attach () , “ ” , .>attach(DF)# DF>r<-Score/Age;r[1]7.5000007.1153857.1428577.2500007.615385, edit() DF>DF.NEW<-edit(DF), DF , 2.3.4 . DF ,DF.NEW , , DF.NEW . edit() , .2.3.42.3.5, , . , . , . ,R . , , , .1.read.table() , data.txt , d:/program Files/R/chengxu/data.txt, , , read.table() , >X<-read.table("d:\\program Files\\R\\chengxu\\data.txt")# >X;is.data.frame(X), X , “data.txt” . ,X<-read.table("d:\\program Files\\R\\chengxu\\data.txt",header=TRUE), , X .read.table()read.table(file,header=FALSE,sep="",quote="\"’",dec=".",s,s;as.is=!stringsAsFactors,na.strings="NA",colClasses=NA,nrows=−1,skip=0,s=TRUE,fill=!blank.lines.skip,strip.white=FALSE,blank.lines.skip=TRUE,comment.char="#";allowEscapes=FALSE,flush=FALSE,stringsAsFactors=default.stringsAsFactors();fileEncoding="",encoding="unknown",text);file .header=TRUE ; ( ) .sep , .skip. .scan , , .2. SPSS SAS Stata Excel“foreign” , library(foreign), “ ” “ ” . SPSS (“data.sav”) SAS (“data.xpt”) Stata (“data.dta”). SPSS X<-read.spss( data.sav ), X , , X<-read.spss( data.sav ,to.data.frame=TRUE).SAS X1<-read.xport(”data.xpt”), X1 .Stata X2<-read.dta(”data.xpt”), X2 .Excel (data.xls) ,R . , Excel “ ( )”, 2.3.5 .,>X<-read.delim("d:\\program Files\\R\\chengxu\\data1.txt",header=TRUE)>X;is.data.frame(X)[1]TRUE2.3.5 ExcelExcel “CSV( )” , 2.3.6 . read.csv() , X<-read.csv( d:\\program Files\\R\\chengxu\\data1. csv ), X .R 50 , data() , data() , (base), , . data(co2). library , .2.3.6 Excel CSV3.write() ,write(x,file="data",ncolumns=if(is.character(x))1else5, append=FALSE,sep=""),x , ;file ( “data”);ap-pend=TRUE , , .>x<-matrix(1:20,ncol=5)>write(x,"d:\\program Files\\R\\chengxu\\foo.data",sep="\t")(d:/program Files/R/chengxu/) foo.data ., write.table() write.csv() , CSV Excel ,>dataframe<-data.frame(Name=c(" "," "," "," "," "),Sex=c(" "," "," "," "," "),Age=c(12,13,14,12,13), Height=c(140,140.5,138.3,135.7,139))>write.table(dataframe,file="d:\\program Files\\R\\chengxu\\foo. txt")>write.csv(dataframe,file="d:\\program Files\\R\\chengxu\\foo.csv") (d:/program Files/R/chengxu/) foo.txt foo.csv . .2.3.6R , . , , ( , ) . , . “{}” .R .1. if/else.if/elseif(cond)statement1if(cond)statement1else statement2cond , statement1; .cond , statement1; statement2.,if/elseif(cond1)statement1else if(cond2)statement2else if(cond3)statement3else statement42.break ,break , . next ,next , . break next , .3.R for ,for(name in expr1)expr2.name ,expr1 ( , 1:20),expr2 .2.3.2 ,4 A,A=⎛⎜⎜⎜⎜⎝0.50.60.50.70.40.50.40.50.50.60.50.70.30.50.30.5⎞⎟⎟⎟⎟⎠, R4 , W=(w1,w2,w3,w4)T=Q−1e/e T Q−1e, e=(1,1,···,1)T,Q=⎛⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎝4i=1a2i1−0.25−a12a21−a13a31−a14a41−a21a124i=1a2i2−0.25−a23a32−a24a42−a31a13−a32a233i=1a2i3−0.25−a34a43−a41a14−a42a24−a43a344i=1a2i4−0.25⎞⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎠.q<-matrix(0,4,4)A<-matrix(c(0.5,0.4,0.5,0.3,0.6,0.5,0.6,0.5,0.5,0.4,0.5,0.3,0.7,0.5,0.7,0.5),ncol=4)#for(i in2:4){for(j in1:(i-1)){q[i,j]=-A[i,j]*A[j,i]q[j,i]=q[i,j]}}for(i in1:4){for(k in1:4){q[i,i]=A[k,i]^2+q[i,i]}q[i,i]=q[i,i]-0.25}q#QQ1<-solve(q);>e<-matrix(c(1,1,1,1));e1<-t(e);w<-matrix(0,1,4) for(i in1:4){w[i]=((Q1%*%e)[i])/(e1%*%Q1%*%e)}w#A 4[,1][,2][,3][,4][1,]0.32379180.20037170.32379180.15204464 W=(0.324,0.200,0.324,0.152)T.2.3.7R , R , . R , , . ,R , mean() , R , .,2.3R ·37·>name <-function (arg 1,arg2,···)expressionexpression R ( ),arg 1,arg 2,··· ., ,.name(expr 1,expr 2,···). , , , “ R ”, source() . .2.3.3Ricker (population dynamics), .N t +1=N t exp r 1−N tK. Ricker, r N 0 .ricker.R, D:/Program Files/R/chengxu/ricker.R.2.3.7ricker2.3.8r =1,2 3>source("D:\\Program Files \\R \\chengxu \\ricker.R")# >layout(matrix(1:3,3,1))# 3·38· 2>ricker(0.1,1);title("r =1")#r=1 >ricker(0.1,2);title("r =2")#r=2 >ricker(0.1,3);title("r =3")#r=31. MATLAB ,(1) randn 10×10 A ;(2) B =(A +A T )/2;(3) B e 1,e 2,···,e 10;(4) i j ,e i e j 0.2. MATLAB myfun.m y =0.5exp(x/3)−x 2sin x , x,y . x .3. MATLAB fibo.m Fibonacci , ibo(n+2)=fibo(n+1)+fibo(n), fibo(1)=0,fibo(2)=1.4.x =cos(mθ),y =sin(nθ),m,n(1)m =n =1;(2)m =3,n =2.5. LINGO(1)s.t.max z =200x 1+300x 2,⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩x 1 100,x 2 120,x 1+2x 2 160,x i 0,i =1,2,(2)min z =cos x 1sin x 2−x 1/(x 2+1),s .t .−1 x 1 2,−1 x 2 1,(3)min z =−x 1−x 2,s .t .⎧⎪⎪⎨⎪⎪⎩x 2 2x 41−8x 31+8x 21+2,x 2 4x 41−32x 31+88x 21−96x 1+36,0 x 13,0 x 24.6. LINGO (1) x 2+y 2=1,0.75x 3−y +0.9=0,(2)x 2+y 2=2,2x 2+x +y 2+y =4.7. , , ,,, n , a i , , , b ,n b , , , , c i , x i =1·39·i ,x i =0 i ,max z =n i =1c i x i ,s .t .n i =1a i x i b,x i =0 1,i =1,2,···,n.8 , 1,3,4,3,3,1,5,10(kg), 2,9,3,8,10,6,4,10( ), 15kg, ,8. 1000m 3, 1200kg, 10 , 1, LINGO .11234567891047517622526226031882382 691829436182522967622112837918123123982241329. 3 A 1,A 2,A 3 4 B 1,B 2,B 3,B 4,3(a 1,a 2,a 3)=(30,25,21);4 (b 1,b 2,b 3,b 4)=(15,17,22,12),A iB j c ij ,C =⎛⎜⎜⎝626749538815⎞⎟⎟⎠, x ij A i B j , ,min z =3 i =14 j =1c ij x ij ,s .t .4 j =1x ij a i ,i =1,2,3;3 i =1x ij =b j ,j =1,2,3,4;x ij 0,i =1,2,3;j =1,2,3,4.LINGO .10. 8 4 , , 4 ,8 2 ( , ), .0-1 , Match(S i ,S j )=1 S i S j ,Match(S i ,S j )=0 S i S j , S i S j Benefit(S i ,S j ),max z =i<jBenefit(i,j )×Match(i,j ),s .t .⎧⎪⎨⎪⎩j =i k =iMatch(j,k )=1,i =1,2,3,4Match(i,j )∈{0,1}.·40· 2LINGO .2S1S2S3S4S5S6S7S8 S1-9342156 S2--173521 S3---44292 S4----1552 S5-----876 S6------23 S7-------411. 8 4 , 2 . , , , 3 , , LINGO .31 2 3 4 5 6 7 8 1-93421562--1735213---442924----15525-----8766------237-------48--------12. a=(5,9,6,2,11,13), R(1) a ;(2) a , ;(3) a .13. R , x=(2,3,4)T,y=(7,8,9)T,(1) z=8x+9y−2e, e=(1,1,0)T;(2) z=2x+y ;(3) x y .14. R 11,12,13,···,30 5×4 , A ,B ,(1)C=A+B;(2)D=A T·B;(3)E=(e ij)5×4, e ij=a ij·b ij;(4)F C 2 3 .15. R , 5 Hilbert H=(h ij)n×n,h ij=1i+j−1.(1) Hilbert H ;(2) H ;(3) H .16. 5 , 4 .(1) ;·41·(2) , read.table() .4(cm) (kg)1 1415642.02 1516549.03 1615741.54 1416252.05 1515945.517. R .A:79.9880.0480.0280.0480.0380.0479.9780.0580.0380.0280.0080.02B:80.0279.9479.9879.9780.0379.9579.97T .18. R ,x3−x−1=0[1,2] , ε=10−6.。