linear-algebra

Finding coordinates of Koch Curve

时间秒杀一切 提交于 2021-02-19 07:37:40
问题 Sorry for my language since English is my second language. I am trying to convert a straight line into a fractal known as Koch curve. The 2 points of the straight line are given and then I need to create the Koch curve where I divide the line to 3 segments and then make the second segment an equilateral triangle. See http://www.tgmdev.be/curvevonkoch.php. So far we convert the straight line to 4 equally segments, and I need to figure out all the coordinates of the Koch curve. I have thought

Eigen linear algebra solvers seem slow

血红的双手。 提交于 2021-02-18 12:17:26
问题 I want to solve a linear algebraic equation Ax = b using Eigen solvers. In my case, A is a complex sparse matrix(26410*26410), b is a real vector (26410*1). I use mex file in MATLAB to map the sparse matrix A and vector b to Eigen accepted format. The reason why I use Eigen solver is to hope it would be faster than solving directly in MATLAB using x = A\b . However, after tried LDLT, SparseLU, CG and BiCGSTAB, I found the results are not very satisfying: LDLT takes 1.462s with norm(A*x - b)

How do I implement the Laplace expansion algorithm in c?

瘦欲@ 提交于 2021-02-10 07:21:54
问题 I'm having trouble figuring out a way to make this algorithm work, as I can't figure out how to do the middle part of the problem. Here's my code so far: int det(int matrixSize, int matrix[][matrixSize]){ int determinant = 0, matrixValues[matrixSize * matrixSize], matrixFirstRowValues[matrixSize * matrixSize]; for(int i = matrixSize; i > 2; i--){ for(int row = 0; row < matrixSize; row++){ for(int col = 0; col < matrixSize; col++){ matrixFirstRowValues[row + (matrixSize - i)] = matrix[1][col +

Issues using the scipy.sparse.linalg linear system solvers

社会主义新天地 提交于 2021-02-08 15:25:37
问题 I've got linear system to solve which consists of large, sparse matrices. I've been using the scipy.sparse library, and its linalg sub-library to do this, but I can't get some of the linear solvers to work. Here is a working example which reproduces the issue for me: from numpy.random import random from scipy.sparse import csc_matrix from scipy.sparse.linalg import spsolve, minres N = 10 A = csc_matrix( random(size = (N,N)) ) A = (A.T).dot(A) # force the matrix to be symmetric, as required by

How may I project vectors onto a plane defined by its orthogonal vector in Python?

守給你的承諾、 提交于 2021-02-08 13:43:13
问题 I have a plane, plane A , defined by its orthogonal vector, say (a, b, c) . (i.e. the vector (a, b, c) is orthogonal to plane A ) I wish to project a vector (d, e, f) onto plane A . How can I do it in Python? I think there must be some easy ways. 回答1: Take (d, e, f) and subtract off the projection of it onto the normalized normal to the plane (in your case (a, b, c) ). So: v = (d, e, f) - sum((d, e, f) *. (a, b, c)) * (a, b, c) / sum((a, b, c) *. (a, b, c)) Here, by *. I mean the component

Getting eigenvalues from 3x3 matrix in Python using Power method

不想你离开。 提交于 2021-02-08 08:41:48
问题 I'm trying to get all eigenvalues from a 3x3 matrix by using Power Method in Python. However my method returns diffrent eigenvalues from the correct ones for some reason. My matrix: A = [[1, 2, 3], [2, 4, 5], [3, 5,-1]] Correct eigenvalues: [ 8.54851285, -4.57408723, 0.02557437 ] Eigenvalues returned by my method: [ 8.5485128481521926, 4.5740872291939381, 9.148174458392436 ] So the first one is correct, second one has wrong sign and the third one is all wrong. I don't know what I'm doing

Scipy - find bases of column space of matrix

杀马特。学长 韩版系。学妹 提交于 2021-02-07 13:23:42
问题 I'm trying to code up a simple Simplex algorithm, the first step of which is to find a basic feasible solution: Choose a set B of linearly independent columns of A Set all components of x corresponding to the columns not in B to zero. Solve the m resulting equations to determine the components of x. These are the basic variables. I know the solution will involve using scipy.linalg.svd (or scipy.linalg.lu ) and some numpy.argwhere / numpy.where magic, but I'm not sure exactly how. Does anyone

How can I find out if A * B is a Hadamard or Dot Product in Numpy?

天涯浪子 提交于 2021-02-07 10:08:33
问题 If I see the following line in a python code where numpy is imported: c = a * b What is the easiest and most practical way to determine if this operation is executed as a Hadamard (elementwise) or dot product (pointwise) operation? Is it right that for a Hadamard product the column and row size of A and B must be the same. For a dot product only the column size of A must be the same as the row size of B, correct? So I can lookup the shape of both and find out which operation is used? 回答1:

How to calculate a rotation matrix in n dimensions given the point to rotate, an angle of rotation and an axis of rotation (n-2 subspace)

泄露秘密 提交于 2021-02-07 07:17:35
问题 I would like to calculate an (nxn) rotation matrix in the n-dimensional space given the following: The point to rotate. An angle of rotation. An axis of rotation (an (n-2) subspace that passes through the origin given by (n-2) unit vectors that span the subspace). the final rotated point. I think that number 4 (the final rotated point) is redundant and it is possible to calculate the rotation matrix without it. But I have them all. Is there a matlab function that already implements it? I know

Julia vs. MATLAB - Distance Matrix - Run Time Test

主宰稳场 提交于 2021-02-04 18:51:05
问题 I started learning Julia not a long time ago and I decided to do a simple comparison between Julia and Matlab on a simple code for computing Euclidean distance matrices from a set of high dimensional points. The task is simple and can be divided into two cases: Case 1: Given two datasets in the form of n x d matrices, say X1 and X2, compute the pair wise Euclidean distance between each point in X1 and all the points in X2. If X1 is of size n1 x d, and X2 is of size n2 x d, then the resulting