Key to MATLAB Exercise 1 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu Key to MatLAB Exersise 1-Matrices arrays 1.>>x0=10,0=15;t5;a=9.81;x=x0+v0*+1/2*a*t2 >>X=3;v=4; 1)>>log(x^2+v^2) 2)>(X-3)^(1/2)(x-2*v)^2 4)>>abs(sin(2 x))exp(v) 5)>sqr(x-5) 6)>>x/(v-4) Warning: Divide by zero. ans=Inf arnI ide by zero. ans=-lnf 9)>>(x-3 (v-4) Warning: Divide by zero. ans= NaN 3. ans =2 ans=0.5000 4.1)>d=[23:-3:2 > numen(d) >>d=[23,20,17,14,11,8,5,2] l(d) 2)>>a=234 6912] >>a=[1:4;22:8,3:3:12] 5.1)>>sze(a) 2)>a(2,3) >>b=a(:1,3]) 3)>>c=a(1,32]-) 7)omited 8)>>a35=a;a35(:5)=[l;1;1 >>aa35=a,[10;20;30J 4=a;a44(4)=[l111 Key to ExI-1
Key to MATLAB Exercise 1 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex11 Key to MATLAB Exersise 1 Matrices & Arrays 1. >> x0=10; v0=15; t=5; a=9.81; x=x0+v0*t+1/2*a*t^2 2. >> x=3;v=4; 1) >> log(x^2+v^2) 2) >> (x3)^(1/2)/(x2*v)^2 3) >> 4/3*pi*v^2 4) >> abs(sin(2*x))*exp(v) 5) >> sqrt(x5) or >> (x5)^(1/2) 6) >> x/(v4) Warning: Divide by zero. ans =Inf 7) >> x/(v4) Warning: Divide by zero. ans =Inf 8) >> eps 9) >> (x3)/(v4) Warning: Divide by zero. ans = NaN 3. ans = 2 ans = 0.5000 4. 1) >> d=[23:3:2] >> numel(d) or >> d=[23,20,17,14,11,8,5,2] >> numel(d) 2) >> a=[1 2 3 4 2 4 6 8 3 6 9 12]; or >> a = [1:4; 2:2:8; 3:3:12]; or >> a1 =[1:4]; a = [a1; 2*a1; 3*a1]; 5. 1) >> size(a) 2) >> a(2,3) >> b=a(:,[1,3]) 3) >> c=a([1,3,2],:) 4) >> x=a(:,end) 5) >> a(1,1)=0 6) omited 7) omited 8) >> a35=a; a35(:,5)=[1;1;1] or >> aa35=[a, [10; 20; 30]] >> a44=a; a44(4,:)=[1 1 1 1] or >> a44=(a; 1 1 1 1)
Key to MATLAB Exercise 1 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu 9)-14)omited 6.>>x=AB -0.5000 -0.5000 A/B ?? Error using=> mrdivide matrix dimensions must agree A/B is equivalent to the expression AB, but here B is a vector, there is no invert of B 8.1)>>X=0nes(6,1);A*x 0 0 0 0 0 From A*x, we get the sum of every row of A, so we know that the determinant of a equal to 0. that is a must be singular 9.>>A= magIc(8),sum(A(:,1:7) ans=260260260260260260260 10.>>a=[121;A=aa*2a*3];C=-1-1-l},D=-2-24 1)>>A°C >>A*D The results show that though A#0, AC=AD, but C is not equal to D. Therefore the proposition Is not true 2)>>A-round(10"rand( 3)); B-round(10*rand(3)) >>inv(A+B > inv(A)+inv(B) The proposition is not true 3)>(A+By2 >>A^2+2*A*B+B^2 The proposition is not true 4)>>A-round(10*rand(3)); B=A+A >>B=B We may try it more times. All results show the proposition is true Key to Ex1-2
Key to MATLAB Exercise 1 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex12 9)14) omited 6. >> x=A\B ans x= 0.5000 1.0000 0.5000 7. >> A/B ??? Error using ==> mrdivide matrix dimensions must agree. A/B is equivalent to the expression 1 AB - , but here B is a vector, there is no invert of B. 8. 1) >> x=ones(6,1); A*x ans = 0 0 0 0 0 0 From A*x, we get the sum of every row of A, so we know that the determinant of A equal to 0, that is A must be singular. 2) omited 9. >> A = magic (8); sum(A(:,1:7)) ans =260 260 260 260 260 260 260 10. >> a=[1 2 1]; A=[a;a*2;a*3]; C=[1 11]'; D=[2 2 4]'; 1) >> A*C >> A*D The results show that though A≠0, AC=AD, but C is not equal to D. Therefore the proposition is not true. 2) >> A=round(10*rand(3)); B=round(10*rand(3)); >> inv(A+B) >> inv(A)+inv(B) The proposition is not true. 3) >> (A+B)^2 >> A^2+2*A*B+B^2 The proposition is not true. 4) >> A=round(10*rand(3)); B=A+A’; >> B == B’ ans = 1 1 1 1 1 1 1 1 1 We may try it more times. All results show the proposition is true. 11. omited