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

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

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

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


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

This is an interesting problem, because the difficulty is not the concept, but rather how to compute it (efficiently). Given points $(X_i,Y_i)$ distributed Uniformly on the unit square, we are interested in $$P\big[\sqrt{(X_2-X_1)^2 + (Y_2-Y_1)^2} \; > \; 1\big] $$ Let $X = X_2 - X_1$ denote the difference of two standard Uniform random variables, which ...


13

What's with all the heavy lifting and machinations? d = ProductDistribution[{TriangularDistribution[{-1, 1}], 2}]; Probability[a^2 + b^2 > 1, {a, b} \[Distributed] d] $\frac{19}{6}-\pi$ Finishes in a few seconds on a netbook...


13

s = {w, x, y, z}; sum = {-1, 3, 5, 8}; add = Plus @@@ Subsets[s, {3}] (* {w + x + y, w + x + z, w + y + z, x + y + z} *) Solve[add == sum, s] (* {{w -> -3, x -> 0, y -> 2, z -> 6}} *)


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


12

I don't know what Mathematica is doing, but there are two ways to justify the result (if you're willing to accept different formulations of integrability). In an analogy with Cesàro summability, the 2 Cos[1] is the "Cesàro sum" $$\int_0^\infty f(u) \; du \buildrel C \over = \lim_{z \rightarrow \infty} {1 \over z} \int_0^z \int_0^y f(u) \; du \; dy$$ of the ...


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


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

Introduction: We are looking for two distinct values of $x$ for which a generic line and your function have 1) the same $y$ value (i.e. the line touches the curve) and 2) the same derivative (i.e. the line is tangent to the curve). We can set up the following system of equations spelling out these conditions: y[x_] := a x + b (* a ...


11

This is not quick (includes J.M. comment): pdf = UniformDistribution[2]; td = TransformedDistribution[(x - y)^2, {x, y} \[Distributed] pdf]; zd = TransformedDistribution[ a + b, {a \[Distributed] td, b \[Distributed] td}]; then ans = 1 - FullSimplify[CDF[zd,1]] yields the desired result.


11

The region within the three curves can be plotted and its area determined using Mathematica's geometric capabilities. RegionPlot[y < 3/x && y < 12 x && y > x/12, {x, 0, 6}, {y, 0, 6}, PlotPoints -> 200, FrameLabel -> {x, y}] and integrate its area by Area[ImplicitRegion[y < 3/x && y < 12 x && y &...


11

mat = ConstantArray[1, {4, 4}] - IdentityMatrix[4]; LinearSolve[mat, {-1, 3, 5, 8}] {6, 2, 0, -3}


11

You need to delay the evaluation of the right-hand side of ScalarCurvature: ScalarCurvature[fun_, xx_, yy_] := scalar /. Derivative[i_, j_][f][x, y] :> D[fun, {xx, i}, {yy, j}] Then it works, although there is a sign difference to your formula: ScalarCurvature[x^2 - y^2, x, y] -(8/(1 + 4 x^2 + 4 y^2)^2)


11

There appears to be a bug, not in Integrate or in BesselK, but in the vertical-axis Ticks of LogLogPlot. Consider the simple case, LogLogPlot[Exp[x], {x, 10^-10, 1}, PlotRange -> All] as it should be. However, LogLogPlot[Exp[x], {x, 10^-10, 1}, WorkingPrecision -> 50, PlotRange -> All] In fact, any value of WorkingPrecision except ...


11

region = ImplicitRegion[ 0 < z < 4 - x*y && 0 <= x <= 2 && 0 <= y <= 1, {x, y, z}]; RegionPlot3D[region, BoxRatios -> {1, 1, 1}, Axes -> True] Volume[region] (* 7 *) RegionMeasure[region] (* 7 *) Integrate[1, {x, 0, 2}, {y, 0, 1}, {z, 0, 4 - x*y}] (* 7 *) Integrate[1, Element[{x, y, z}, region]]...


10

You can take Michael Trott's code and modify it a bit to easily plot these surfaces Import["http://www.mathematicaguidebooks.org/V6/downloads/\ RiemannSurfacePlot3D.m"] rsurf[func_] := Grid[{{RiemannSurfacePlot3D[w == func, Re[w], {z, w}, ImageSize -> 400, Coloring -> Hue[Rescale[ArcTan[1.4 Im[w]], {-Pi/2, Pi/2}]], PlotPoints -&...


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


10

RegionMeasure chooses a method which is slow when exact non-rational coefficients are present. I will correct this for a future version. Thanks for pointing it out. In Mathematica 10 the example works fast with approximate coefficients. In[1]:= Timing@RegionMeasure@N@ RegionIntersection[ Tetrahedron[{{0, 0, Sqrt[3/2]}, {2/Sqrt[3], 0, ...


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*)


10

Consider Derivative[1][f[##] &] // FullForm Function[0] Function[0][x] 0 So the snippet you quote from the docs might not be entirely accurate; might not be considering such an edge case as ##. I believe that Derivative is looking for head Slot when detects a pure function goes on to rewrite it, so it ignores head SlotSequence -- i.e., ...


10

For fun: RegionPlot3D[ z <= -2 x^2 - 2 y^2 && z <= 8 x + y - 20, {x, -10, 10}, {y, -10, 10}, {z, -100, 0}, PlotPoints -> 150, Mesh -> None, PlotStyle -> Directive[Darker@Red, Specularity[1]], Axes -> False, Boxed -> False ]


10

Here is one way: noIn[y_, x_] = y; noIn[Indeterminate, x_] = Round[x]; transIn[x_] = noIn[(1 + Erf[2 ArcTanh[2 x - 1]])/2, x]; transOut[x_] = noIn[(1 - Erf[2 ArcTanh[2 x - 1]])/2, x]; SeedRandom[15] f[x_, y_] = RandomReal[{-1, 1}, 4].Sin[RandomReal[{-2, 2}, {4, 4}].{1, x, y, x^(4/3)}]/3; r[t_] = {1/2 + Sin[t] + t^(3/2) - (t/2)^2, Sin[t] - t^2 + (2 t/3)^5 - ...


9

Is this what you want? Clear[Derivative, h]; h[0] = 1; (* to avoid division by zero with OP's example R *) Derivative[1][h][s_] := Block[{Derivative}, h'[\[FormalS]] /. First@Solve[ D[R[a + h[\[FormalS]]] == - \[FormalS], \[FormalS]], h'[\[FormalS]]] /. \[FormalS] -> s ]; Derivative[n_][h][s_] := D[Derivative[n - 1][h][\[...


9

Mathematica seems to split the integrand component, E^(-((-m + Log[x])^2/(2 s^2))) into E^(-((m^2 + Log[x]^2)/(2 s^2))) times the sort-of "coefficient" E^((m Log[x])/s^2) (* == x^(m/s^2) *) in order to calculate the integral in terms of Meijer $G$. For reasons that are obscure to me, it seems to want the coefficient of m in the exponent to be ...



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