Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

# Tag Info

49

Consider this: ParametricPlot3D[ RotationTransform[a, {0, 1, 0}][{0, 0, Sin[3 a] + 5/4}], {a, 0, 2 Pi}, Evaluated -> True] Now rotate this around a circle, while rotating it at the same time around its' origin: ParametricPlot3D[ RotationTransform[b, {0, 0, 1}][{6, 0, 0} + RotationTransform[a + 3 b, {0, 1, 0}][{0, 0, Sin[3 a] + 5/4}]], {...

46

You asked for alternative approaches to what you did, so here is one: A completely different approach to the one-dimensional time-independent Schrödinger equation would be to use matrix techniques. The idea is to eliminate the need for NDSolve entirely. For bound-state problems, you can do this by choosing a basis satisfying the condition of vanishing wave ...

28

We couldn't be really pleased if we didn't exploit existing Mathematica functionality to get exact solutions. Here we provide them with Reduce rewriting the given system to an exact one and using a trick by adding another variable x because one can see that any solutions are described by two different arguments t and t + x. Now we can realize that one can ...

25

The plan is first get the "external" contour and then use Green's theorem to find its area. r[t_] := {-9 Sin[2 t] - 5 Sin[3 t], 9 Cos[2 t] - 5 Cos[3 t], 0} (*find the intersections*) tr = Quiet@ToRules@Reduce[{r@t1 == r@t2, 0 < t1 < t2 < 2 Pi}, {t1, t2}]; pt = {t1, t2} /. {tr} // Flatten; pts = SortBy[pt, N@# &]; pps = Partition[pts, 2]; Now ...

20

I'm adding this answer to put on record an answer to the second part the question, "what is the parametric equation?". The parametric equation is implicit in Kirma's RotationTransform expression. To extract it, one need simply write something like Clear[a, b] quoit[a_, b_] := Evaluate @ RotationTransform[b, {0, 0, 1}][{6, 0, 0} + RotationTransform[...

19

You can get the curve in polynomial implicit form as below. poly = GroebnerBasis[{x^2 - ct, y^2 - st, ct^2 + st^2 - 1}, {x, y}, {ct, st}][] (* Out= -1 + x^4 + y^4 *) To get the area, integrate the characteristic function for the interior of the region. That that's where the polynomial is nonpositive (just notice that it is negative at the ...

19

ColorFunction and Epilog were around in version 7. However, ColorFunction did get an update in version 9 so I am not certain if this will work in version 7. Animate[ ParametricPlot[circle[t], {t, Max[0, u - .2], u}, PlotRange -> {{-dMax, dMax}, {-dMax, dMax}}, ColorFunction -> Function[{x, y, w}, Opacity[w, Blue]], Frame -> True, Axes ->...

18

Can be done as follows. (1) Find implicit form from parametric. (2) Solve for pts $(x,y)$ where implicit eqn and gradient simultaneously vanish. (3) Discard those solutions that correspond to cusps. The rest correspond to crossings. The code below handles steps (1) and (2). I found it useful to rationalize because we eventually get an overdetermined system ...

17

Since it seems to have not been mentioned yet: yet another way to obtain an approximation of the area of your Lamé curve is to use the shoelace method for computing the area. Here's a Mathematica demonstration: pts = First[Cases[ ParametricPlot[{Sqrt[Abs[Cos[t]]] Sign[Cos[t]], Sqrt[Abs[Sin[t]]] Sign[Sin[t]]}, {t, 0, 2 π}, ...

17

Third solution A slightly simpler and more geometric approach leads to a third form for the solution (including Artes' and my second) -- don't you just love trigonometric functions! By symmetry, two points starting from a vertex of the hypocycloid (star) and going in opposite directions at the same speed will meet at one of the desired crossings. If the ...

17

A least squares approach: model = a/((x - x01)^2 + c y^2) + a/((x - x02)^2 + c y^2) $\frac{a}{c y^2+(x-\text{x01})^2}+\frac{a}{c y^2+(x-\text{x02})^2}$ If we assume the equation will be model==1, then the sum of the squares of the residuals will be: errorfunc = Total[(1 - (model /. {x -> #[], y -> #[]} &) /@ data)^2]; Then, minimizing ...

16

Actually, I want the output to be {} if there is anything wrong with the argument. For this I recommend one or more definitions with patterns that only match a valid argument, and a fall-through definition for anything else. For example if the argument should be a nonempty list of integers: (* primary definition *) func[arg : {__Integer}] := Mean[arg] (*...

15

As Jens mentioned, the spatially discretize the equation is another alternative for bound state problem. Here is my very simple implementation of this approach. The basic idea is express the equation on a grid. The differentials can be expressed as finite differences. For example, the second order derivative can be expressed as \frac{d^2\psi}{d x^2}\... 14 If the potential is (\tanh (x)+1) (\tanh (x)-1) you can obtain the analytic solution using Mathematica as follows: [I have omitted some of the detail - e.g. the asymptotic expansions - because the details are analogous to the simple harmonic oscillator case in my previous answer (see above).] Define the potential. u[x_] = (1 + Tanh[x]) (-1 + Tanh[x]) ... 14 You can use Table for this: Plot[Evaluate@Table[f[a, b, 2, 3], {b, 0, 5, 1}], {a, 0, 1}] And you can also put there multiple parameters, so Table will use all of them. You can use PlotLegend to specify the legend: Plot[Evaluate@Table[f[a, b, 2, 3], {b, 0, 5, 1}], {a, 0, 1}, PlotLegends -> LineLegend[Table[b, {b, 0, 5, 1}], LegendLabel -> x]] 14 Okay, this'll be a short answer just to show what you can do. What you are trying for here is essentially an inverse to FrenetSerretSystem, which will give the curvature and basis vectors from the parametric equations. We have these equations for the tangent vector, the normal vector, and the binormal vector \begin{align} \dfrac{d\mathbf{T}}{ds} &= &... 13 Concerning the comment about creating the surfaces, sure: Mathematica is one of the best tools available for that. Here's the Klein bottle, for example. ParametricPlot3D[{ (3 + Cos[v/2]*Sin[u] - Sin[v/2]*Sin[2 u])*Cos[v], (3 + Cos[v/2]*Sin[u] - Sin[v/2]*Sin[2 u])*Sin[v], Sin[v/2]*Sin[u] + Cos[v/2]*Sin[2 u]}, {u, -Pi, Pi}, {v, 0, 2 Pi}, Axes -> ... 13 Here's my slight simplification of the Klein bottle parametric equations. I believe the original parametrization is due to Stewart Dickson (whose depiction of the bottle was in the "Graphics Gallery" of the old versions of The Mathematica Book). ParametricPlot3D[{6 Cos[u] (1 + Sin[u]), 16 Sin[u], 0} + 2 (2 - Cos[u]) {Cos[Clip[u, {0, π}]] ... 11 One can use one of the line integral forms of the area, derived from Green's Theorem:A = \frac12 \int_C x \; dy - y \; dx = \int_C x \; dy = - \int_C y \; dx The first one is symmetric, which sometimes is an advantage. c[t_] := {Sqrt[Abs[Cos[t]]] Sign[Cos[t]], Sqrt[Abs[Sin[t]]] Sign[Sin[t]]} dA = 1/2 c'[t].Cross[c[t]] (* complicated output *) One ...

11

As in version 10.2, there is the NDEigensystem can be used to calculate the eigenstates and eigenvalues of a differential operator. For example in the harmonic potential case, the even and odd eigen functions can be calculated using Neumann and Dirichlet boundary condition respectively: {egnVal1, egnVec1} = NDEigensystem[{-1/2 Laplacian[u[x], {x}] + 1/2 ...

11

I just finished blog post about the creation of nice graphics from Mathematica Graphics3D using the Blender render framework: http://wolfig-techblog.blogspot.de/2015/04/blender-as-shader-for-mathematica.html Maybe you can find some inspiration there for your own graphics. I managed to generate a reasonable Klein bottle with glass shading: Note: the ...

11

My defined function next find {nextpoint, nextdirection} value from {startpoint, startdirection} using NSolve. next[{sp_, sd_}][δ_] := Module[{φ, sol, fp, fd}, sol = NSolve[{{x[φ, δ], y[φ, δ]} == sp + t sd, Abs[t] > 10^(-9), 0 <= φ < 2 π}, {t, φ}, Reals]// Quiet; sol = If[Length[sol] > 0, sol[]]; fp = {x[φ, δ], y[φ, δ]} /. sol; ...

11

plt = ParametricPlot[ u {9 Sin[2 t] + 5 Sin[3 t], 9 Cos[2 t] - 5 Cos[3 t]}, {t, 0, 2 Pi}, {u, 0, 1}, MeshFunctions -> {Sqrt@(#1^2 + #2^2) &}, Mesh -> {{1}}, PlotPoints -> 30, MeshStyle -> Cyan, MeshShading -> {Cyan}] Post-process plt to remove Lines plt /. Line[_] :> Sequence[] or to paint them Cyan: plt /. Line[x_] :> {...

11

The main issue is simply that your constraint should not be imposed after the integration of the field lines, but beforehand. This means that we should choose the starting points from which the differential equations of the field lines are integrated to lie on the desired cylinder right from the beginning. Then, all you have to do is to impose the ...

11

You can take a continuous function and evaluate it at the same points that are also used by ParametricPlot3D to create the curve. Here is a way to do it: rr = Reap[ ParametricPlot3D[γ[t], {t, 0, 2 Pi + .01}, ColorFunction -> Function[{x, y, z, t}, Hue[wColor[Sow[t, "tValues"]]]], ColorFunctionScaling -> False, PlotStyle -> ...

11

There are a number of ways to do this, e.g.: f[a_, x_] := 1/((1 - x) (1 + a/(1 - x)^2)) parameters = {0, 0.01, 0.02, 0.05, 0.1}; Plot[Evaluate[f[#, x] & /@ parameters], {x, 0, 1}, PlotRange -> {0, 5}, PlotLegends -> Table[Row[{"\!$$\*SubscriptBox[\(R$$, $$L$$]\)/R=", j}], {j, parameters}]] or using Table: Plot[Evaluate[Table[f[j, x],...

11

s = ParametricNDSolveValue[{x'[t] == -y[t] + x[t]*Log[x[t]], y'[t] == x[t] + y[t]*Log[x[t]], x == x0, y == 0}, {x, y}, {t, 1}, x0] f[x0_, t_] := Through[Through[s@x0]@t] pts = Table[f[x0, t], {x0, 1, 2, .2}, {t, 0, 1, .1}]; Show[Graphics[{Green, Arrow /@ pts, Black, Point /@ pts}, ...

11

If I understand the question correctly, you wish to obtain a parameterized solution {U2[U1], W2[W1]} from the equation in the question, so that you can vary that parameter to obtain a "nice" solution. One approach is as follows. Define exp = 32 + 8 a^2 (2 + b) + 4 a (2 + b) (6 + b) - b (-4 (8 + U1 - W1 + U2[U1]) + b (-8 + (-2 + U1) U1 + W1^2 - 2 U2[...

11

A minor change to model eliminates the error cited in the question. (Replace s[t] by s in the final line of the code immediately below.) model = ParametricNDSolveValue[{e'[t] == (k2 + k3) es[t] - k1 e[t] s[t], es'[t] == -e'[t], s'[t] == k2 es[t] - k1 e[t] s[t], p'[t] == k3 es[t], e == 0.001, s == 5, es == 0, p == 0}, s, {t, 0, tmax}...

10

Here is a symbolic solution of your eigenvalue problem. Define the differential equation (setting $\hbar = \omega = m_0 = 1$). diffeq = -(1/2) \[Psi]''[x] + 1/2 x^2 \[Psi][x] == e \[Psi][x] Symbolically solve the differential equation. soln = DSolve[diffeq, \[Psi], x][[1, 1]] (* \[Psi] -> Function[{x}, C ParabolicCylinderD[1/2 (-1 - 2 e), I ...

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