octave:2> xi=rand(4,2) xi = 0.427769 0.093895 0.390375 0.838197 0.231371 0.494721 0.490948 0.756559 octave:3> diffdiv1(xi) ans = 9.3895e-02 -1.9904e+01 -1.1235e+02 1.5970e+03 octave:4> v(1)=1 v = 1 octave:5> v(2)=2 v = 1 2 octave:6> w=zeros(4,1) w = 0 0 0 0 octave:7> w(1)=1 w = 1 0 0 0 octave:8> w(2)=2 w = 1 2 0 0 octave:9> diffdiv1(xi) ans = 9.3895e-02 -1.9904e+01 -1.1235e+02 1.5970e+03 octave:10> octave:10> xi(:,1) = linspace(-1,1,11)' error: A(I,J,...) = X: dimensions mismatch octave:10> xi xi = 0.427769 0.093895 0.390375 0.838197 0.231371 0.494721 0.490948 0.756559 octave:11> clear xi octave:12> xi(:,1) = linspace(-1,1,11)' xi = -1.00000 -0.80000 -0.60000 -0.40000 -0.20000 0.00000 0.20000 0.40000 0.60000 0.80000 1.00000 octave:13> xi(:,2) = exp(xi(:,1)) xi = -1.00000 0.36788 -0.80000 0.44933 -0.60000 0.54881 -0.40000 0.67032 -0.20000 0.81873 0.00000 1.00000 0.20000 1.22140 0.40000 1.49182 0.60000 1.82212 0.80000 2.22554 1.00000 2.71828 octave:14> x=linspace(-1,1,101); octave:15> y = intpolyvalnewt(x,xi); octave:16> plot(x,y,xi(:,1),xi(:,2),'o') octave:17> y = intpolyvalnewt(x,xi); octave:17> y = intpolyvalnewt(x,xi); octave:18> octave:18> y = intpolyvalnewt(x,xi); i = 1 i = 2 i = 3 i = 4 i = 5 i = 6 i = 7 i = 8 i = 9 i = 10 i = 11 octave:19> y = intpolyvalnewt(x,xi); i = 1 i = 2 i = 3 i = 4 i = 5 octave:19> xi(:,1)=[1;2;2;3] error: A(I,J,...) = X: dimensions mismatch octave:19> clear xi octave:20> xi(:,1)=[1;2;2;3] xi = 1 2 2 3 octave:21> n = 5; octave:22> xi = linspace (0, 2 * pi, n + 1)'; octave:23> xi(:, 2) = sin (xi(:, 1)); octave:24> x = linspace (0, 2 * pi, 101); octave:25> di = diffdiv2 (xi); octave:26> y = zeros (size (x)); octave:27> w = ones (size (x)); octave:28> for i = 1:n + 1 > y = y + di(i) * w; > w = w .* (x - xi(i, 1)); > end octave:29> plot (x, y, xi(:, 1), xi(:, 2), '*') octave:30> hold on octave:31> xfin = linspace (6, 7, 51); octave:32> plot (xfin, (xfin - 2 * pi)) octave:33> n = 5; octave:34> xi = linspace (0, 2 * pi, n)' xi = 0.00000 1.57080 3.14159 4.71239 6.28319 octave:35> xi = [xi; 2 * pi]; octave:36> xi xi = 0.00000 1.57080 3.14159 4.71239 6.28319 6.28319 octave:37> xi(1:n, 2) = sin (xi(1:n, 1)) xi = 0.00000 0.00000 1.57080 1.00000 3.14159 0.00000 4.71239 -1.00000 6.28319 -0.00000 6.28319 0.00000 octave:38> xi(n + 1, 2) = cos (xi(n + 1, 1)) xi = 0.00000 0.00000 1.57080 1.00000 3.14159 0.00000 4.71239 -1.00000 6.28319 -0.00000 6.28319 1.00000 octave:39> x = linspace (0, 2 * pi, 101); octave:40> di = diffdiv2 (xi); octave:41> y = zeros (size (x)); octave:42> w = ones (size (x)); octave:43> for i = 1:n + 1 > y = y + di(i) * w; > w = w .* (x - xi(i, 1)); > end octave:44> figure octave:45> plot (x, y, xi(1:n, 1), xi(1:n, 2), '*') octave:46> hold on octave:47> xfin = linspace (6, 7, 51); octave:48> plot (xfin, (xfin - 2 * pi)) octave:49> demo diffdiv2 diffdiv2 example 1: n = 5; xi = linspace (0, 2 * pi, n + 1)'; xi(:, 2) = sin (xi(:, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end plot (x, y, xi(:, 1), xi(:, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) Press to continue: octave:49> close all octave:50> demo diffdiv2 diffdiv2 example 1: n = 5; xi = linspace (0, 2 * pi, n + 1)'; xi(:, 2) = sin (xi(:, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end plot (x, y, xi(:, 1), xi(:, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) Press to continue: diffdiv2 example 2: n = 5; xi = linspace (0, 2 * pi, n)'; xi = [xi; 2 * pi]; xi(1:n, 2) = sin (xi(1:n, 1)); xi(n + 1, 2) = cos (xi(n + 1, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end plot (x, y, xi(1:n, 1), xi(1:n, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) octave:51> hold off octave:52> close all octave:53> demo diffdiv2 diffdiv2 example 1: n = 5; xi = linspace (0, 2 * pi, n + 1)'; xi(:, 2) = sin (xi(:, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end plot (x, y, xi(:, 1), xi(:, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) Press to continue: diffdiv2 example 2: n = 5; xi = linspace (0, 2 * pi, n)'; xi = [xi; 2 * pi]; xi(1:n, 2) = sin (xi(1:n, 1)); xi(n + 1, 2) = cos (xi(n + 1, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end plot (x, y, xi(1:n, 1), xi(1:n, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) octave:54> close all octave:55> demo diffdiv2 diffdiv2 example 1: n = 5; xi = linspace (0, 2 * pi, n + 1)'; xi(:, 2) = sin (xi(:, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end figure plot (x, y, xi(:, 1), xi(:, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) hold off Press to continue: diffdiv2 example 2: n = 5; xi = linspace (0, 2 * pi, n)'; xi = [xi; 2 * pi]; xi(1:n, 2) = sin (xi(1:n, 1)); xi(n + 1, 2) = cos (xi(n + 1, 1)); x = linspace (0, 2 * pi, 101); di = diffdiv2 (xi); y = zeros (size (x)); w = ones (size (x)); for i = 1:n + 1 y = y + di(i) * w; w = w .* (x - xi(i, 1)); end figure plot (x, y, xi(1:n, 1), xi(1:n, 2), '*') hold on xfin = linspace (6, 7, 51); plot (xfin, (xfin - 2 * pi)) hold off octave:56> x=rand(1,5) x = 0.030739 0.282647 0.770933 0.181057 0.367392 octave:57> sort(x) ans = 0.030739 0.181057 0.282647 0.367392 0.770933 octave:58> help sort 'sort' is a built-in function from the file libinterp/corefcn/data.cc -- Built-in Function: [S, I] = sort (X) -- Built-in Function: [S, I] = sort (X, DIM) -- Built-in Function: [S, I] = sort (X, MODE) -- Built-in Function: [S, I] = sort (X, DIM, MODE) Return a copy of X with the elements arranged in increasing order. For matrices, 'sort' orders the elements within columns For example: sort ([1, 2; 2, 3; 3, 1]) => 1 1 2 2 3 3 If the optional argument DIM is given, then the matrix is sorted along the dimension defined by DIM. The optional argument 'mode' defines the order in which the values will be sorted. Valid values of 'mode' are "ascend" or "descend". The 'sort' function may also be used to produce a matrix containing the original row indices of the elements in the sorted matrix. For example: [s, i] = sort ([1, 2; 2, 3; 3, 1]) => s = 1 1 2 2 3 3 => i = 1 3 2 1 3 2 For equal elements, the indices are such that equal elements are listed in the order in which they appeared in the original list. Sorting of complex entries is done first by magnitude ('abs (Z)') and for any ties by phase angle ('angle (z)'). For example: sort ([1+i; 1; 1-i]) => 1 + 0i 1 - 1i 1 + 1i NaN values are treated as being greater than any other value and are sorted to the end of the list. The 'sort' function may also be used to sort strings and cell arrays of strings, in which case ASCII dictionary order (uppercase 'A' precedes lowercase 'a') of the strings is used. The algorithm used in 'sort' is optimized for the sorting of partially ordered lists. See also: sortrows, issorted. Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list. octave:59> clear xi octave:60> xi(:,1)=[1;2;3;2] xi = 1 2 3 2 octave:61> xi(:,2)=[10;11;12;13] xi = 1 10 2 11 3 12 2 13 octave:62> xi([1,2,4,3],:) ans = 1 10 2 11 2 13 3 12 octave:63> sortrows(xi) ans = 1 10 2 11 2 13 3 12 octave:64> xi(:,3)=xi(:,2) xi = 1 10 10 2 11 11 3 12 12 2 13 13 octave:65> xi(:,2)=[0;1;0;0] xi = 1 0 10 2 1 11 3 0 12 2 0 13 octave:66> sortrows(xi) ans = 1 0 10 2 0 13 2 1 11 3 0 12 octave:67> temp=sortrows(xi) temp = 1 0 10 2 0 13 2 1 11 3 0 12 octave:68> temp(:,2)=[] temp = 1 10 2 13 2 11 3 12 octave:69> quit