Vandermonde mátrix matlab-ban

Fórumok

Matlab-ban kellene vandermonde mátrix-ot előállítanom. Próbáltam neten keresgetni, de többnyire csak a matlab beépített függvényét találom meg, a vander() -t, amit persze nem szabad használni.
Amit eddig találtam, de nekem nem működik:


clear A
for i=1:n;
   for j=1:n;
      A(i,j) = x(i)^(n-j);
   end;
end;

Ötlet?

Hozzászólások


clear A
for i=1:n,
   for j=1:n,
      A(i,j) = x(i).^(n-j);
   end
end

n legyen egyenlő x hosszával és működik.

Ha függvény kell:


function A=vandermonde(x)

for i=1:length(x),
   for j=1:length(x),
      A(i,j) = x(i).^(length(x)-j);
   end
end

x a vektor, amiből a mátrixot csinálod. Ezt mentsd le vandermonde.m-be, majd hívj meg, mittudomén: A=vandermonde([1 2 3]) Ne felejtsd el a PATH-hoz hozzáadni...

>> A=vandermonde([1 2 3])
??? Undefined function or method 'vandermonde' for input arguments of type 'double'.

Ez a path miatt lenne? A current directory egyébként felül jól van kiválasztva. A path-ot is próbálgattam ugyanoda beállítani (amennyiben ez másra való mint a current directory):

>> PATH('D:\Matlab\work')
Warning: Could not find an exact (case-sensitive) match for 'PATH'.
D:\Matlab\toolbox\matlab\general\path.m is a case-insensitive match and will be used instead.
You can improve the performance of your code by using exact
name matches and we therefore recommend that you update your
usage accordingly. Alternatively, you can disable this warning using
warning('off','MATLAB:dispatcher:InexactMatch').

De a függvényhívásra ezek után is ugyanazt a hibát írja, amit fentebb írtam.
------------
szerk.: megoldódott a probléma. A fájl, amibe először elmentettem vander2.m volt, aztán elmentettem vandermonde.m -ként is és mostmár működik!
Köszi a helpet ;)

Vandermonde (általában) szerintem (nem vagyok Matlab szakértő):

for i=1:n; # sorok
for j=1:n; # oszlopok
V(i, j) = x(i)^(j-1);
end;
end;

A determinánsa (hátha az is kell ;-): az összes x(j) - x(i) különbséget össze kell szorozni, melyre 1 <= i < j <= n, ez n(n-1)/2 tényező.

Remélem, nem írtam el semmilyen indexet!
----------
Were antimatter present, its detection would be quite simple and straightforward. The most rudimentary detector suffices: simply place it down and wait. If the detector disappears, antimatter has been discovered - get out fast!