2*3 ans = 6 A=[1,2;3,4] A = 1 2 3 4 A*B ans = 70 100 150 220 B=[10,20;30,40] B = 10 20 30 40 A*B ans = 70 100 150 220 v=[10;11] v = 10 11 A*v ans = 32 74 A A = 1 2 3 4 w=[1,2] w = 1 2 w*v ans = 32 v v = 10 11 v*A ??? Error using ==> mtimes Inner matrix dimensions must agree. A^2 ans = 7 10 15 22 A*A ans = 7 10 15 22 w^2 ??? Error using ==> mpower Matrix must be square. w*w ??? Error using ==> mtimes Inner matrix dimensions must agree. w w = 1 2 w.*w ans = 1 4 w(1)*w(1) ans = 1 w(2)*w(2) ans = 4 A A = 1 2 3 4 A.^2 ans = 1 4 9 16 A^2 ans = 7 10 15 22 A*A ans = 7 10 15 22 w w = 1 2 v v = 10 11 w.*v ??? Error using ==> times Matrix dimensions must agree. v' ans = 10 11 w.*v' ans = 10 22 exp(1) ans = 2.7183 exp(2) ans = 7.3891 exp([1,2]) ans = 2.7183 7.3891 exp(A) ans = 2.7183 7.3891 20.0855 54.5982 sin(A) ans = 0.8415 0.9093 0.1411 -0.7568 v+w ??? Error using ==> plus Matrix dimensions must agree. v v = 10 11 w w = 1 2 v+w' ans = 11 13 v.+w' ??? v.+w' | Error: Unexpected MATLAB operator. v v = 10 11 v+1 ans = 11 12 10>9 ans = 1 9>10 ans = 0 A A = 1 2 3 4 A>2 ans = 0 0 1 1 A>B ans = 0 0 0 0 B B = 10 20 30 40 v=10:19 v = Columns 1 through 7 10 11 12 13 14 15 16 Columns 8 through 10 17 18 19 v>=15 ans = Columns 1 through 7 0 0 0 0 0 1 1 Columns 8 through 10 1 1 1 find(v>=15) ans = 6 7 8 9 10 v(6:10) ans = 15 16 17 18 19 index=find(v>=15) index = 6 7 8 9 10 v(index)=v(index)-15v(index) ??? v(index)=v(index)-15v(index) | Error: Unexpected MATLAB expression. v(index)=v(index)-15 v = Columns 1 through 7 10 11 12 13 14 0 1 Columns 8 through 10 2 3 4 w=[1,2,-5,6,7,-4] w = 1 2 -5 6 7 -4 index=find(w>=5) index = 4 5 w(index)=5 w = 1 2 -5 5 5 -4 w(find(w>=5))w(find(w>=5)) ??? w(find(w>=5))w(find(w>=5)) | Error: Unexpected MATLAB expression. w(find(w>=5)) ans = 5 5 A A = 1 2 3 4 find(A>2)4 ??? find(A>2)4 | Error: Unexpected MATLAB expression. find(A>2) ans = 2 4 index=find(A>2) index = 2 4 A(index) ans = 3 4 A A = 1 2 3 4 index=find(A>=3) index = 2 4 B(index)=1 B = 10 20 1 1 clear B B ??? Undefined function or variable 'B'. B(index)=1 B = 0 1 0 1 B=zeros(2,2) B = 0 0 0 0 B(index)=1 B = 0 0 1 1 A=[1,2,1;1,1,1;0,1,0] A = 1 2 1 1 1 1 0 1 0 b=[1;1;0] b = 1 1 0 x=[lambda;0;1-lambda] ??? Undefined function or variable 'lambda'. lambda=1 lambda = 1 x=[lambda;0;1-lambda] x = 1 0 0 A*x ans = 1 1 0 b b = 1 1 0 lambda=2 lambda = 2 x=[lambda;0;1-lambda] x = 2 0 -1 A*x ans = 1 1 0 A A = 1 2 1 1 1 1 0 1 0 A=[1,2;3,4] A = 1 2 3 4 b=[1;2] b = 1 2 x=A\b x = 0 0.5000 A*x ans = 1 2 b b = 1 2 A=[1,2,1;1,3,1;0,1,1;1,1,1] A = 1 2 1 1 3 1 0 1 1 1 1 1 b=[1;2;0;1] b = 1 2 0 1 x=A\b x = 0.8333 0.5000 -0.5000 A*x ans = 1.3333 1.8333 0.0000 0.8333 b b = 1 2 0 1 A A = 1 2 1 1 3 1 0 1 1 1 1 1 B=[1,2;3,4] B = 1 2 3 4 C=[2,3;4,5] C = 2 3 4 5 B*C ans = 10 13 22 29 C*B ans = 11 16 19 28 x x = 0.8333 0.5000 -0.5000 A\b ans = 0.8333 0.5000 -0.5000 A'*A ans = 3 6 3 6 15 7 3 7 4 A'*b ans = 4 9 4 x x = 0.8333 0.5000 -0.5000 (A'*A)\(A'*b) ans = 0.8333 0.5000 -0.5000 A\b ans = 0.8333 0.5000 -0.5000 A=[1,1,1;0,1,0] A = 1 1 1 0 1 0 b=[1;0] b = 1 0 A\b ans = 1 0 0 x=A\b x = 1 0 0 norm(x) ans = 1 y=[1/2;0;1/2] y = 0.5000 0 0.5000 A*y ans = 1 0 b b = 1 0 norm(y) ans = 0.7071 hilb(2) ans = 1.0000 0.5000 0.5000 0.3333 A=hilb(2) A = 1.0000 0.5000 0.5000 0.3333 x=[1;1] x = 1 1 b=A*x b = 1.5000 0.8333 A\b ans = 1.0000 1.0000 A=hilb(20) A = Columns 1 through 4 1.0000 0.5000 0.3333 0.2500 0.5000 0.3333 0.2500 0.2000 0.3333 0.2500 0.2000 0.1667 0.2500 0.2000 0.1667 0.1429 0.2000 0.1667 0.1429 0.1250 0.1667 0.1429 0.1250 0.1111 0.1429 0.1250 0.1111 0.1000 0.1250 0.1111 0.1000 0.0909 0.1111 0.1000 0.0909 0.0833 0.1000 0.0909 0.0833 0.0769 0.0909 0.0833 0.0769 0.0714 0.0833 0.0769 0.0714 0.0667 0.0769 0.0714 0.0667 0.0625 0.0714 0.0667 0.0625 0.0588 0.0667 0.0625 0.0588 0.0556 0.0625 0.0588 0.0556 0.0526 0.0588 0.0556 0.0526 0.0500 0.0556 0.0526 0.0500 0.0476 0.0526 0.0500 0.0476 0.0455 0.0500 0.0476 0.0455 0.0435 Columns 5 through 8 0.2000 0.1667 0.1429 0.1250 0.1667 0.1429 0.1250 0.1111 0.1429 0.1250 0.1111 0.1000 0.1250 0.1111 0.1000 0.0909 0.1111 0.1000 0.0909 0.0833 0.1000 0.0909 0.0833 0.0769 0.0909 0.0833 0.0769 0.0714 0.0833 0.0769 0.0714 0.0667 0.0769 0.0714 0.0667 0.0625 0.0714 0.0667 0.0625 0.0588 0.0667 0.0625 0.0588 0.0556 0.0625 0.0588 0.0556 0.0526 0.0588 0.0556 0.0526 0.0500 0.0556 0.0526 0.0500 0.0476 0.0526 0.0500 0.0476 0.0455 0.0500 0.0476 0.0455 0.0435 0.0476 0.0455 0.0435 0.0417 0.0455 0.0435 0.0417 0.0400 0.0435 0.0417 0.0400 0.0385 0.0417 0.0400 0.0385 0.0370 Columns 9 through 12 0.1111 0.1000 0.0909 0.0833 0.1000 0.0909 0.0833 0.0769 0.0909 0.0833 0.0769 0.0714 0.0833 0.0769 0.0714 0.0667 0.0769 0.0714 0.0667 0.0625 0.0714 0.0667 0.0625 0.0588 0.0667 0.0625 0.0588 0.0556 0.0625 0.0588 0.0556 0.0526 0.0588 0.0556 0.0526 0.0500 0.0556 0.0526 0.0500 0.0476 0.0526 0.0500 0.0476 0.0455 0.0500 0.0476 0.0455 0.0435 0.0476 0.0455 0.0435 0.0417 0.0455 0.0435 0.0417 0.0400 0.0435 0.0417 0.0400 0.0385 0.0417 0.0400 0.0385 0.0370 0.0400 0.0385 0.0370 0.0357 0.0385 0.0370 0.0357 0.0345 0.0370 0.0357 0.0345 0.0333 0.0357 0.0345 0.0333 0.0323 Columns 13 through 16 0.0769 0.0714 0.0667 0.0625 0.0714 0.0667 0.0625 0.0588 0.0667 0.0625 0.0588 0.0556 0.0625 0.0588 0.0556 0.0526 0.0588 0.0556 0.0526 0.0500 0.0556 0.0526 0.0500 0.0476 0.0526 0.0500 0.0476 0.0455 0.0500 0.0476 0.0455 0.0435 0.0476 0.0455 0.0435 0.0417 0.0455 0.0435 0.0417 0.0400 0.0435 0.0417 0.0400 0.0385 0.0417 0.0400 0.0385 0.0370 0.0400 0.0385 0.0370 0.0357 0.0385 0.0370 0.0357 0.0345 0.0370 0.0357 0.0345 0.0333 0.0357 0.0345 0.0333 0.0323 0.0345 0.0333 0.0323 0.0312 0.0333 0.0323 0.0312 0.0303 0.0323 0.0312 0.0303 0.0294 0.0312 0.0303 0.0294 0.0286 Columns 17 through 20 0.0588 0.0556 0.0526 0.0500 0.0556 0.0526 0.0500 0.0476 0.0526 0.0500 0.0476 0.0455 0.0500 0.0476 0.0455 0.0435 0.0476 0.0455 0.0435 0.0417 0.0455 0.0435 0.0417 0.0400 0.0435 0.0417 0.0400 0.0385 0.0417 0.0400 0.0385 0.0370 0.0400 0.0385 0.0370 0.0357 0.0385 0.0370 0.0357 0.0345 0.0370 0.0357 0.0345 0.0333 0.0357 0.0345 0.0333 0.0323 0.0345 0.0333 0.0323 0.0312 0.0333 0.0323 0.0312 0.0303 0.0323 0.0312 0.0303 0.0294 0.0312 0.0303 0.0294 0.0286 0.0303 0.0294 0.0286 0.0278 0.0294 0.0286 0.0278 0.0270 0.0286 0.0278 0.0270 0.0263 0.0278 0.0270 0.0263 0.0256 x=ones(20,1) x = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 b=A*x b = 3.5977 2.6454 2.1908 1.9010 1.6926 1.5326 1.4044 1.2986 1.2093 1.1327 1.0660 1.0074 0.9553 0.9087 0.8666 0.8286 0.7938 0.7620 0.7328 0.7058 A\b Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.022277e-19. ans = 1.0000 1.0000 1.0011 0.9820 1.1605 0.1614 3.6903 -4.3229 7.3634 -4.0209 6.4701 -8.6025 14.1165 -17.0399 29.4536 -30.1286 16.7031 2.1314 -3.3961 2.2777 x=A\b Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.022277e-19. x = 1.0000 1.0000 1.0011 0.9820 1.1605 0.1614 3.6903 -4.3229 7.3634 -4.0209 6.4701 -8.6025 14.1165 -17.0399 29.4536 -30.1286 16.7031 2.1314 -3.3961 2.2777 A*x-b ans = 1.0e-15 * 0 0 0 -0.2220 0.4441 0 0.6661 0.4441 0.6661 0.2220 0.4441 0.2220 0.1110 0.1110 0.3331 0.2220 0.3331 0.2220 0.4441 0.2220 cond(A) ans = 2.4819e+18 x=[-10,0,10] x = -10 0 10 3*x^2+4*x-1 ??? Error using ==> mpower Matrix must be square. x x = -10 0 10 x^2 ??? Error using ==> mpower Matrix must be square. x.^2 ans = 100 0 100 3*x.^2+4*x-1 ans = 259 -1 339 polyval([3,4,-1],x) ans = 259 -1 339 x=linspace(-10,10,100); y=polyval([3,4,-1],x); plot(x,y) x=[-10,0,10] x = -10 0 10 y=polyval([3,4,-1],x); plot(x,y) plot(x,y,'*') plot(x,y,'o') plot(x,y,'.') x=linspace(-10,10,100); y=polyval([3,4,-1],x); plot(x,y,'.') x=linspace(0,2*pi,6) x = Columns 1 through 4 0 1.2566 2.5133 3.7699 Columns 5 through 6 5.0265 6.2832 y=sin(x); a=polyfit(x,y,5); polyval(a,x) ans = Columns 1 through 4 0.0000 0.9511 0.5878 -0.5878 Columns 5 through 6 -0.9511 0.0000 y y = Columns 1 through 4 0 0.9511 0.5878 -0.5878 Columns 5 through 6 -0.9511 -0.0000 polyval(a,3*pi) ans = -25.0436 sin(3*pi) ans = 3.6739e-16 plot(x,y,'*') xx=linspace(0,2*pi,100); yy=sin(xx); plot(xx,yy) plot(x,y,'*',xx,yy), pp=polyval(a,xx); plot(x,y,'*',xx,yy,xx,pp) x=linspace(-5,5,11); y=1./(1+x.^2);./ ??? y=1./(1+x.^2);./ | Error: Unexpected MATLAB operator. y=1./(1+x.^2); a=polyfit(x,y,10); xx=linspace(-5,5,100); yy=1./(1+xx.^2); pp=polyval(a,xx); plot(x,y,'*',xx,yy,xx,pp) legend('nodi','funzione','polinomio') x x = Columns 1 through 7 -5 -4 -3 -2 -1 0 1 Columns 8 through 11 2 3 4 5 y y = Columns 1 through 4 0.0385 0.0588 0.1000 0.2000 Columns 5 through 8 0.5000 1.0000 0.5000 0.2000 Columns 9 through 11 0.1000 0.0588 0.0385 xx xx = Columns 1 through 4 -5.0000 -4.8990 -4.7980 -4.6970 Columns 5 through 8 -4.5960 -4.4949 -4.3939 -4.2929 Columns 9 through 12 -4.1919 -4.0909 -3.9899 -3.8889 Columns 13 through 16 -3.7879 -3.6869 -3.5859 -3.4848 Columns 17 through 20 -3.3838 -3.2828 -3.1818 -3.0808 Columns 21 through 24 -2.9798 -2.8788 -2.7778 -2.6768 Columns 25 through 28 -2.5758 -2.4747 -2.3737 -2.2727 Columns 29 through 32 -2.1717 -2.0707 -1.9697 -1.8687 Columns 33 through 36 -1.7677 -1.6667 -1.5657 -1.4646 Columns 37 through 40 -1.3636 -1.2626 -1.1616 -1.0606 Columns 41 through 44 -0.9596 -0.8586 -0.7576 -0.6566 Columns 45 through 48 -0.5556 -0.4545 -0.3535 -0.2525 Columns 49 through 52 -0.1515 -0.0505 0.0505 0.1515 Columns 53 through 56 0.2525 0.3535 0.4545 0.5556 Columns 57 through 60 0.6566 0.7576 0.8586 0.9596 Columns 61 through 64 1.0606 1.1616 1.2626 1.3636 Columns 65 through 68 1.4646 1.5657 1.6667 1.7677 Columns 69 through 72 1.8687 1.9697 2.0707 2.1717 Columns 73 through 76 2.2727 2.3737 2.4747 2.5758 Columns 77 through 80 2.6768 2.7778 2.8788 2.9798 Columns 81 through 84 3.0808 3.1818 3.2828 3.3838 Columns 85 through 88 3.4848 3.5859 3.6869 3.7879 Columns 89 through 92 3.8889 3.9899 4.0909 4.1919 Columns 93 through 96 4.2929 4.3939 4.4949 4.5960 Columns 97 through 100 4.6970 4.7980 4.8990 5.0000 ss=spline(x,y,xx);xx) ??? ss=spline(x,y,xx);xx) | Error: Unbalanced or unexpected parenthesis or bracket. ss=spline(x,y,xx); plot(x,y,'*',xx,yy,xx,ss) legend('nodi','funzione','spline') yerrore=y+(rand(size(y))-0.5)/10; plot(x,y,'*',x,yerrore,'o') x x = Columns 1 through 7 -5 -4 -3 -2 -1 0 1 Columns 8 through 11 2 3 4 5 y=2*x y = Columns 1 through 7 -10 -8 -6 -4 -2 0 2 Columns 8 through 11 4 6 8 10 plot(x,y,'*') yerrore=y+(rand(size(y))-0.5)/10; plot(x,y,'*',x,yerrore,'o') yerrore=y+(rand(size(y))-0.5)/5; plot(x,y,'*',x,yerrore,'o') yerrore=y+(rand(size(y))-0.5); plot(x,y,'*',x,yerrore,'o') a=polyfit(x,yerrore,1); pp=polyval(a,xx); plot(x,yerrore,'*',xx,pp) y=x.^2 y = Columns 1 through 7 25 16 9 4 1 0 1 Columns 8 through 11 4 9 16 25 yerrore=y+(rand(size(y))-0.5); plot(x,yerrore,'*') a=polyfit(x,yerrore,2); pp=polyval(a,xx); plot(x,yerrore,'*',xx,pp) diary off