>> %more manipulations with matrices >> %suppose that we want to duplicate a column vector >> x=[2;6;7] x = 2 6 7 >> %we generate a matrix X 3x5, all of its columns equal the vector x: >> X=x(:,ones(1,5)) X = 2 2 2 2 2 6 6 6 6 6 7 7 7 7 7 >> %of course the `5' in the command can be changed to any number >> %suppose now that we would like to generate a vandermonde matrix >> % 3x3 based on the vector x, i.e., >> %V(i,j)=x(i)^{j-1} >> clear V >> clear X >> X=x(:,ones(1,3)) X = 2 2 2 6 6 6 7 7 7 >> %this is V, save the fact the powers are still missing >> %let's generate a matrix J that contains the powers: >> j=[2:-1:0]' j = 2 1 0 >> J=j(:,ones(1,3))' J = 2 1 0 2 1 0 2 1 0 >> V=X.^J V = 4 2 1 36 6 1 49 7 1 >> %do not forget to save, if you need. >> quit 9 flops. >> %---------------------- >> %--------------------- >> %below this point is the experiment with polynomial interpolation >> z=[0:.01:3.16]; >> fsin=sin(z); >> plot(z,fsin) >> %now we interpolate sin(z) at the interpolation points x >> x=[.5;1.5;2.5]; >> F=sin(x); >> hold on >> %from now until we type `hold off', the plots are made one on top of the >> %other >> inter >> x=[.5;.7;.9]; >> F=sin(x); >> inter >> x(4)=2; >> F(4)=sin(x(4)); >> inter >> x(5)=2.8; >> F(5)=sin(x(5)); >> inter >> hold off %++++++++++++++++++++++ %now, we will try interpolate 1/(1+t^2) on [0,3] >> fbell=1./(1+z.^2); >> plot(z,fbell) >> clear x,F >> x=[0:.5:3]'; >> F=1./(1+x.^2); >> plot(z,fbell) >> hold on >> inter >> p-fbell ans = Columns 1 through 7 0 0.0009 0.0017 0.0024 0.0030 0.0035 0.0039 Columns 8 through 14 0.0043 0.0045 0.0047 0.0048 0.0049 0.0049 0.0049 Columns 15 through 21 0.0048 0.0047 0.0046 0.0045 0.0043 0.0041 0.0040 Columns 22 through 28 0.0038 0.0036 0.0033 0.0031 0.0029 0.0027 0.0025 Columns 29 through 35 0.0023 0.0021 0.0019 0.0017 0.0015 0.0014 0.0012 Columns 36 through 42 0.0011 0.0009 0.0008 0.0007 0.0006 0.0005 0.0004 Columns 43 through 49 0.0003 0.0003 0.0002 0.0001 0.0001 0.0001 0.0000 Columns 50 through 56 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 Columns 57 through 63 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 Columns 64 through 70 0.0001 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 Columns 71 through 77 0.0003 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 Columns 78 through 84 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 Columns 85 through 91 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002 Columns 92 through 98 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0001 Columns 99 through 105 0.0001 0.0000 -0.0000 -0.0000 -0.0001 -0.0001 -0.0001 Columns 106 through 112 -0.0001 -0.0002 -0.0002 -0.0002 -0.0002 -0.0003 -0.0003 Columns 113 through 119 -0.0003 -0.0003 -0.0003 -0.0003 -0.0004 -0.0004 -0.0004 Columns 120 through 126 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 Columns 127 through 133 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 -0.0004 Columns 134 through 140 -0.0004 -0.0004 -0.0003 -0.0003 -0.0003 -0.0003 -0.0003 Columns 141 through 147 -0.0002 -0.0002 -0.0002 -0.0002 -0.0002 -0.0001 -0.0001 Columns 148 through 154 -0.0001 -0.0001 -0.0000 -0.0000 0.0000 0.0001 0.0001 Columns 155 through 161 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0003 Columns 162 through 168 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 Columns 169 through 175 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0005 Columns 176 through 182 0.0005 0.0005 0.0005 0.0005 0.0005 0.0004 0.0004 Columns 183 through 189 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0003 Columns 190 through 196 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0002 Columns 197 through 203 0.0001 0.0001 0.0001 0.0000 -0.0000 -0.0000 -0.0001 Columns 204 through 210 -0.0001 -0.0001 -0.0002 -0.0002 -0.0003 -0.0003 -0.0003 Columns 211 through 217 -0.0004 -0.0004 -0.0004 -0.0005 -0.0005 -0.0005 -0.0006 Columns 218 through 224 -0.0006 -0.0006 -0.0007 -0.0007 -0.0007 -0.0007 -0.0008 Columns 225 through 231 -0.0008 -0.0008 -0.0008 -0.0008 -0.0008 -0.0008 -0.0008 Columns 232 through 238 -0.0008 -0.0008 -0.0008 -0.0008 -0.0008 -0.0007 -0.0007 Columns 239 through 245 -0.0007 -0.0006 -0.0006 -0.0006 -0.0005 -0.0005 -0.0004 Columns 246 through 252 -0.0004 -0.0003 -0.0002 -0.0002 -0.0001 -0.0000 0.0001 Columns 253 through 259 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 Columns 260 through 266 0.0009 0.0010 0.0011 0.0012 0.0013 0.0014 0.0016 Columns 267 through 273 0.0017 0.0018 0.0019 0.0020 0.0021 0.0022 0.0023 Columns 274 through 280 0.0024 0.0025 0.0026 0.0027 0.0028 0.0029 0.0029 Columns 281 through 287 0.0030 0.0030 0.0030 0.0030 0.0030 0.0030 0.0030 Columns 288 through 294 0.0030 0.0029 0.0028 0.0027 0.0025 0.0024 0.0022 Columns 295 through 301 0.0020 0.0017 0.0015 0.0012 0.0008 0.0004 -0.0000 Columns 302 through 308 -0.0005 -0.0010 -0.0015 -0.0021 -0.0028 -0.0035 -0.0043 Columns 309 through 315 -0.0051 -0.0060 -0.0069 -0.0079 -0.0090 -0.0102 -0.0114 Columns 316 through 317 -0.0127 -0.0141 >> hold off >> plot(z,p-fbell) >> quit 52788 flops.