Bob Hanlon
  • Member for 8 years, 4 months
  • Last seen this week
  • Clarksville, MD
How can I minimize expression involving logarithms?
10 votes

Clear["Global`*"] f[a_, b_] := Log[a, 4 (3 b - 1)/9] + 8 (Log[b/a, a])^2 - 1 min = (FindMinimum[{f[a, b], 1/2 < b < a, 0 < a < 1}, {a, b}, WorkingPrecision -> 20] // N) /....

View answer
Distance between two cities
10 votes

Clear["Global`*"] countries = EntityList@EntityClass["Country", "Europe"]; capitals = #["CapitalCity"] & /@ countries; Manipulate[ Column[{ distance[start, end, UnitSystem -> units], ...

View answer
Why am I getting a negative value from $\int_{0}^{\infty}x^{\frac{-9}{8}}*e^{-16*x^{\frac{-1}{8}}-\frac{2*x}{0.5^{9}}}dx$?
Accepted answer
10 votes

This is a precision issue. $Version (* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *) Since you used a machine precision number (i.e., 0.5) in the integrand, the integration is done with ...

View answer
finding fit for data
10 votes

dataskmc2 = {{9.65827, 0.551402}, {10.2803, 0.602804}, {11.4566, 0.953271}, {12.6648, 1.3972}, {13.8468, 1.13551}, {15.0618, 0.845794}, {16.1433, 0.817757}, {17.4852, 0.981308}, {18.6631, ...

View answer
Integrate Squared Legendre Polynomial
Accepted answer
10 votes

Generate a sequence using Table then use FindSequenceFunction to find the general form f[n_] = FindSequenceFunction[ Table[Integrate[LegendreP[n, x]^2, {x, -1, 1}], {n, 10}], n] (* 2/(1 + 2 n) *)...

View answer
Inverse CDF of non-builtin probability distribution
Accepted answer
10 votes

Clear[RaisedCosineDistribution] As with built-in distributions, you need to include the parameters in the distribution definition, and the constraints on the parameters as Assumptions in the ...

View answer
Why my probability function does not work?
10 votes

The correct syntax for a multivariate UniformDistribution is dist = UniformDistribution[{{0, 2*Pi}, {0, 2*Pi}}]; Note that Distributed is \[Distributed] Probability[Cos[X1] + Cos[X2] <= 5, {X1, ...

View answer
Select 2D data in a certain range
10 votes

Using ImplicitRegion to define regions SeedRandom[1]; array = RandomReal[1, {1000, 2}]; rgn1 = ImplicitRegion[0.4 <= x <= 0.7, {x, y}]; rgn2 = ImplicitRegion[0.4 <= x <= 0.7 && ...

View answer
Simplify sum of complex logs to single real log
Accepted answer
10 votes

expr = Log[-t - I w] + Log[-t + I w]; expr // ComplexExpand[#, TargetFunctions -> {Re, Im}] & // Simplify[#, {w > 0, t > 0}] & (* Log[t^2 + w^2] *)

View answer
Turn binary number into string of words
10 votes

bin = 1011011; words = (bin // IntegerDigits) /. {1 -> "one", 0 -> "zero"}; (str = StringJoin[Riffle[words, " "]]) // InputForm (* "one zero one one zero one one" *) Speak[str]

View answer
Decreasing computation time for numerical plot
Accepted answer
10 votes

M = 1.876 // Rationalize m = 0.9389 // Rationalize; q = Sqrt[Q2 + ν^2]; E3[p3_] = Sqrt[p3^2 + m^2]; E4[p3_] = Sqrt[p3^2 + q^2 - 2*p3*q*Cos[θ] + m^2]; For p3zero1 and p3zero2 use Set rather than ...

View answer
Inverse Laplace Transform difficulty
Accepted answer
10 votes

InverseLaplaceTransform[(2 s^2 + s + 13)/((s - 1) ((s + 1)^2 + 4)), s, t] 2*E^t + (3/4)IE^((-1 - 2*I)t) (-1 + E^(4*I*t)) % // ComplexExpand // Simplify 2*E^t - (3*Cos[t]*Sin[t])/E^t % //...

View answer
how to remove Null's from output?
Accepted answer
10 votes

Table[If[Mod[n!, n^(2 n)] == 0, n], {n, 1, 1000}] /. Null -> Sequence[] {1} Cases[Table[If[Mod[n!, n^(2 n)] == 0, n], {n, 1, 1000}], _?NumericQ] {1} Select[Table[If[Mod[n!, n^(2 n)] == 0, n]...

View answer
The graph of inverse function $f^{-1}(y)$
10 votes

f[x_] = Piecewise[{ {1 - x, -1 < x <= 0}, {(1/x + Floor[1/x])/(1 + 1/x + Floor[1/x]), 0 < x < 1}}]; Plot[InverseFunction[f][y], {y, f[1. - 10^-9], f[-1. + 10^-9]}, ...

View answer
Fullsimplify does not simplify Abs'[1.-a]
Accepted answer
10 votes

Mathematica does not have a rule for the derivative of Abs. Assuming that the term arose from taking the derivative with respect to a then taking the derivative of Abs[1-a] results in D[Abs[1 - a], a]...

View answer
Ticks issue for ListLogPlot
9 votes

$Version (* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *) Clear["Global`*"] Version 12.1.1 also has mismatched FrameTicks on the left and right edges: llp = ListLogPlot[ ...

View answer
Trying to fit a circle. Data have weights
9 votes

Clear["Global`*"] data = {{-2.5, 0.0}, {-2, 1.1}, {1, 2.1}, {0, 2.5}, {1, 1.9}, {2, 1.1}, {2.5, 0}, {2, -1.3}, {1, -2.2}, {0, -2.5}, {-1, -2.2}, {-2, -1.2}, {-2.5, 0}}; w = {.1, .2, ....

View answer
How can I speed up RandomVariate in the following case?
9 votes

Clear["Global`*"] dist[gamma_] := ProbabilityDistribution[Exp[-(x/(2*gamma))] 1/(2*gamma), {x, 0, Infinity}]; The distribution dist is equivalent to the built-in ...

View answer
Some doubts about symbolic equations in Wolfram Mathematica
Accepted answer
9 votes

Clear["Global`*"] eqns = {a*b == c + d + e, d/f == g*h + i, k == a/c}; With three equations you can solve for one variable while eliminating two others. To Solve for k while eliminating {a,...

View answer
Finding the exact symbolic formula for a function defined recursively
Accepted answer
9 votes

Clear["Global`*"] h[i_, 0] := 1 h[i_, j_] := ((j - 1)/(i + 1))*h[i + 2, j - 2] Use the recursion to generate a sequence for even values of j seq = {#, h[i, #]} & /@ Range[0, 10, 2] (* ...

View answer
Include the legend inside the plot but was failed
Accepted answer
9 votes

Space for the legend is available at the upper left ListPlot[{ {2, 5, 2, 8, 6, 8, 3}, {1, 2, 5, 2, 3, 4, 3}}, PlotMarkers -> {"✶", 15}, Joined -> True, PlotStyle -> {Orange, ...

View answer
How to find the sum of that series related to Legendre functions of the second kind?
9 votes

Clear["Global`*"] Defining the sum recursively: LegendreQ[n, Sqrt[2]/2]/(n + 1) /. n -> 0 // Simplify (* 1/2 Log[3 + 2 Sqrt[2]] *) sum[0] = Log[3 + 2 Sqrt[2]]/2.0`20; sum[m_Integer?...

View answer
Create special Matrix in mathematica
Accepted answer
9 votes

Clear["Global`*"] A[n_Integer?Positive] := DiagonalMatrix[Range[n], 1, n + 1] A /@ Range[2, 4]//Column

View answer
Having difficulty plotting linear system of equations
Accepted answer
9 votes

For 2 or 3 dimensions: Clear["Global`*"] eqnsFromMatrix[m_?MatrixQ, b_?VectorQ] := Block[ {x, n = Length@m, var, eqns, pt = LinearSolve[m, b], min, max, plt, grph}, min = Floor@Min@pt; max ...

View answer
How to plot a sphere from the standard equation?
9 votes

The equation for a sphere is x^2 + y^2 + z^2 == r^2 With[{r = 7.5}, ContourPlot3D[r^2 == (x^2 + y^2 + z^2), {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, AxesOrigin -> {0, 0, 0}, PlotRange ->...

View answer
Area of region bounded by $y^2=4x$ and $y=2x-4$
9 votes

The enclosed region is rgn = ImplicitRegion[ -2 Sqrt[x] < y < 2 Sqrt[x] && y > 2 x - 4, {x, y}]; The area is Area[rgn] (* 9 *) or RegionMeasure[rgn] (* 9 *) Which agree ...

View answer
Find the square root using a recursive formula
9 votes

Clear["Global`*"] f[a_?(# > 0 &)] := Module[{x, m = 1}, x[0] = 1.; x[n_] := x[n] = (x[n - 1] + a/x[n - 1])/2; While[x[m]^2 != a, m++]; x[m]] f[#] - Sqrt[#] & /@ {2, E, Pi, Prime[...

View answer
Solve command does not solve this equation!
9 votes

Clear["Global`*"] f[n_, x_] := (1/(4 (-1 + x^2)^2)) ((1 - x^2) (-4 π (-1 + x^2) + n (5 - 2 x^2 + x^4)) Cosh[n x] Sinh[π x] + Sinh[n x] ((1 - x^2) (-4 n (-1 + x^2) + π (5 - ...

View answer
How to prevent Mathematica rounding extremely small numbers to zero?
9 votes

There was a change in handling underflow in later versions. $Version (* "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" *) Clear["Global`*"] bessktot[ω0_, σ_] := BesselK[1, Sqrt[ω0/σ^2]/Sqrt[...

View answer
How to check is there any negative term in a large list?
9 votes

Since you have a very large list, you should look at the timing list = RandomReal[1, 10^6]; (And @@ Positive[list]) // AbsoluteTiming (* Hanlon *) (* {0.050573, True} *) VectorQ[list, Positive] // ...

View answer