Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is a Classroom License for instructional use only.
- Research and commercial use is prohibited.
- >> A = randi([-20,20], 5, 5);
- >> b = randi([-20,20],5,1);
- >> xM = A\b;
- >> r = A* xM - b
- r =
- 1.0e-13 *
- 0.1421
- 0
- -0.1421
- 0
- 0.0711
- >> residuo = norm(r)
- residuo =
- 2.1316e-14
- >> cond(A)
- ans =
- 36.8035
- >> % lu
- >> [L, U, P] = lu(A)
- L =
- 1.0000 0 0 0 0
- 1.0000 1.0000 0 0 0
- 0.7647 -0.3613 1.0000 0 0
- -0.8824 -0.2122 -0.8816 1.0000 0
- 0.2941 0.7731 -0.6118 0.3445 1.0000
- U =
- 17.0000 -9.0000 19.0000 -3.0000 -19.0000
- 0 28.0000 -20.0000 15.0000 37.0000
- 0 0 -35.7563 -7.2857 33.8992
- 0 0 0 11.1130 34.9700
- 0 0 0 0 -7.3269
- P =
- 0 1 0 0 0
- 0 0 0 1 0
- 1 0 0 0 0
- 0 0 1 0 0
- 0 0 0 0 1
- >> % PA = LU
- >> norm(P*A-LU)
- Undefined function or variable 'LU'.
- Did you mean:
- >> norm(P*A-L*U)
- ans =
- 5.0243e-15
- >> % risolvere Ax=b usando L,U,P
- >> % PAx = Pb, LUx = Pb --> Ly= PB, Ux = y
- >> % PAx = Pb, LUx = Pb --> Ly= Pb, Ux = y
- >>
- >> y = L\(P*b)
- y =
- 10.0000
- -4.0000
- 1.9076
- 5.6564
- -13.6305
- >> xlu = U\y
- xlu =
- -0.2072
- 2.2619
- 2.7995
- -5.3451
- 1.8603
- >> [xM xlu]
- ans =
- -0.2072 -0.2072
- 2.2619 2.2619
- 2.7995 2.7995
- -5.3451 -5.3451
- 1.8603 1.8603
- >> norm(xM-xlu)
- ans =
- 0
- >> % sbagliato
- >> % ultima PARTE
- >> dA = det(A)
- dA =
- -1.3858e+06
- >> A
- A =
- 13 -17 -14 -15 6
- 17 -9 19 -3 -19
- -15 2 19 17 14
- 17 19 -1 12 18
- 5 19 12 19 7
- >> @
- @
- |
- Error: Expression or statement is incomplete or incorrect.
- >> % PA = LU A=inv(P)*L*U
- >> inv(P)
- ans =
- 0 0 1 0 0
- 1 0 0 0 0
- 0 0 0 1 0
- 0 1 0 0 0
- 0 0 0 0 1
- >> P
- P =
- 0 1 0 0 0
- 0 0 0 1 0
- 1 0 0 0 0
- 0 0 1 0 0
- 0 0 0 0 1
- >> inv(P) - P'
- ans =
- 0 0 0 0 0
- 0 0 0 0 0
- 0 0 0 0 0
- 0 0 0 0 0
- 0 0 0 0 0
- >> % A = P' * L*U --> det(A) = det(P')*det(L)*det(U)
- >> det(P')
- ans =
- -1
- >> L
- L =
- 1.0000 0 0 0 0
- 1.0000 1.0000 0 0 0
- 0.7647 -0.3613 1.0000 0 0
- -0.8824 -0.2122 -0.8816 1.0000 0
- 0.2941 0.7731 -0.6118 0.3445 1.0000
- >> -prod(diag(U))
- ans =
- -1.3858e+06
- >> % calcolo l'inversa di A come sistema multiplo
- >> % A * inv(A) = I ----> A*X=I
- >> miainv = A\eye(size(A))
- miainv =
- 0.0418 0.0097 -0.0158 -0.0137 0.0573
- -0.1371 0.0268 0.0092 0.1464 -0.2047
- -0.1109 0.0588 0.0564 0.1396 -0.2169
- 0.2116 -0.0714 -0.0580 -0.2679 0.4295
- -0.0420 0.0135 0.0470 0.1003 -0.1365
- >> inv(A)
- ans =
- 0.0418 0.0097 -0.0158 -0.0137 0.0573
- -0.1371 0.0268 0.0092 0.1464 -0.2047
- -0.1109 0.0588 0.0564 0.1396 -0.2169
- 0.2116 -0.0714 -0.0580 -0.2679 0.4295
- -0.0420 0.0135 0.0470 0.1003 -0.1365
- >> norm(inv(A)-miainv)
- ans =
- 6.6138e-17
- >> eye(3,3)
- ans =
- 1 0 0
- 0 1 0
- 0 0 1
- >> norm(miainv-inv(A))
- ans =
- 6.6138e-17
- >> % calcolare l'inversa colonna per colonna usando
- >> % la fattorizzazione LUP
- >> Inva=zeros(size(A));
- >> id = eye(size(A);
- for j=1:size(A,2)
- InvA(:,j) = A\id(:,j);
- end
- id = eye(size(A);
- |
- Error: Unbalanced or unexpected parenthesis or bracket.
- >> id = eye(size(A);
- id = eye(size(A);
- |
- Error: Unbalanced or unexpected parenthesis or bracket.
- >> id = eye(size(A));
- >> for j=1:size(A,2)
- InvA(:,j) = A\id(:,j);
- end
- >> norm(inv(A)-InvA)
- ans =
- 6.6138e-17
- >> id
- id =
- 1 0 0 0 0
- 0 1 0 0 0
- 0 0 1 0 0
- 0 0 0 1 0
- 0 0 0 0 1
- >> id(:,0)
- Subscript indices must either be real positive integers or logicals.
- >> id(:,2)
- ans =
- 0
- 1
- 0
- 0
- 0
- >> % A casuale 2x2, generare 100 vettori sul cerchio unitario, trasformarli mediante A e .....
- >> A=rand(2,2); cond(A)
- ans =
- 24.2750
- >> A
- A =
- 0.7060 0.2769
- 0.0318 0.0462
- >> t = linspace(0,2*pi,200)
- t =
- Columns 1 through 10
- 0 0.0316 0.0631 0.0947 0.1263 0.1579 0.1894 0.2210 0.2526 0.2842
- Columns 11 through 20
- 0.3157 0.3473 0.3789 0.4105 0.4420 0.4736 0.5052 0.5368 0.5683 0.5999
- Columns 21 through 30
- 0.6315 0.6630 0.6946 0.7262 0.7578 0.7893 0.8209 0.8525 0.8841 0.9156
- Columns 31 through 40
- 0.9472 0.9788 1.0104 1.0419 1.0735 1.1051 1.1367 1.1682 1.1998 1.2314
- Columns 41 through 50
- 1.2630 1.2945 1.3261 1.3577 1.3892 1.4208 1.4524 1.4840 1.5155 1.5471
- Columns 51 through 60
- 1.5787 1.6103 1.6418 1.6734 1.7050 1.7366 1.7681 1.7997 1.8313 1.8629
- Columns 61 through 70
- 1.8944 1.9260 1.9576 1.9891 2.0207 2.0523 2.0839 2.1154 2.1470 2.1786
- Columns 71 through 80
- 2.2102 2.2417 2.2733 2.3049 2.3365 2.3680 2.3996 2.4312 2.4628 2.4943
- Columns 81 through 90
- 2.5259 2.5575 2.5891 2.6206 2.6522 2.6838 2.7153 2.7469 2.7785 2.8101
- Columns 91 through 100
- 2.8416 2.8732 2.9048 2.9364 2.9679 2.9995 3.0311 3.0627 3.0942 3.1258
- Columns 101 through 110
- 3.1574 3.1890 3.2205 3.2521 3.2837 3.3152 3.3468 3.3784 3.4100 3.4415
- Columns 111 through 120
- 3.4731 3.5047 3.5363 3.5678 3.5994 3.6310 3.6626 3.6941 3.7257 3.7573
- Columns 121 through 130
- 3.7889 3.8204 3.8520 3.8836 3.9152 3.9467 3.9783 4.0099 4.0414 4.0730
- Columns 131 through 140
- 4.1046 4.1362 4.1677 4.1993 4.2309 4.2625 4.2940 4.3256 4.3572 4.3888
- Columns 141 through 150
- 4.4203 4.4519 4.4835 4.5151 4.5466 4.5782 4.6098 4.6413 4.6729 4.7045
- Columns 151 through 160
- 4.7361 4.7676 4.7992 4.8308 4.8624 4.8939 4.9255 4.9571 4.9887 5.0202
- Columns 161 through 170
- 5.0518 5.0834 5.1150 5.1465 5.1781 5.2097 5.2413 5.2728 5.3044 5.3360
- Columns 171 through 180
- 5.3675 5.3991 5.4307 5.4623 5.4938 5.5254 5.5570 5.5886 5.6201 5.6517
- Columns 181 through 190
- 5.6833 5.7149 5.7464 5.7780 5.8096 5.8412 5.8727 5.9043 5.9359 5.9674
- Columns 191 through 200
- 5.9990 6.0306 6.0622 6.0937 6.1253 6.1569 6.1885 6.2200 6.2516 6.2832
- >> % A casuale 2x2, generare 200 vettori sul cerchio unitario, trasformarli mediante A e .....
- >> t = linspace(0,2*pi,200);
- >> x = cos(t); y = sin(t);
- >> hold on
- plot(x,y,'b'); axis equal;
- >> shg
- >> axis([-20 20 -20 20]);
- >> shg
- >> PCerchio = [x,y];
- >> PCerchio = [x;y];
- >> Ptransf = A*PCerchio;
- >> shg
- >> plot(Ptransf(1,:), Ptransf(2,:), 'r')
- >> plot(x,y,'b');
- >> hold on;
- >> plot(x,y,'b');
- >> plot(x,y,'b');
- >> plot(Ptransf(1,:), Ptransf(2,:), 'r')
- >> cond(A)
- ans =
- 24.2750
- >> A
- A =
- 0.7060 0.2769
- 0.0318 0.0462
- >> P=ginput(2)
- P =
- 0.3571 0.0497
- -0.2143 0.0205
- >> norm(P(1,:))/norm(P(2,:))
- ans =
- 1.6751
- >> P=ginput(2)
- Error using ginput (line 84)
- Interrupted by figure deletion
- >> plot(Ptransf(1,:), Ptransf(2,:), 'r')
- >> plot(x,y,'b');
- >> hold on
- >> plot(x,y,'b');
- >> plot(Ptransf(1,:), Ptransf(2,:), 'r')
- >> P=ginput(2)
- P =
- 0.7627 0.0497
- -0.0207 0.0322
- >> norm(P(1,:))/norm(P(2,:))
- ans =
- 19.9714
- >> % costruire una matrice 5x5 singolare
- >> % consiglio: ultima colonna è comb delle prime 4
- >> A = -2+4*rand(5,4);
- >> A = [A A*rand(4,1)]
- A =
- -1.6115 -1.8622 -1.2525 1.0187 -1.9751
- 1.2938 -0.2450 -0.0409 -0.8959 -0.3124
- 0.7793 -0.4738 -0.2177 0.7188 -0.1076
- -0.7316 1.0621 0.5853 0.6204 1.2151
- 1.8009 1.1808 0.8375 -1.3496 1.1471
- >> rank(A)
- ans =
- 4
- >> inv(A)
- Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.635734e-17.
- ans =
- 1.0e+15 *
- 0.2616 0.3779 -0.0057 0.4011 0.1279
- 1.0954 1.5829 -0.0237 1.6797 0.5356
- 2.1095 3.0482 -0.0457 3.2348 1.0315
- 0.7482 1.0811 -0.0162 1.1473 0.3659
- -2.1980 -3.1761 0.0476 -3.3705 -1.0748
- >> det(A)
- ans =
- 2.1596e-17
- >> format long
- >> det(A)
- ans =
- 2.159627605372215e-17
- >>
Advertisement
Add Comment
Please, Sign In to add comment