t=-1:.5:1 t = -1.0000 -0.5000 0 0.5000 1.0000 t=t' t = -1.0000 -0.5000 0 0.5000 1.0000 y=[-1 -.5 0 .5 2]' y = -1.0000 -0.5000 0 0.5000 2.0000 y=[1 .5 0 .5 2]' y = 1.0000 0.5000 0 0.5000 2.0000 plot(t,y,'*') A=vander(t) A = 1.0000 -1.0000 1.0000 -1.0000 1.0000 0.0625 -0.1250 0.2500 -0.5000 1.0000 0 0 0 0 1.0000 0.0625 0.1250 0.2500 0.5000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 A=fliplr(A) A = 1.0000 -1.0000 1.0000 -1.0000 1.0000 1.0000 -0.5000 0.2500 -0.1250 0.0625 1.0000 0 0 0 0 1.0000 0.5000 0.2500 0.1250 0.0625 1.0000 1.0000 1.0000 1.0000 1.0000 y y = 1.0000 0.5000 0 0.5000 2.0000 x=A\b ??? Undefined function or variable 'b'. x=A\y x = -0.0000 -0.1667 2.1667 0.6667 -0.6667 help polyval POLYVAL Evaluate polynomial. Y = POLYVAL(P,X) returns the value of a polynomial P evaluated at X. P is a vector of length N+1 whose elements are the coefficients of the polynomial in descending powers. Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1) If X is a matrix or vector, the polynomial is evaluated at all points in X. See also polyvalm for evaluation in a matrix sense. [y,DELTA] = POLYVAL(p,x,S) uses the optional output structure s created by polyfit to generate prediction error estimates delta. delta is an estimate of the standard deviation of the error in predicting a future observation at x by P(X). If the coefficients in p are least squares estimates computed by polyfit, and the errors in the data input to polyfit are independent, normal, with constant variance, then y +/- delta will contain at least 50% of future observations at x. y = POLYVAL(p,x,[],MU) or [y,DELTA] = POLYVAL(p,x,s,MU) uses xhat = (X-MU(1))/MU(2) in place of x. The centering and scaling parameters mu are optional output computed by polyfit. Class support for inputs p,x,s,MU: float: double, single See also polyfit, polyvalm. Reference page in Help browser doc polyval x x = -0.0000 -0.1667 2.1667 0.6667 -0.6667 p=flipud(x) p = -0.6667 0.6667 2.1667 -0.1667 -0.0000 t t = -1.0000 -0.5000 0 0.5000 1.0000 tt=-1:.01:1 tt = Columns 1 through 7 -1.0000 -0.9900 -0.9800 -0.9700 -0.9600 -0.9500 -0.9400 Columns 8 through 14 -0.9300 -0.9200 -0.9100 -0.9000 -0.8900 -0.8800 -0.8700 Columns 15 through 21 -0.8600 -0.8500 -0.8400 -0.8300 -0.8200 -0.8100 -0.8000 Columns 22 through 28 -0.7900 -0.7800 -0.7700 -0.7600 -0.7500 -0.7400 -0.7300 Columns 29 through 35 -0.7200 -0.7100 -0.7000 -0.6900 -0.6800 -0.6700 -0.6600 Columns 36 through 42 -0.6500 -0.6400 -0.6300 -0.6200 -0.6100 -0.6000 -0.5900 Columns 43 through 49 -0.5800 -0.5700 -0.5600 -0.5500 -0.5400 -0.5300 -0.5200 Columns 50 through 56 -0.5100 -0.5000 -0.4900 -0.4800 -0.4700 -0.4600 -0.4500 Columns 57 through 63 -0.4400 -0.4300 -0.4200 -0.4100 -0.4000 -0.3900 -0.3800 Columns 64 through 70 -0.3700 -0.3600 -0.3500 -0.3400 -0.3300 -0.3200 -0.3100 Columns 71 through 77 -0.3000 -0.2900 -0.2800 -0.2700 -0.2600 -0.2500 -0.2400 Columns 78 through 84 -0.2300 -0.2200 -0.2100 -0.2000 -0.1900 -0.1800 -0.1700 Columns 85 through 91 -0.1600 -0.1500 -0.1400 -0.1300 -0.1200 -0.1100 -0.1000 Columns 92 through 98 -0.0900 -0.0800 -0.0700 -0.0600 -0.0500 -0.0400 -0.0300 Columns 99 through 105 -0.0200 -0.0100 0 0.0100 0.0200 0.0300 0.0400 Columns 106 through 112 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 Columns 113 through 119 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 Columns 120 through 126 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 Columns 127 through 133 0.2600 0.2700 0.2800 0.2900 0.3000 0.3100 0.3200 Columns 134 through 140 0.3300 0.3400 0.3500 0.3600 0.3700 0.3800 0.3900 Columns 141 through 147 0.4000 0.4100 0.4200 0.4300 0.4400 0.4500 0.4600 Columns 148 through 154 0.4700 0.4800 0.4900 0.5000 0.5100 0.5200 0.5300 Columns 155 through 161 0.5400 0.5500 0.5600 0.5700 0.5800 0.5900 0.6000 Columns 162 through 168 0.6100 0.6200 0.6300 0.6400 0.6500 0.6600 0.6700 Columns 169 through 175 0.6800 0.6900 0.7000 0.7100 0.7200 0.7300 0.7400 Columns 176 through 182 0.7500 0.7600 0.7700 0.7800 0.7900 0.8000 0.8100 Columns 183 through 189 0.8200 0.8300 0.8400 0.8500 0.8600 0.8700 0.8800 Columns 190 through 196 0.8900 0.9000 0.9100 0.9200 0.9300 0.9400 0.9500 Columns 197 through 201 0.9600 0.9700 0.9800 0.9900 1.0000 help polyval POLYVAL Evaluate polynomial. Y = POLYVAL(P,X) returns the value of a polynomial P evaluated at X. P is a vector of length N+1 whose elements are the coefficients of the polynomial in descending powers. Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1) If X is a matrix or vector, the polynomial is evaluated at all points in X. See also polyvalm for evaluation in a matrix sense. [y,DELTA] = POLYVAL(p,x,S) uses the optional output structure s created by polyfit to generate prediction error estimates delta. delta is an estimate of the standard deviation of the error in predicting a future observation at x by P(X). If the coefficients in p are least squares estimates computed by polyfit, and the errors in the data input to polyfit are independent, normal, with constant variance, then y +/- delta will contain at least 50% of future observations at x. y = POLYVAL(p,x,[],MU) or [y,DELTA] = POLYVAL(p,x,s,MU) uses xhat = (X-MU(1))/MU(2) in place of x. The centering and scaling parameters mu are optional output computed by polyfit. Class support for inputs p,x,s,MU: float: double, single See also polyfit, polyvalm. Reference page in Help browser doc polyval pv=polyval(p,tt) pv = Columns 1 through 7 1.0000 1.0013 1.0018 1.0016 1.0007 0.9992 0.9969 Columns 8 through 14 0.9940 0.9905 0.9863 0.9816 0.9763 0.9704 0.9640 Columns 15 through 21 0.9571 0.9497 0.9417 0.9334 0.9245 0.9153 0.9056 Columns 22 through 28 0.8955 0.8851 0.8742 0.8631 0.8516 0.8397 0.8276 Columns 29 through 35 0.8152 0.8025 0.7896 0.7764 0.7630 0.7494 0.7356 Columns 36 through 42 0.7217 0.7075 0.6932 0.6788 0.6643 0.6496 0.6348 Columns 43 through 49 0.6200 0.6051 0.5902 0.5752 0.5601 0.5451 0.5301 Columns 50 through 56 0.5150 0.5000 0.4850 0.4701 0.4552 0.4404 0.4257 Columns 57 through 63 0.4110 0.3965 0.3821 0.3678 0.3536 0.3396 0.3257 Columns 64 through 70 0.3120 0.2985 0.2852 0.2720 0.2591 0.2464 0.2339 Columns 71 through 77 0.2216 0.2096 0.1978 0.1863 0.1750 0.1641 0.1534 Columns 78 through 84 0.1430 0.1329 0.1231 0.1136 0.1044 0.0956 0.0871 Columns 85 through 91 0.0790 0.0712 0.0637 0.0566 0.0499 0.0436 0.0376 Columns 92 through 98 0.0320 0.0268 0.0220 0.0176 0.0137 0.0101 0.0069 Columns 99 through 105 0.0042 0.0019 -0.0000 -0.0014 -0.0025 -0.0030 -0.0032 Columns 106 through 112 -0.0028 -0.0021 -0.0008 0.0008 0.0030 0.0056 0.0087 Columns 113 through 119 0.0122 0.0162 0.0207 0.0257 0.0311 0.0370 0.0434 Columns 120 through 126 0.0503 0.0576 0.0654 0.0737 0.0825 0.0918 0.1016 Columns 127 through 133 0.1118 0.1225 0.1337 0.1454 0.1576 0.1703 0.1834 Columns 134 through 140 0.1970 0.2111 0.2257 0.2407 0.2562 0.2722 0.2887 Columns 141 through 147 0.3056 0.3230 0.3408 0.3592 0.3779 0.3972 0.4168 Columns 148 through 154 0.4370 0.4575 0.4786 0.5000 0.5219 0.5442 0.5669 Columns 155 through 161 0.5901 0.6137 0.6376 0.6620 0.6868 0.7120 0.7376 Columns 162 through 168 0.7636 0.7899 0.8166 0.8437 0.8712 0.8990 0.9271 Columns 169 through 175 0.9556 0.9844 1.0136 1.0431 1.0729 1.1030 1.1334 Columns 176 through 182 1.1641 1.1950 1.2263 1.2578 1.2896 1.3216 1.3539 Columns 183 through 189 1.3864 1.4191 1.4520 1.4852 1.5185 1.5520 1.5857 Columns 190 through 196 1.6196 1.6536 1.6878 1.7221 1.7565 1.7910 1.8257 Columns 197 through 201 1.8604 1.8952 1.9301 1.9650 2.0000 hold on plot(tt,pv,'r.') A A = 1.0000 -1.0000 1.0000 -1.0000 1.0000 1.0000 -0.5000 0.2500 -0.1250 0.0625 1.0000 0 0 0 0 1.0000 0.5000 0.2500 0.1250 0.0625 1.0000 1.0000 1.0000 1.0000 1.0000 A=A(:,1:3) A = 1.0000 -1.0000 1.0000 1.0000 -0.5000 0.2500 1.0000 0 0 1.0000 0.5000 0.2500 1.0000 1.0000 1.0000 x=A\y x = 0.0857 0.4000 1.4286 xx=A(1:3,:)\y(1:3) xx = 0 -1 0 p=flipud(x) p = 1.4286 0.4000 0.0857 pv=polyval(p,tt) pv = Columns 1 through 7 1.1143 1.0899 1.0657 1.0419 1.0183 0.9950 0.9720 Columns 8 through 14 0.9493 0.9269 0.9047 0.8829 0.8613 0.8400 0.8190 Columns 15 through 21 0.7983 0.7779 0.7577 0.7379 0.7183 0.6990 0.6800 Columns 22 through 28 0.6613 0.6429 0.6247 0.6069 0.5893 0.5720 0.5550 Columns 29 through 35 0.5383 0.5219 0.5057 0.4899 0.4743 0.4590 0.4440 Columns 36 through 42 0.4293 0.4149 0.4007 0.3869 0.3733 0.3600 0.3470 Columns 43 through 49 0.3343 0.3219 0.3097 0.2979 0.2863 0.2750 0.2640 Columns 50 through 56 0.2533 0.2429 0.2327 0.2229 0.2133 0.2040 0.1950 Columns 57 through 63 0.1863 0.1779 0.1697 0.1619 0.1543 0.1470 0.1400 Columns 64 through 70 0.1333 0.1269 0.1207 0.1149 0.1093 0.1040 0.0990 Columns 71 through 77 0.0943 0.0899 0.0857 0.0819 0.0783 0.0750 0.0720 Columns 78 through 84 0.0693 0.0669 0.0647 0.0629 0.0613 0.0600 0.0590 Columns 85 through 91 0.0583 0.0579 0.0577 0.0579 0.0583 0.0590 0.0600 Columns 92 through 98 0.0613 0.0629 0.0647 0.0669 0.0693 0.0720 0.0750 Columns 99 through 105 0.0783 0.0819 0.0857 0.0899 0.0943 0.0990 0.1040 Columns 106 through 112 0.1093 0.1149 0.1207 0.1269 0.1333 0.1400 0.1470 Columns 113 through 119 0.1543 0.1619 0.1697 0.1779 0.1863 0.1950 0.2040 Columns 120 through 126 0.2133 0.2229 0.2327 0.2429 0.2533 0.2640 0.2750 Columns 127 through 133 0.2863 0.2979 0.3097 0.3219 0.3343 0.3470 0.3600 Columns 134 through 140 0.3733 0.3869 0.4007 0.4149 0.4293 0.4440 0.4590 Columns 141 through 147 0.4743 0.4899 0.5057 0.5219 0.5383 0.5550 0.5720 Columns 148 through 154 0.5893 0.6069 0.6247 0.6429 0.6613 0.6800 0.6990 Columns 155 through 161 0.7183 0.7379 0.7577 0.7779 0.7983 0.8190 0.8400 Columns 162 through 168 0.8613 0.8829 0.9047 0.9269 0.9493 0.9720 0.9950 Columns 169 through 175 1.0183 1.0419 1.0657 1.0899 1.1143 1.1390 1.1640 Columns 176 through 182 1.1893 1.2149 1.2407 1.2669 1.2933 1.3200 1.3470 Columns 183 through 189 1.3743 1.4019 1.4297 1.4579 1.4863 1.5150 1.5440 Columns 190 through 196 1.5733 1.6029 1.6327 1.6629 1.6933 1.7240 1.7550 Columns 197 through 201 1.7863 1.8179 1.8497 1.8819 1.9143 plot(tt,pv,'m.') plot(t,y,'*') A A = 1.0000 -1.0000 1.0000 1.0000 -0.5000 0.2500 1.0000 0 0 1.0000 0.5000 0.2500 1.0000 1.0000 1.0000 x_ne=(A'*A)\(A'*b) ??? Undefined function or variable 'b'. x_ne=(A'*A)\(A'*y) x_ne = 0.0857 0.4000 1.4286 x x = 0.0857 0.4000 1.4286 format long x_ne x_ne = 0.08571428571429 0.40000000000000 1.42857142857143 x x = 0.08571428571429 0.40000000000000 1.42857142857143 eps=1e-4 eps = 1.000000000000000e-004 A=[1 0; eps 0; 0 eps] A = 1.00000000000000 0 0.00010000000000 0 0 0.00010000000000 cond(A) ans = 1.000000005000000e+004 B=A'*A B = 1.00000001000000 0 0 0.00000001000000 A(1,2)=1 A = 1.00000000000000 1.00000000000000 0.00010000000000 0 0 0.00010000000000 cond(A) ans = 1.414213565908629e+004 B=A'*A B = 1.00000001000000 1.00000000000000 1.00000000000000 1.00000001000000 cond(B) ans = 2.000000017978153e+008 A=rand(7,3) A = 0.95012928514718 0.01850364324822 0.17626614449462 0.23113851357429 0.82140716429525 0.40570621306210 0.60684258354179 0.44470336435319 0.93546969910761 0.48598246870930 0.61543234810009 0.91690443991341 0.89129896614890 0.79193703742704 0.41027020699095 0.76209683302739 0.92181297074480 0.89364953091353 0.45646766516834 0.73820724581067 0.05789130478427 A(:,3)=A(:,1)+A(:,2)+rand(7,1)*1e-6 A = 0.95012928514718 0.01850364324822 0.96863328126353 0.23113851357429 0.82140716429525 1.05254649103604 0.60684258354179 0.44470336435319 1.05154595775628 0.48598246870930 0.61543234810009 1.10141495570028 0.89129896614890 0.79193703742704 1.68323620634116 0.76209683302739 0.92181297074480 1.68391000249394 0.45646766516834 0.73820724581067 1.19467551477149 cond(A) ans = 1.002985674583390e+007 B=A'*A B = 3.14417571135679 2.52172510098107 5.66590201682648 2.52172510098107 3.27342353377351 5.79515018857355 5.66590201682648 5.79515018857355 11.46105496370887 cond(B) ans = 1.011139234967039e+014 theta=rand(1) theta = 0.27218792496996 Q=[cos(theta) sin(theta); -sin(theta) cos(theta)] Q = 0.96318500166862 0.26883945499242 -0.26883945499242 0.96318500166862 figure(2) plot(Q) A A = 0.95012928514718 0.01850364324822 0.96863328126353 0.23113851357429 0.82140716429525 1.05254649103604 0.60684258354179 0.44470336435319 1.05154595775628 0.48598246870930 0.61543234810009 1.10141495570028 0.89129896614890 0.79193703742704 1.68323620634116 0.76209683302739 0.92181297074480 1.68391000249394 0.45646766516834 0.73820724581067 1.19467551477149 [Q,R]=qr(A) Q = Columns 1 through 4 -0.53583280666272 0.66478729364967 0.47240218658380 0.10010398456997 -0.13035236403346 -0.56866996518120 0.59461585828032 -0.12176595572594 -0.34223359896889 0.03755472087769 -0.28333177086147 -0.39430192279281 -0.27407359637067 -0.20176156466687 -0.21411659092739 0.87562036889230 -0.50265499029763 -0.06892416648758 -0.24426317271729 -0.13217467938886 -0.42979044154668 -0.27769585949042 -0.33401413871659 -0.18766857684435 -0.25742849315506 -0.33269912497871 0.35484560853142 0.01666034080780 Columns 5 through 7 -0.09766582583730 0.13006806550193 -0.10630196936119 -0.06320652735884 -0.16150962206020 -0.51102577418425 -0.52213376942561 -0.60720633561267 0.06626990867833 -0.17022829947337 -0.18931852213283 -0.08246097926904 0.78543102189636 -0.20527697282474 -0.08007653124457 -0.26042841432116 0.71377674303022 -0.11865938017260 0.01183744497635 0.02898325421540 0.83418747063952 R = -1.77318236833011 -1.42214650112717 -3.19532954873802 0 -1.11844662952921 -1.11844715506368 0 0 0.00000071603367 0 0 0 0 0 0 0 0 0 0 0 0 format short Q Q = -0.5358 0.6648 0.4724 0.1001 -0.0977 0.1301 -0.1063 -0.1304 -0.5687 0.5946 -0.1218 -0.0632 -0.1615 -0.5110 -0.3422 0.0376 -0.2833 -0.3943 -0.5221 -0.6072 0.0663 -0.2741 -0.2018 -0.2141 0.8756 -0.1702 -0.1893 -0.0825 -0.5027 -0.0689 -0.2443 -0.1322 0.7854 -0.2053 -0.0801 -0.4298 -0.2777 -0.3340 -0.1877 -0.2604 0.7138 -0.1187 -0.2574 -0.3327 0.3548 0.0167 0.0118 0.0290 0.8342 Q'*Q ans = 1.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 1.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 0.0000 1.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 1.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 1.0000 format short e ans ans = Columns 1 through 5 1.0000e+000 -8.3267e-017 -8.3267e-017 -9.5410e-017 -1.4311e-017 -8.3267e-017 1.0000e+000 2.0817e-016 -6.9389e-017 5.2042e-018 -8.3267e-017 2.0817e-016 1.0000e+000 -4.3368e-017 -1.2143e-017 -9.5410e-017 -6.9389e-017 -4.3368e-017 1.0000e+000 -5.0876e-017 -1.4311e-017 5.2042e-018 -1.2143e-017 -5.0876e-017 1.0000e+000 5.3776e-017 -8.1532e-017 -8.1532e-017 -5.7842e-017 -6.3805e-017 -2.7756e-017 -5.5511e-017 5.5511e-017 -5.2042e-018 1.2143e-017 Columns 6 through 7 5.3776e-017 -2.7756e-017 -8.1532e-017 -5.5511e-017 -8.1532e-017 5.5511e-017 -5.7842e-017 -5.2042e-018 -6.3805e-017 1.2143e-017 1.0000e+000 -1.3878e-017 -1.3878e-017 1.0000e+000 x x = 8.5714e-002 4.0000e-001 1.4286e+000 x_ne x_ne = 8.5714e-002 4.0000e-001 1.4286e+000 A A = 9.5013e-001 1.8504e-002 9.6863e-001 2.3114e-001 8.2141e-001 1.0525e+000 6.0684e-001 4.4470e-001 1.0515e+000 4.8598e-001 6.1543e-001 1.1014e+000 8.9130e-001 7.9194e-001 1.6832e+000 7.6210e-001 9.2181e-001 1.6839e+000 4.5647e-001 7.3821e-001 1.1947e+000 b=rand(7,1) b = 1.9881e-001 1.5274e-002 7.4679e-001 4.4510e-001 9.3181e-001 4.6599e-001 4.1865e-001 x_back=A\b x_back = 6.1253e+005 6.1253e+005 -6.1253e+005 format long x_back x_back = 1.0e+005 * 6.12526161725053 6.12526170650753 -6.12525640369264 x_ne=(A'*A)\(A'*b) x_ne = 1.0e+005 * 6.15998173710904 6.15998184246404 -6.15997652333489 [Q,R]=qr(A) Q = Columns 1 through 4 -0.53583280666272 0.66478729364967 0.47240218658380 0.10010398456997 -0.13035236403346 -0.56866996518120 0.59461585828032 -0.12176595572594 -0.34223359896889 0.03755472087769 -0.28333177086147 -0.39430192279281 -0.27407359637067 -0.20176156466687 -0.21411659092739 0.87562036889230 -0.50265499029763 -0.06892416648758 -0.24426317271729 -0.13217467938886 -0.42979044154668 -0.27769585949042 -0.33401413871659 -0.18766857684435 -0.25742849315506 -0.33269912497871 0.35484560853142 0.01666034080780 Columns 5 through 7 -0.09766582583730 0.13006806550193 -0.10630196936119 -0.06320652735884 -0.16150962206020 -0.51102577418425 -0.52213376942561 -0.60720633561267 0.06626990867833 -0.17022829947337 -0.18931852213283 -0.08246097926904 0.78543102189636 -0.20527697282474 -0.08007653124457 -0.26042841432116 0.71377674303022 -0.11865938017260 0.01183744497635 0.02898325421540 0.83418747063952 R = -1.77318236833011 -1.42214650112717 -3.19532954873802 0 -1.11844662952921 -1.11844715506368 0 0 0.00000071603367 0 0 0 0 0 0 0 0 0 0 0 0 c=Q'*b c = -1.26251999267332 -0.27118820347161 -0.43858898373003 -0.09032121514744 0.12940084856907 -0.36085582038072 0.20316767394235 x=R\c(1:3) ??? Error using ==> mldivide Matrix dimensions must agree. x_qr=R(1:3,1:3)\c(1:3) x_qr = 1.0e+005 * 6.12526161520747 6.12526170446446 -6.12525640164957 x_back x_back = 1.0e+005 * 6.12526161725053 6.12526170650753 -6.12525640369264 x_ne x_ne = 1.0e+005 * 6.15998173710904 6.15998184246404 -6.15997652333489 close diary ??? Error using ==> close Specified window does not exist. help diary DIARY Save text of MATLAB session. DIARY FILENAME causes a copy of all subsequent command window input and most of the resulting command window output to be appended to the named file. If no file is specified, the file 'diary' is used. DIARY OFF suspends it. DIARY ON turns it back on. DIARY, by itself, toggles the diary state. Use the functional form of DIARY, such as DIARY('file'), when the file name is stored in a string. See also save. Reference page in Help browser doc diary diary off