New answers tagged

0

Solve's 2nd argument must be a variable or list of variables to solve for. It takes conditions restricting those variables as part of its 1st argument. So you should write Solve[Sin[x] == Cos[2 x] && 0 ≤ x ≤ 2 π, x] which will give {{x -> π/6}, {x -> (5 π)/6}, {x -> (3 π)/2}, {x -> (3 π)/2}} You can visually verify the solution by ...


2

As I mentioned in my comment, it looks like the problem is the Log trying to evaluate when the argument is negative. Adding Abs in the argument might help. Also, the model itself doesn't seem to match the data: are you sure that data should follow that function? It looks to me that Exp[-x^(1/2)] fits the data better: fitfunction[x_] := b*Exp[-c*x^(1/2) + ...


7

If Off[PredictorFunction::mlincfttp] won't work, perhaps this: (* holds up evaluation until x is numeric *) ClearAll[applyN]; applyN[f_][x_?NumericQ] := f[x]; Plot[Evaluate@Through@(applyN /@ predictors)@x, {x, 0, 5}]


5

You could try with: Show[Plot[#[x], {x, 0, 5}, PlotStyle -> RandomColor[]] & /@ predictors] Or if you want the same colorscheme for each plot: colors = {Blue, Red}; Show[Plot[predictors[[#]][x], {x, 0, 1}, PlotStyle -> colors[[#]]] & /@ Range@Length[predictors],PlotRange -> All]


0

A simple replacement of the variable won't do if you want to perform general integration by substitution. We can define a function like the following for this task: intSub[x_ -> g_, y_][expr_] := expr /. {Integrate[f_, x] :> Integrate[(f /. x -> g) D[g, y], y], Integrate[f_, {x, a_, b_}] :> Integrate[(f /. x -> g) D[g, y], ...


8

But a 0 / 1 error warning was generated. The error is 1/0 and not 0/1, it happened because you used machine floating point numbers. f[k_] := (4^k (4^k - 1.) Abs[BernoulliB[2 k]])/(2 k)!; n = 89; 1/Power[f[n], (2 n - 1)^-1] gives is too small to represent as a normalized machine number; precision \ may be lost Power::infy But if you change the ...


2

Edit Your numeric problems are induced because you are using machine precision arithmetic. The fix is to define the parameters as exact quantities and do the computations with Mathematica's arbitrary precision arithmetic. You also have some bad syntax in your code, I will correct those errors in presentation of the making of the computation with ...


2

Use exact constants so that the numerical integration can be done with a specified level of precision. p = 1/100; m = -1/2*Log[29/10]; s = Sqrt[Log[29/10]]; r = 1/2; tailF[x_] := 1 - CDF[NormalDistribution[0, 1], (Log[x] - m)/s] t = Quantile[LogNormalDistribution[m, s], p]; v1 = -r*NIntegrate[((tailF[x]/(1 - p))^r)*Log[tailF[x]/(1 - p)], {x, t, ...


1

You need to specify initial conditions: FirEqn = -D[IPF[z, t], z] - D[IPF[z, t], t] - IPF[z, t] SecEqn = -D[IPB[z, t], z] - D[IPB[z, t], t] - IPB[z, t] (* a wild guess *) ROCP = 1; RICP = 1; solIntEqn = NDSolve[{ FirEqn == 0, SecEqn == 0, IPF[0, t] == 4 Exp[-(t - 1)^2], IPF[5, t] == IPB[5, t]/ROCP, IPB[0, t] == 4 Exp[-(t - 1)^2]/RICP, IPB[...


4

With little modifications it seems to wotk: s = ParametricNDSolveValue[{Derivative[2][y][x] + (a + b*(2 + (2/Pi)*ArcTan[x]))*y[x] == 0, y[-10] == Exp[I*10*Sqrt[a + b]], Derivative[1][y][-10] == (-I)*Sqrt[a + b]*Exp[I*10*Sqrt[a + b]]}, y, {x, -10, 10}, {a, b}] u = ParametricNDSolveValue[{Derivative[2][z][x] + (a + b*(2 + (2/Pi)*ArcTan[x]))*z[x] == 0, z[...


4

This uses less memory: Last@Reap@Do[ With[{n = Sqrt[1 + 12 x^2 (1 + x) + 0``1]}, (* <-- N.B. *) If[FractionalPart@n == 0, Sow@{x, Round[n]}]] &, {x, 10^(10)}] On my machine the first and last 10^6 iterations take about 0.4 seconds, so I project it might finish in less than an hour and a half.


1

Here are some other simple ways to do it by turning the NIntegrate expression into a pure function of it lower limit of integration and mapping it over a list of the lower list values. NIntegrate[ 0.5449597442549279` z^1.5540952398630834`*z^0.16243884686615462`, {z, #, 1}] & /@ Table[i/100, {i, 100}] and NIntegrate[ 0.5449597442549279` z^1....


2

You don't need For. Try x = Table[i/100, {i, 1, 100}]; Table[NIntegrate[0.5449597442549279 (1 - z)^1.5540952398630834*z^0.16243884686615462`, {z, x[[i]], 1}], {i, 1, 100}] (*{0.162334, 0.159651, 0.156776, 0.153787, 0.150722, 0.147607, …}*)


1

I tried to reproduce your situation in a simpler contrived example: results = Table[ {i, a /. NonlinearModelFit[ {1}, If[i == 2, 1/0, 1], {a}, x ]["BestFitParameters"]}, {i, 3} ]; As you can see, the code above triggers the Power::infy error on purpose for one value of the parameter ($i=2$), but works fine for the other ...


4

Here's a direct search using a fast square test from this answer: sQ[n_] := FractionalPart@Sqrt[n + 0``1] == 0 Reap[Do[If[sQ[441 + 48*x*(1 + x) (-13 + 16*x)], Sow[x]], {x, 2*10^7}]][[2,1]] //AbsoluteTiming (* {91.0767, {1}} *) So in 91 seconds we've checked up to $x\le2\times10^7$, which corresponds to $y\le2478\times10^9$. Using parallel ...


7

Hmm, I just posted an answer yesterday that overcame just this problem with the undocumented option "SolveDiscreteSolutionBound" that controls a system limit: With[{ropts = SystemOptions["ReduceOptions"]}, Internal`WithLocalSettings[ SetSystemOptions[ "ReduceOptions" -> "SolveDiscreteSolutionBound" -> (1400*10^9)], Solve[y^2 == 441 + 48*x*(...


1

In Mathematica 12.0, the documentation for InstallRsays: If "RHomeLocation" is set to a specific location, this enables RLink to use external R distribution, where the specified location should correspond to the setting of the R_HOME variable (point at the root of R distribution). This option is currently supported on Windows only. So what you did should ...


8

I have created a GmshLink package as a workaround exactly for such questions. Please also see this answer for another nice example of use. First we load the package and show path to directory containing GMSH executable. Get["GmshLink`"] $GmshDirectory = "path_to_directory\\gmsh-4.5.0-Windows64"; Define symbolic region and calculate its bounds (optionally)....


8

You can force Mathematica to use a finer mesh by using BoundaryDiscretizeRegion and giving the option MaxCellMeasure. Like so: r = ImplicitRegion[ -0.5 <= x <= 0.5 && -0.5 <= y <= 0.5 && -0.5 <= z <= 0.5 && (x^2 + z^2 <= 0.04 || y^2 + (0.3 + z)^2 <= 0.04), {x, y, z}]; BoundaryDiscretizeRegion[...


2

Boolean operations are easier to perform with discretized regions. Try this: RegionUnion[ BoundaryDiscretizeRegion[cyl1], BoundaryDiscretizeRegion[cyl2] ]


Top 50 recent answers are included