Hot answers tagged

23

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 ...


19

Just wanted to update everyone that things are much simpler, - there is built in support for this: MeshFunctions -> {"ArcLength"} So for our case: Show[{ ParametricPlot3D[KnotData[{3, 1}, "SpaceCurve"][t], {t, 0, 2 Pi}, (* the trick *) Mesh -> 15, MeshFunctions -> {"ArcLength"}, (* styles *) MeshStyle -> Directive[Red, ...


19

Summary: Setting GenerateConditions -> False turns off safety checks. In my opinion, when the user does that and the result is erroneous, I would not call that a bug. Now WRI could decide to improve Mathematica in this case, but it might not be such a simple matter. On the other hand, it is entirely up to the user to decide whether or not he or she is ...


17

SphericalPlot3D is having problems where the radius goes to infinity. You can use RegionFunction to restrict the plotting region to a range where the function is well-behaved: SphericalPlot3D[ Sqrt[1/(Sin[θ]^2 Cos[2 ϕ] - Cos[θ]^2)], {θ, 0, π}, {ϕ, 0, 2 π}, MaxRecursion -> 4, PlotRange -> {-3, 3}, RegionFunction -> Function[{x, y, z, θ, ϕ, ...


16

$Version (* "8.0 for Microsoft Windows (64-bit) (October 7, 2011)" *) Direct attack fails: Timing[Convolve[Sinc[x], Exp[-x^2], x, y]] (* Out[218]= {59.296, Convolve[Sinc[x], E^-x^2, x, y]} *) or, equivalently, Timing[Integrate[Sinc[x] Exp[-(x - y)^2], {x, -∞, ∞}] ] $\left\{49.92,\int_{-\infty }^{\infty } e^{-(x-y)^2} \text{Sinc}[x] \, dx\right\}$ ...


16

The "canonical" way in Mathematica is f[x_, y_] := x^2 + y^2 g[x_, y_] := x^4 + 4 x y + 2 y^4 - 8 Maximize[{f[x, y], g[x, y] == 0}, {x, y}] If you want to make explicit usage of the Lagrange multiplier: ss = N@Solve[Grad[f[x, y] + λ g[x, y], {x, y}] == 0 && g[x, y] == 0, {x, y, λ}, Reals] gives the {x, y} coordinates of the maxs and mins. ...


16

I believe there are at least three cases treated separately by Derivative. 1) A function defined by a Symbol. This follows the the rule cited in the documentation. g[x___] := f[x]; Derivative[1][g][x] // Trace (* { { g' , { g[#1] <-- Here the rule is being applied , f[#1] } , f'[#1] & } , (f'[#1] &)[x] , f'[x] } ...


16

I would approach this from the fact that both are forms of multiplication, but one has a negative exponent. So RandomReal[{1, 20}]^RandomChoice[{1, -1}] will randomly be either 1/x or x, where x is a random number between 1 and 20.


15

A simple alternative is to use Plot3D with both RegionFunction and Filling. Plot3D[y, {x, 0, 1}, {y, 0, 1}, RegionFunction -> Function[{x, y, z}, x^2 + y^2 <= 1 && x >= 0 && y >= 0 && z >= 0], Filling -> 0, FillingStyle -> Opacity[.75], PlotStyle -> Opacity[.5], AxesLabel -> (Style[#, 14, Bold] ...


15

Your function f is a good one for demonstrating to your students that they must be careful when working with a computer's built-in floating point capability. It is very fast, but because of its fixed and limited precision, it can never be absolutely trusted. Mathematica's is often to be preferred for serious numerics because you can switch from machine ...


14

There is a specific function called CountRoots, which does exactly what you want: CountRoots[poly, x] (* 12 *) You can then compare this number to the number of roots given by the length of the coefficient list: Exponent[poly, x] (* 36 *)


14

Update a working approach using Fourier transforms The following method is based on the idea that the Laplace operator is just a multiplication with $-k^2$ in Fourier space. Therefore, I first find the Fourier transform of the $1/r$ potential and then do an inverse Fourier transform of that result, multiplied by $-k^2$ (which I call laplacianFT in the ...


13

Update: a way of joining (taking the union of) the first rectangle and first circle, so that the edge form only marks the exterior of the joined form p = 100; curve = Line@ Table[{.53, 0} + {.07, Sqrt[0.5]} {Sin[-2 Pi k /p], Cos[-2 Pi k /p]}, {k, -1 + p/2}]; poly = Polygon[Join[t1 = Table[{.47, 0} + {.07, Sqrt[0.5]} {Sin[-2 Pi k /p], ...


12

Chances are it will behave similarly to Integrate[Exp[-x t^3 ], {t, 0, π/2}]. I show a numerical verification below. We'll use the dominant series term, which we can compute, for the above integral, and compare to numerical integrations of the one we cannot compute analytically. ee1[x_] := Exp[-x*t^3] ee2[x_] := Exp[-x*t^3*Cos[t]]; Let's get the candidate ...


12

$Version (* Out[228]= "8.0 for Microsoft Windows (64-bit) (October 7, 2011)" *) The result provided by Mathematica is correct: Integrate[a/(a^2 + Sin[t]^2), {t, 0, 2 π}] (* Out[213]= (2 π)/(Sqrt[1 + 1/a^2] a) *) Now the same procedure as "always" which "explains" the zero result. The indefinite integral is Integrate[a/(a^2 + Sin[t]^2), t] (* ...


12

For what it's worth, you can monitor the progress of Integrate and NIntegrate. I'm not sure how helpful the tools below are, but I feel it is probably worth mentioning them. Integrate Internal`Integrate`debugSwitch If you set Internal`Integrate`debugSwitch to the magic number 10, it will print its (major) steps in searching for the answer. For instance: ...


12

As J.M. noted, when you do it by hand, you presume that you are working with real variables and, probably, that a > 0. Mathematica doesn't make such assumptions by default, so you need to give it a hint. For example, Integrate[Sqrt[4 a^2 - x^2 - y^2] Boole[x^2 + y^2 < 2 a x], {x, 0, 2 a}, {y, 0, a}, Assumptions -> a > 0] will give 4/9 ...


11

I've got a theory.... Let's try to get the antiderivative: Integrate[(1 + 16*Tan[2*x - y]^2)/(1 + 4*Tan[2*x - y]^2), x, Assumptions -> y \[Element] Reals] (*returns 5 x - (5 y)/2 - ArcTan[2 Tan[2 x - y]] *) Seems legit. You can test with D[5 x - (5 y)/2 - ArcTan[2 Tan[2 x - y]], x] and plot or rearrange. This antiderivative is technically correct, ...


11

Just purely for fun: to illustrate approximation of volume integral. Manipulate[ Module[{dp, dpl, dpu, r = Range[0, 1, 1/n], f, cc, lb, la, ub, ua, ll, ul}, dp = Range[0, 1, 1/#] & /@ Range[2, 100]; dpl = Total[Pi Most[#]/(Length@# - 1)] & /@ dp; dpu = Total[Pi Rest[#]/(Length@# - 1)] & /@ dp; f = Sqrt /@ r; cc = Partition[{#, 0, ...


11

One quick way for rational functions is to leverage built-in control system functions: TransferFunctionPoles[TransferFunctionModel[1/(1 + s^2), s]][[1, 1]] {-I, I}


11

On a different occasion (Dirichlet coefficients as limits: wrong) I have shown that the sometimes limited capabilities of the function Limit[] can be improved by using an intermediate Series[]. Following this idea we can write for the limit in question Limit[Expand[ Normal[Series[(n - n Sqrt[1 + x])^2, {x, 0, 2}]] /. x -> 10/ n + Sin[n]/n^2], n ...


10

Here is a visualization using MeshFunctions (as mentioned by Daniel in the comment): f = x y z; g = x^2 + 10 y^2 + z^2; gp = With[{r = 3}, RegionPlot3D[g < 5, {x, -r, r}, {y, -r, r}, {z, -r, r}, PlotStyle -> Orange, PlotPoints -> 40, Mesh -> None, ViewPoint -> Front, PlotTheme -> "Classic"] ]; With[{r = 3}, Manipulate[ ...


10

It has to do with the default behavior of GenerateConditions in multivariate integrals. Setting it explicitly to True will help in this case. Some explanation may be found here or here. The gist is that, for multiple integration, automatically checking conditions and issuing provisos for all but the final integration is typically both too costly (in speed) ...


10

This should be a comment, but it's too long... This isn't really a Mathematica solution, but here's some insight into the integral. I assume all parameters are positive. Call your integral $I$ and let $s = b^2/(2c)$. Substituting $t = \sqrt{x}$ transforms $I$ into the Laplace transform $$ I = \frac{1}{2} \mathcal{L}_t\left( J_0(n \sqrt{t} \,) \theta(a^2 - ...


10

However, is there something you can put in the code to set the speed? Animate takes an option AnimationRate I still haven't been able to draw the bottom part of the first animation on https://courses.engr.illinois.edu/tam212/avt.xhtml#avt and note how it continues to move to the right (without everything jumping around). I think you can get as ...


10

The problem here is the Sin[n] which has no limit since it is an oscillating function, but it is always bounded by $\pm 1$: if you change you code with the following: Limit[(n - Sqrt[1 + 10 n + n^2])^2, n -> Infinity] with 1 in place of Sin (or -1 if you want), you get the result: (*25*)


9

Here's how to make Mathematica integrate this, but a lot is done by hand. Cos[β] Exp[I z Cos[β - α]] == Cos[β] Cos[z Cos[α - β]] + I Cos[β] Sin[z Cos[α - β]] The integral of the first summand is zero. Make the substitution γ == α - β and expand the Cos[β] to Cos[α] Cos[γ] + Sin[α] Sin[γ]. Also note that the function is Pi-periodic. The integral ...


9

It seems, that findExponentialGeneratingFunction would be equivalent to FindGeneratingFunction of the sequence {a1/0!,a2/1!,a3/2!,...}. Therefore findExponentialGeneratingFunction = FindGeneratingFunction[#1/(Factorial /@ Range[0, Length@#1 - 1]), #2] & findExponentialGeneratingFunction[{1,1,1,1,1,1,1,1},x] (* Exp[x] *)


9

Converting to polar coordinates helps with the xy integral: Assuming[θ ∈ Reals && h ∈ Reals && h > 0 && x ∈ Reals && y ∈ Reals && z ∈ Reals && z > 0, Integrate[((7695 h x^2 y^2 z^6 Sin[2 θ]) / (2 π (h^2 + x^2 + y^2)^(5/2) (h^2 + x^2 + y^2 + 2 h z + z^2)^8) /. {x -> r Cos[t], y -> r ...


9

Assuming that you have used the parametrization $$r(t)=(\cos{t},\sin{t},t).$$ You could just make the interval over which you plot the blue line shorter, from $[0,2\pi]$ to $[\frac{1}{2}\pi,2\pi]$, so that the plots don't overlap. Then you would get something like this: Show[ ParametricPlot3D[r[t], {t, π/2, 2 π}, PlotStyle -> {Blue, Thick, ...



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