Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 193

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.

2 votes

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 *)
4 votes
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 …
3 votes

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} *)
5 votes
Accepted

Easiest way to create a binary variable

Boole@Thread[Greater[x, y]] == MapThread[Boole@Greater@## &, {x, y}]
6 votes

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 *) …
4 votes
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 …
2 votes

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]] + …
3 votes
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 …
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]]
2 votes

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]]; …
0 votes

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 + …
3 votes
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 …
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 …
2 votes

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_] : …
12 votes
Accepted

Plotting a moving ball for projectile motion with animate

The same, but more Mathematica-ish (working with functions, representing vectors as lists and using NestList instead of variables and looping-appending): Clear["Global`"]; dt = .01; velInit = {0, 1.2 …

15 30 50 per page