octave

Scipy.linalg.eig() giving different eigenvectors from GNU Octave's eig()

江枫思渺然 提交于 2019-12-22 12:26:50
问题 I want to compute the eigenvalues for a generalized eigenvalue problem with lambda * M * v = K * v, where lambda is the eigenvalue, v is an eigenvector, and M and K are matrices. Let's say we have K = 1.8000 + 0.0000i -1.0970 + 0.9550i -1.0970 - 0.9550i 1.8000 + 0.0000i M = 209 0 0 209 In Octave, if I do [V,D]=eig(K,M) , I get: V = 0.53332 - 0.46429i -0.53332 + 0.46429i 0.70711 + 0.00000i 0.70711 + 0.00000i D = Diagonal Matrix 0.34555 0 0 3.25445 However, if I do scipy.linalg.eig(K, b=M)

Subtracting multiple vectors from each row of an array (super broadcasting)

我的梦境 提交于 2019-12-22 10:36:39
问题 I have a data set, X that is m x 2 , and three vectors stored in a matrix C = [c1'; c2'; c3'] that is 3 x 2 . I am trying to vectorize my code that finds, for each data point in X , which vector in C is closest (squared distance). I would like to subtract each vector (row) in C from each vector (row) in X , resulting in an m x 6 or 3m x 2 matrix of differences between the elements of X and the elements of C . My current implementation does this one row in X at a time: for i = 1:size(X, 1)

Octave plot points as animation

若如初见. 提交于 2019-12-22 08:37:34
问题 I have the following octave script, TOTAL_POINTS = 100; figure(1) for i=1:TOTAL_POINTS randX = rand(1); randY = rand(1); scatter(randX, randY); hold on; endfor When I run this by octave script.m , I get nothing. When I add the line pause to the end of this script, it works but I only see the plot after all the 100 points are plotted. I want to see the plot point by point. Not after I plotted every single point. PS: I have Ubuntu . 回答1: Try adding drawnow at the end of the iteration. At least

What is the fastest way to write a matrix to a text file in Octave?

徘徊边缘 提交于 2019-12-22 02:04:00
问题 I have a large matrix (2e6 x 3) which I have to write to a text file. dlmwrite takes about 230s to achieve this task. From your experience what is the fastest way to write a large matrix to a text file? 回答1: The following applies to MATLAB, but I suggest you try it in Octave. First of all, if you can - transpose the matrix. Here are examples using fprintf and csvwrite (essentially dlmwrite ) A = rand(3, 1e6); tic; fid = fopen('data.txt', 'w+'); for i=1:size(A, 1) fprintf(fid, '%f ', A(i,:));

What is the fastest way to write a matrix to a text file in Octave?

和自甴很熟 提交于 2019-12-22 02:02:50
问题 I have a large matrix (2e6 x 3) which I have to write to a text file. dlmwrite takes about 230s to achieve this task. From your experience what is the fastest way to write a large matrix to a text file? 回答1: The following applies to MATLAB, but I suggest you try it in Octave. First of all, if you can - transpose the matrix. Here are examples using fprintf and csvwrite (essentially dlmwrite ) A = rand(3, 1e6); tic; fid = fopen('data.txt', 'w+'); for i=1:size(A, 1) fprintf(fid, '%f ', A(i,:));

Warnings after octave installation

走远了吗. 提交于 2019-12-21 20:44:28
问题 I am getting following warning after launching octave. i used installation instruction from here. What could be the issue? Are these major warnings? I am using windows. warning: gmsh does not seem to be present some functionalities will be disabled warning: dx does not seem to be present some functionalities will be disabled warning: function C:\Octave\Octave3.6.0_gcc4.6.2\share\octave\packages\statistics- 1.1.0\fstat.m shadows a core library function 回答1: That's because you have installed

Inferior octave freezes

 ̄綄美尐妖づ 提交于 2019-12-21 17:20:15
问题 In emacs octave-mode, when I type M-x run-octave the command freezes so I do C-g to escape. I can switch to the *Inferior Octave* buffer with C-x b but there is no prompt, just the welcome message. C-c i l also does not work. 回答1: With Emacs 24.3.1 simply add PS1(">> ") to ~/.octaverc . No need to change the value of 'inferior-octave-prompt'. 回答2: From http://savannah.gnu.org/bugs/?41099#comment4: Add PS1(">> ") to ~/.octaverc Add (setq inferior-octave-prompt ">> ") to ~/.emacs.d/init.el (or

finding the best/ scale/shift between two vectors

久未见 提交于 2019-12-21 12:25:33
问题 I have two vectors that represents a function f(x), and another vector f(a x+b) i.e. a scaled and shifted version of f(x). I would like to find the best scale and shift factors. *best - by means of least squares error , maximum likelihood, etc. any ideas? for example: f1 = [0;0.450541598502498;0.0838213779969326;0.228976968716819;0.91333736150167;0.152378018969223;0.825816977489547;0.538342435260057;0.996134716626885;0.0781755287531837;0.442678269775446;0]; f2 = [-0.029171964726699;-0

Octave imread function

流过昼夜 提交于 2019-12-21 10:55:22
问题 I installed latest Octave on Ubuntu 14.04 machine. However, when I tried to run imread command, it showed the following error message: octave:12> imread('newfile.png') error: imread: invalid image file: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: failed to load: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: undefined symbol: _ZN6Magick5ColorC1Ehhh error: called from: error: /usr/share/octave/3.8.1/m/image/private/_

Efficient Array Preallocation in MATLAB

百般思念 提交于 2019-12-21 07:53:28
问题 One of the first things one learns about programming efficiently in MATLAB is to avoid dynamically resizing arrays. The standard example is as follows. N = 1000; % Method 0: Bad clear a for i=1:N a(i) = cos(i); end % Method 1: Better clear a; a = zeros(N,1); for i=1:N a(i) = cos(i) end The 'Bad' variant here requires O( N ^2) time to run, as it must allocate a new array and copy the old values at each iteration of the loop. My own preferred practice when debugging is to allocate an array with