# Search Results

Results tagged with
Search options answers only not deleted user 193
51 results

Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

### Apply Collatz Funtion to solve and print the answer

collatz = Switch[Mod[#, 2], 0, #/2, 1, 3 # + 1] &; count[x1_, s1_] := Length@NestWhileList[collatz, x1, # != s1 &] count[100, 1] (* 26 *)
• 115k
Accepted

### Using function to transform a list

I haven't followed your logic carefully, but you probably want something like Fcoord[coord : {_?NumericQ, _String}] := Module[{x, y}, If[(Mod[coord[[1]], 30]) != 0, y = (Quotient[coord[[1]], 30 …
• 115k

### How would one set up a conditional to evaluate at the last output value (wondrous numbers)

NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, 5, # != 1 &] (* {5, 16, 8, 4, 2, 1} *)
• 115k
Accepted

• 115k

### Is it possible to treat starting values as variables?

Not sure about what you're trying to do, but this doesn't bring up errors: ClearAll[f]; f[a_?NumericQ] := x /. FindRoot[x^2 - 1 == a, {x, a - 1, a + 1}] NIntegrate[f[z], {z, 0, 5}] (* -> 9.13129 *) …
• 115k
Accepted

### Getting imaginary data from known real data using Kramers-Kronig relations

epsilon1as you defined it, isn't a function but a list. You may try something like: {epsilon1, w} = ToExpression@Import["http://pastebin.com/raw.php?i=Z08GwMa8"]; f = Interpolation[Transpose[{Flatten …
• 115k

### Find the best parallel lines to a given data set

An easy, no brain used, direct approach: pts = Table[{x, Sin[x*3] + x/2. + RandomReal[.5]}, {x, 0, 10, .1}]; sol = Minimize[{c2 - c1, And @@ (m #[[1]] + c1 <= #[[2]] <= (m #[[1]] + …
• 115k
Accepted

### How to define a function or procedure that includes multiple steps?

The following does (I believe) the same as your code. Perhaps I could do it better if I understood what are you trying to calculate calc[s_Integer] := Module[{output, latticeWthPadding, neighborhoo …
• 115k
1 vote

### How to obtain a smaller-sized output from Solve

Is something like this useful? s1 = Solve[Table[RandomInteger[100, {15}]. Array[x, 15] == y@i, {i, 15}], Array[y, 15]]; y[1] /. s1[[1]]
• 115k

### Need help looping a notebook evaluation

This is equivalent to your code, and iterates dynamically: f1[t_] := 5*t p = 1/10; k = 6/10; r = {}; SeedRandom[42]; Dynamic[ Refresh[ a = (IntegerDigits@RandomInteger[{1111, 9999}])[[;; 3]]; …
• 115k

### Diophantine and odd

Not efficient, just showing that Mathemtica can do it from "first principles" Reduce[a + b + c == 91 && And @@ Thread[0 <= {a, b, c} <= 51] && Exists[Element[{aa, bb, cc}, Integers], 2 aa + …
• 115k
Accepted

### How can Time be made to go backwards?

Replace your timer = .. by tf = IntegerPart[AbsoluteTime[] + 60]; Dynamic@Refresh[ Show[{digit[#[[-2]], 12], digit[#[[-1]], 15]}, ImageSize -> 26] &@ IntegerDigits[1000 + tf - IntegerPart@Abs …
• 115k
1 vote
Accepted

### How to insert an expression in a Mathematica program?

From the help: Block[{a = 1, b = 2, c = 3, d = 4}, Get["ExampleData/language"]] or Module[{a = 1, b = 2, c = 3, d = 4}, Evaluate@Get["ExampleData/language"]] If you want your variables to be glo …
• 115k

### Question about designing a particular data structure

You could do something like this (draft) c = Red; pcl := {c, Blue}; Module[{preserve, pcl1}, reset[] := (pcl1 = pcl; preserve = {}); reset[]; SetAttributes[set, HoldAll]; set[element_, value_] : …
• 115k