Tag Info

New answers tagged

0

Two small issues in your code. You have incorrect syntax in your Nest statement that assigns a value to S. sqrt is not defined. I think you want Sqrt and will have to change your brackets as well. Use SetDelayed (:=) for assignment of w to have it re-evaluated each time in the Nest statement. Hope this helps.


5

Instead of doing the integration yourself, why not have Mathematica do it for you? g = 6.674*^-11; dt = 0.001; tStop = 2000; soln = First@NDSolve[{ x1''[t] == g (m2/Norm[x2[t] - x1[t]]^3 (x2[t] - x1[t]) + m3/Norm[x3[t] - x1[t]]^3 (x3[t] - x1[t])), x2''[t] == g (m3/Norm[x3[t] - x2[t]]^3 (x3[t] - x2[t]) + m1/Norm[x1[t] ...


0

RandomVariate[NormalDistribution[0,1]] If you want 10 such numbers: RandomVariate[NormalDistribution[0, 1], 10] Answering the question below: RandomVariate[TruncatedDistribution[{0, 1}, NormalDistribution[0, 1]], 12]


4

I nest the right turns with # + Normalize@Cross[#] &. Since 2012rcampion has rather solved the coloring, here's a version using a close match from one of Mathematica's gradients. cf = Lighter[ColorData["AvocadoColors", 1. - #], (1. - #)^8] &; With[{npts = 87}, Graphics[ GraphicsComplex[ NestList[# + Normalize@Cross[#] &, {1., 0.}, npts - ...


10

I tried to do this without looking at the previous answers... let me know if I accidentally plagiarized! With[{n = 87}, Module[{radii = Sqrt[Range[n]], angles, coords}, angles = Accumulate @ Most[ArcCot[radii]] ~Prepend~ 0; coords = radii * Transpose @ Through[{Cos, Sin}[angles]]; Graphics[{ EdgeForm[Black], Reverse @ MapIndexed[{ ...


3

In such cases I prefer to get an idea from numerical solution. f[x_] = 202. (2.51521 + 1/(-1 + E^(202. x))) + 802. (2.52457 + 1/(-1 + E^(802. x))) + 1802. (2.52632 + 1/(-1 + E^(1802. x))) + 3202. (2.52694 + 1/(-1 + E^(3202. x))) + 5002. (2.52722 + 1/(-1 + E^(5002. x))); data = Table[{a, x /. FindRoot[f[x] == a, {x, -0.001}]}, {a, -100, 100, 10}]; ...


0

You are using insufficient precision: theta2'[.8] (* -0.794774 + 0.280078 I *) Precision[.8] (* MachinePrecision *) Use exact arguments: theta2'[8/10] and get the exact result. Use N et. al. with desired precision to retrieve numeric values. N[theta2'[8/10], 10] (* -0.8874928427 + 4.596*10^-7 I *)


7

There are different ways to do this. The easiest, I think, is to use DerivativeFilter: data = Table[Sin[x]*Cos[y], {x, 0, 2 Pi, 0.2}, {y, 0, 2 Pi, 0.2}]; gradFilter[data_] := Module[{n = ArrayDepth[data]}, MapThread[List, Table[DerivativeFilter[data, UnitVector[n, i]], {i, n}], n]] ListVectorPlot[gradFilter[data]] I made this independent of ...


2

In addition to @ybeltukov's excellent answer, I thought it would be worth noting the behaviour of RuntimeOptions, when compiling to either the Wolfram Virtual Machine (WVM) or to C, for these subnormal positive doubles. f = Compile[{{t, _Real}}, Exp[-9 t^2]]; Needs["GeneralUtilities`"] f[1.] (* = 0.00012341 *) f[8.872] (* = 2.191*10^-308 *) Do[f[1.], ...


5

Looking at your code, the problem occurs when you're trying to return {node-1, Transpose[{xn,phi}]}. If instead you run the following code, which only returns Transpose[{xn,phi}], calU=Compile[{{x,_Real,1},{energy,_Real},{m,_Real},{a,_Real}}, Module[{i,node,xn,nn,phi,V,h,f,temp}, h=x[[3]]; xn=Range[x[[1]],x[[2]],h]; nn=Length@xn; ...


1

This is not an answer, but rather one route to explore the feasibility of your model. Once you have the set of equations obtained from ParametricNDSolve you can plot them using Manipulate to see how the values of k affect the shape of the concentration vs. time plots: This graphic was obtained using the following (data contains the Imported google ...


0

There is another possibility, and that is to differentiate an InterpolatingFunction. Here is an example of a rather poorly behaving function whose derivative we can recover by this technique. The transfer function of a Butterworth filter looks like h[s_] := 1 / (1 + 2s + 2s^2 + s^3) for s complex. The Arg of this function, which, for purely imaginary ...


3

The integral over a spherical region is easily performed by Mathematica even analytically. Assuming f=1 and for brevity putting the center of the sphere at the origin: Timing@Integrate[1, {x, -r, +r}, {y, -Sqrt[r^2 - x^2], +Sqrt[ r^2 - x^2]}, {z, -Sqrt[r^2 - x^2 - y^2], +Sqrt[r^2 - x^2 - y^2]}] (*{0.218401, 4 Pi r^3 / 3}*) Assigning a numerical value to ...


3

For your example, I would simply do this: R = 2.3; {x0, y0, z0} = {1.2, 2.3, 3.4}; NIntegrate[1, {x, -R + x0, R + x0}, {y, y0 - Sqrt[R^2 - (x - x0)^2], y0 + Sqrt[R^2 - (x - x0)^2]}, {z, z0 - Sqrt[R^2 - (x - x0)^2 - (y - y0)^2], z0 + Sqrt[R^2 - (x - x0)^2 - (y - y0)^2]}]; For a general function func = Function[{x,y,z},body] and a set of boundaries ...


4

What you experience is not Mathematica not dealing with 0.02 correctly, but your yy[...] being called with arguments, for which it is not defined. The following modification will show you the reason: yy[x_, t_]:= Which[x == 0, yy[0, t] = 0, x == 1, yy[1, t] = 0, t == 0, yy[x, 0] = Exp[-1000 (x - .3)^2], True, Print["x==", x, " t==", t];"yy[" ...


3

I believe the symbolic evaluation is not correct but correct simplified expression can be found. I await insight from others wrt reasons. Here, as integer arguments of Beta have just changed to factorial. func[a_, b_] := Factorial[a - 1] Factorial[b - 1]/Factorial[a + b - 1]; f[m_] := FullSimplify@ Sum[Binomial[m, i] Binomial[m, j] (j + 1) p^ i (1 - ...


1

This? FullSimplify[Sum[ Binomial[m, i] Binomial[m, j] (j + 1)/(m + 2) p^i (1 - p)^(m - i) Beta[i+j+1, 2m-i-j+1]/Beta[i+1,m-i+1], {i, 0, m}, {j, 0, m}]] (* gives (2 (1+m)(1-p)^m)/(2+m)^2 *) BUT your latex doesn't match your Mathematica and I don't know which to trust.


0

Adding "SymbolicProcessing" -> 0 (it's probably the "default setting" of Matlab, right?) and making use of parallelism gives me a 3X speedup on my dual-core old laptop: laxis = ParallelTable[1.0 i, {i, 1, 2046}]; Total[ParallelMap[ NIntegrate[#/(x^3 + 10), {x, 0, Infinity}, Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule", ...


4

This is a very simple way to do it. I modified your code very little to add the condition, that is inside a hole, then set the solution to be the boundary condition at the edge of the hole inside, which I set to be zero. Added one line: startRow = 4; endRow = 6; startCol = 4; endCol = 6; Which tells the boundaries of the hole. And inside the Table ...


4

You can use "MaxBoundaryCellMeasure" for that: L = 10; a = 1; k = 1/2; mesh = 0.06; BoxL = x == L || x == -L || y == L || y == -L; reg = ImplicitRegion[(-L <= x <= L && -L <= y <= L) && (x^2 + y^2 >= a^2), {x, y}]; bcθ = {DirichletCondition[u[x, y] == ArcTan[x, y] k, x^2 + y^2 == a^2], DirichletCondition[u[x, y] == 0, ...


2

As mentioned by Albert Retey in the comment above, you can't expect that NDSolve makes use of your parallel kernels, period. However, since your equation set is just a system of 1st order linear ODEs, you can turn to MatrixExp, which seems to parallelize automatically: coe = gamma - DiagonalMatrix@Total@gamma; init = ConstantArray[0., 816]; init[[-2]] = ...



Top 50 recent answers are included