Hot answers tagged

30 votes
Accepted

Add a vector to a list of vectors

I recommend using Transpose twice since it is more efficient than other approaches. Moreover Plus has the ...
user avatar
  • 54k
27 votes
Accepted

How can I reproduce a beautiful 3D vector plot?

Nice "inverse problem". The angle distribution looks to me like a Gaussian. ...
user avatar
21 votes
Accepted

Animate a circle "rolling" along a complicated 3D curve

EDIT As OP wishes (and as Rahul correctly points out) my original answer puts unit circle in TB plane (my error as labels suggest) and what is desired is TN plane. ...
user avatar
  • 55k
20 votes
Accepted

How to detect loops in a vector field?

Maybe you can transform this into an easier problem: If you were instead looking for lines that are at any point perpendicular to your vector field: (that's easy, it's just a coordinate ...
user avatar
  • 35.4k
17 votes
Accepted

Orthogonal vector in two dimensions

It's already built-in. It's called Cross. Cross[{1, 2}] Output is {-2, 1}
user avatar
17 votes
Accepted

How to make Mathematica show matrices and vectors nicely

Add this to your notebook or init file $PrePrint = If[MatrixQ[#], MatrixForm[#], #] &; Then all matrices will automatically display as ...
user avatar
  • 108k
17 votes

Add a vector to a list of vectors

To achieve what you need requires to distribute the sum over v2: (v1 + # &) /@ v2 which is a short form of: ...
user avatar
  • 1,542
15 votes
Accepted

How to find the magnitude of a vector?

Norm in general assumes complex arguments and uses Abs to provide for that: Norm[{x, y}] Sqrt[Abs[x]^2 + Abs[y]^2] For ...
user avatar
  • 14.9k
15 votes
Accepted

VectorPlot3D - vectors starting at points

Update V.11.3: In version 11.3+ the new option VectorMarkers can be used with Placed to control the position of vectors: ...
user avatar
  • 349k
14 votes

VectorScale Explanation

The option VectorPoints determines how many vector boxes there are. The plot domain is subdivided into a grid, whose grid points span the plot domain in each ...
user avatar
  • 213k
14 votes
Accepted

Defining quantum-mechanical Bra and Ket operations

The definition of the scalar product in your question assumes that all your kets are orthogonal unit vectors. In that case, the most natural approach would be to use the built-in ...
user avatar
  • 95k
14 votes
Accepted

Remove Abs from Norms of Vectors

expr = Norm[{a, b*c}] Sqrt[Abs[a]^2 + Abs[b c]^2] Since ComplexExpand assumes all its variables to be real, we ...
user avatar
13 votes
Accepted

How to calculate a list without loop?

Accumulate@Array[b, {3}] (* {b[1], b[1] + b[2], b[1] + b[2] + b[3]} *) therefore: ...
user avatar
12 votes

Is it possible to do vector calculus in Mathematica?

Our package VEST (Vector Einstein Summation Tools) is designed to do exactly this. It's described here and can be downloaded from github along with a tutorial. I realize this question is now very ...
user avatar
  • 291
12 votes

Vectors with a certain magnitude in Mathematica

RandomPoint makes this a one liner (as of version 10.2): RandomPoint[Sphere[{0, 0, 0}, 4]] ...
user avatar
  • 32.7k
12 votes
Accepted

Complex result for Real vectors in VectorAngle

I believe this is one of the many manifestations of machine precision arithmetic in Mathematica, and it appears because VectorAngle also works with complex values. ...
user avatar
  • 264k
12 votes
Accepted

stream plot 2d cross section

You may use SliceVectorPlot3D. ...
user avatar
  • 39.3k
12 votes

How do I determine if two 2d vector parallel?

Based on the definition of the scalar product for $d$-dimensional vectos \begin{equation} a \cdot b = |a| |b| \cos(\phi) \end{equation} you can create a test based only on vector operations. The ...
user avatar
12 votes

How can I reliably plot ellipse-field streamlines?

Use NDSolve to solve for y(x) Perhaps this serves as a starting point. Shown below is the case when b = -1. Each streamline is obtained from ...
user avatar
  • 5,059
12 votes
Accepted

Can we turn this for loop into a more elegant Mathematica code?

Apparently, you try to apply a permutation given by list indirection to a vector duplicate. Here are several ways to do it, ...
user avatar
11 votes

"NotAvailable" and "NotApplicable" data points returned by WeatherData[]

NB I think there's a problem with this code, please see this answer by ubpdqn for more information. I'll update these snippets when I get the chance. Yours is a question with many possible ...
user avatar
  • 1,491
11 votes

Complex result for Real vectors in VectorAngle

Just found this. This is probably a good opportunity to demonstrate the importance of using a numerically stable formula. I will use a simpler example: ...
user avatar
11 votes

How do I sum the products of the elements of a vector?

SymmetricPolynomial is the built-in way to get the sums you want: ...
user avatar
  • 33.5k
11 votes

Remove Abs from Norms of Vectors

If you have to use FullSimplify or Simplify, you can use the option ComplexityFunction to ...
user avatar
  • 349k
10 votes

Using the epsilon tensor in Mathematica

The symbol $\epsilon$ is called the Levi-Civita tensor, it is usually written in terms of its components $\epsilon_{i j k}$. Having defined two vectors (i.e. first order contravariant tensors): <...
user avatar
  • 54k
10 votes

How to detect loops in a vector field?

The following is far from perfect, just a kickstart: ...
user avatar
10 votes
Accepted

Derivatives of vectors

Here's how you should probably do this: vec = Array[v, 3] D[vec.vec, vec.{0, 0, 1}] (* {v[1], v[2], v[3]} *) (* 2 v[3] *) I'll just make a couple of points about ...
user avatar
  • 21.5k
10 votes

How to calculate a list without loop?

FoldList[{0, 1} # + #2 &, list]
user avatar
  • 83.3k
10 votes

Plotting a complicated 3D wave on the surface of a sphere

It seems to me that your function depends on too many variables to be represented entirely as a 3D contour. Perhaps we can get to what you need by approximation. To start off, here is perhaps an ...
user avatar
  • 58.4k

Only top scored, non community-wiki answers of a minimum length are eligible