Tag Info

Hot answers tagged

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


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


6

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


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


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


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

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


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


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}]; ...


3

NIntegrate does each integral separately This has been observed before: NIntegrate piecewise vector function, Nested NIntegrate of vector function. It is also clear from the following BenchmarkPlot: int[n_] := Block[{shaxis}, shaxis = Table[1.0*i, {i, 1, n}]; NIntegrate[shaxis/(x^3 + 10), {x, 0, Infinity}, Method -> {"GlobalAdaptive", Method ...


2

While I'm not sure why the error you see is generated, you can fix your sumT function by taking the fF call out of the Map form: sumT = Compile[ {{tab, _Real, 2}}, Total[fF /@ Map[enn[#[[1]], #[[2]]] &, tab]], CompilationTarget -> "C"]; This worked fine for me in version 10.1 of Mathematica: sumT[tab] // AbsoluteTiming (* ==> {0.000667, ...


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


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


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.



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