# Tag Info

## New answers tagged programming

2

I seem to have missed this earlier. Anyway, creating a closed spline in Mathematica explicitly is actually rather simple. Witness the following: pts = {{1, 4}, {.5, 6}, {5, 4}, {3, 12}, {11, 14}, {8, 4}, {12, 3}, {11, 9}, {15, 10}, {17, 8}}; m = 5; (* degree *) n = Length[pts]; f = BSplineFunction[pts, SplineClosed -> True, SplineDegree -> m]; ...

4

To make sure all the walks start at {0}, you could use Li[n_] := 2*RandomVariate[BinomialDistribution[n, 1/2], n] - n; Tb[n_, m_] := Table[Join[{0}, Li[n]], {i, 1, m}]; ListPlot[Tb[10, 5], Joined -> True] Then the average distance for 1 run is calc using Ave[n_] := Abs[Total[Flatten[Tb[n, 1], 1]]]/n N[Ave[1000]] (* 0.891*) You can ...

1

I think it is reasonable to try to produce correct and robust code that will apply Newton's algorithm for finding a zero of a differentiable function of one real variable while maintaining the OP's procedural style. For robustness, a clear distinction will be made between arguments and localized ancillary variables. The arguments will be f, the function ...

1

For a beginner one hint: f[x_] = Exp[x] + Sin[x] - 4 // N; NestList[(# - f[#]/f'[#]) &, 1, 5] {1, 1.1351, 1.12999, 1.12998, 1.12998, 1.12998} Please read the documentation

3

Let $t$ represent the imaginary part of a zeta zero on the critical line. The asymptotic expansion of RiemannSiegelTheta[t] for large $t$ is Simplify[Series[RiemannSiegelTheta[t], {t, Infinity, 2}]] the first term of which is $\frac{1}{2}{\rm Log}[\frac{t}{2\pi}]-\frac{1}{2}$. For large $t$, the phase of the zeta function on the critical line is ...

0

The construction of custom operators with precedence is described in the Complex Patterns and Advanced Features Notation Package Tutorial. More general informations can be found in Precedence of Operators in Notations. The following operator definitions work for the examples given in the question. First loading the Notation Package: Needs["Notation"] ...

6

If you want to have more than one "common block," one possibility would be to use a named Context to emulate each block. For example, here I define two "blocks," common1 and common2, and define a variable x in each of them. The Module below then uses these values by prefacing the desired x with the desired Context name: common1x = 1; common2x = 2; f[x_] ...

1

The comments so far give you an answer where the fixed point is, and what condition to the variable c must hold. If I understand you right you want simply to key this in Mathematica to find a fixed point (for given c). There are various ways. Here is one of them. First define a function to search the fixed point for: fun[x_, c_] := x^2 + c Then you can ...

13

I am answering because I was curious as to what exactly was the problem, and from my investigation, it is clear you need to learn basic debugging techniques. So, I will walk you through how I did it. First, I ran it with some "reasonable" values for the arguments p1 = program[5, Pi, 1, 1] which returned a plot with what appears to be a single point in ...

4

To "official-ize" my comments above, use RuleDelayed: A[1, 2, 4, 5] /. A[a__] :> Position[{a}, 4] {{3}} The reason to use RuleDelayed here is the same as SetDelayed. They both keep the rhs unevaluated until the rule is used, meaning that once the pattern matches on the lhs, a__ is substituted in for a on the rhs. Otherwise with normal Rule, rhs is ...

1

The simplest way that comes to my mind is to substitute your list of vertices for the list of vertices used to draw the cube available through PolyhedronData. The code for doing that would be Module[{ cube = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1}, {1, -1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}}, p = PolyhedronData["Cube", ...

6

What follows is, of course, a terrible hack... since NMinimize is implemented entirely in top-level Mathematica, its code allows inspection by spelunking tools. The relevant function is NMinimize[1, x]; (* force autoloading *) Needs["GeneralUtilities"] PrintDefinitions[OptimizationNMinimizeDumpCoreDE] and the desired behavior can be achieved by ...

6

Here are a couple of other options: Use system option "StrictLexicalScoping" If you use SetSystemOptions["StrictLexicalScoping" -> True] Then your code runs fine (I changed the input to hun to avoid other errors): With[{fun = makeFun[10]}, hun[x_] := fun[x]; hun[Range[15]]] (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *) Reasonably general top-level ...

7

One possible workaround is to "turn off" the name rewriting that Function does is makeFun, and provide a name for the formal parameter you know is unique. There are several ways of doing this, but this one is mine: In[6]:= Module[{x, function}, Attributes[function] = HoldAll; makeFun[len_] := function[x, Take[x, ...

0

I am not sure if it has already be mentioned. Adding Object-Oriented Capabilities to Mathematica

12

Cloud symbols are stored in cloud objects (under $CloudSymbolBase) and local symbols are stored in local objects (under$LocalSymbolBase), which can be addressed using CloudObject and LocalObject respectively. DeleteFile can be used for both cloud and local objects, for example DeleteFile[CloudObject["MySolution", $CloudSymbolBase]] ... 0 (Code to extract text from cell copied from John Fultz here.) This needs work but it's the start of one possible approach. To split a tagged cell at semi-colons: nb = EvaluationNotebook[]; cellObject = First[Cells[nb, CellTags -> {"MyCode"}]]; SelectionMove[cellObject, All, Cell]; text = First[ FrontEndExecute[ ... 3 Update: I realized that version 10 now has FindCycle, which takes care of this easily, e.g. FindCycle[PetersenGraph[5,2], 5, All]. The solution of @kglr is unfortunately flawed: to look for 6-cycles in g = GridGraph[{3, 2}], it would look at whether CycleGraph[6] is isomorphic with g, which it is not. We need to test for subgraph isomorphism without ... 3 As I noted in an earlier comment, the ODE to be solved can be rewritten as eq = y'[x] == Log[1 - Exp[-y[x]]] Then, s = First@NDSolve[{y'[x] == Log[1 - Exp[-y[x]]], y[0] == 1}, y, {x, 0, 5}]; Plot[Evaluate[ReIm[y[x] /. s]], {x, 0, 5}, AxesLabel -> {x, y}] where Re[y] is blue, and Im[y] is tan. Because the ODE is singular at y == 0, it is natural ... 6 Use Rasterize[..., "Image"] to avoid double rasterization When working with image processing functionality like ImageResize etc. it is important to know that these functions always expect an object with Head Image as input and not Graphics. It is somewhat counterintuitive but Rasterize by default produces not an Image but a Graphics object which will be ... 1 The following is in the right direction if you include the answer to invalid Symbol characters also. opts = {"$divide$" :> "/", "$backslash$" :> "\\", "$period$" :> ".", "$tilde$" :> "~", "$backtick$" :> "`", "$exclaim$" :> "!", "$at$" :> "@", "$number$" :> "#", "$dollar$" :> "$", "$percent$" :> "%", "$caret$" ...

2

Although the code you posted does not execute as-is, your report that it works on your end as far as the initialization of the input field and plot region go. I will therefore only tackle the problem with FileNameSetter here. It has been reported before that Manipulate doesn't directly accept FileNameSetter as a control type (Manipulate and FileNameSetter ...

Top 50 recent answers are included