Questions tagged [wolfram-mathematica]

Wolfram Mathematica is a computer algebra system and programming language from Wolfram Research. Mathematica has its own Stack Exchange site at https://mathematica.stackexchange.com/ and that site is the preferred place to ask questions about it.

Wolfram Mathematica is a computer algebra system and programming language from Wolfram Research. The programming language is a term-rewriting functional programming language strongly influenced by . Not to be confused with mathematics ().

Mathematica has its own Stack Exchange site. That is the preferred site for asking questions on this topic.

Tips for asking Mathematica questions

  • Include self-contained source code or a link to a notebook that illustrates the issue
  • Include relevant image, for a graphics related question

A chat room for the tag is available here. It is intended for discussion of some meta-related problems and perhaps some social activity.

Free Mathematica Programming Book


Don't forget to check out our little Tool Bag and add your favorite tricks there.

4457 questions
27
votes
5 answers

Sprintf equivalent in Mathematica?

I don't know why Wikipedia lists Mathematica as a programming language with printf. I just couldn't find the equivalent in Mathematica. My specific task is to process a list of data files with padded numbers, which I used to do it in bash…
jxy
  • 784
  • 7
  • 16
26
votes
5 answers

How to insert a column into a matrix, the correct Mathematica way

I think Mathematica is biased towards rows not columns. Given a matrix, to insert a row seems to be easy, just use Insert[] (a = {{1, 2, 3}, {4, 0, 8}, {7 , 8, 0}}) // MatrixForm 1 2 3 4 0 8 7 8 0 row = {97, 98, 99}; (newa =…
Nasser
  • 12,849
  • 6
  • 52
  • 104
26
votes
2 answers

How do I access the StackOverflow API from Mathematica

I was wondering the other day if StackOverflow had an API I could access from Mathematica, and apparently it does: "Saving plot annotations" What's the best way to get data from StackOverflow into Mathematica? Sjoerd used the information to make a…
Brett Champion
  • 8,497
  • 1
  • 27
  • 44
26
votes
3 answers

Mathematica - Separating Notebooks

Is there a way to separate open Mathematica notebooks so that they don't share any variables? How about making it so some variables are shared but not all?
knpwrs
  • 15,691
  • 12
  • 62
  • 103
25
votes
3 answers

Mathematica "linked lists" and performance

In Mathematica, I create singly linked lists like so: toLinkedList[x_List] := Fold[pair[#2, #1] &, pair[], Reverse[x]]; fromLinkedList[ll_pair] := List @@ Flatten[ll]; emptyQ[pair[]] := True; emptyQ[_pair] := False; Using the symbol pair for…
Pillsy
  • 9,781
  • 1
  • 43
  • 70
25
votes
2 answers

How does a system like Wolfram Alpha or Mathematica solve equations?

I'm building a web-based programming language partially inspired by Prolog and Haskell (don't laugh). It already has quite a bit of functionality, you can check out the prototype at http://www.lastcalc.com/. You can see the source here and read…
sanity
  • 35,347
  • 40
  • 135
  • 226
24
votes
2 answers

Exposing Symbols to $ContextPath

There are a variety of Internal`context functions that are useful, such as InheritedBlock, Bag and StuffBag, etc., as well as many useful Developer` functions. I wish to expose a selection of these symbols such that they may be addressed plainly…
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
24
votes
4 answers

Mathematica: How to clear the cache for a symbol, i.e. Unset pattern-free DownValues

I'm a bad cacher: Sometimes, when no one is watching, I'll cache results without including the full context like so: f[x_]:=f[x]=x+a; a=2; f[1]; DownValues[f] Out[2]= {HoldPattern[f[1]]:>3,HoldPattern[f[x_]]:>(f[x]=x+a)} This leads to horribly…
Janus
  • 5,421
  • 2
  • 26
  • 37
24
votes
5 answers

Performance difference between functions and pattern matching in Mathematica

So Mathematica is different from other dialects of lisp because it blurs the lines between functions and macros. In Mathematica if a user wanted to write a mathematical function they would likely use pattern matching like f[x_]:= x*x instead of…
Samsdram
  • 1,615
  • 15
  • 18
24
votes
3 answers

plotting legends in Mathematica

How do you plot legends for functions without using the PlotLegends package?
Wombat
  • 241
  • 1
  • 2
  • 3
23
votes
4 answers

What are the benefits of switching from Rule and /. to OptionsPattern[] and OptionValue in a large application?

Old habits die hard, and I realise that I have been using opts___Rule pattern-matching and constructs like thisoption /. {opts} /. Options[myfunction] in the very large package that I'm currently developing. Sal Manango's "Mathematica Cookbook"…
Verbeia
  • 4,400
  • 2
  • 23
  • 44
23
votes
5 answers

Using Array and Table Functions in Mathematica. Which is best when

I have been mostly a Table functions user in mathematica. However I have noticed that in several examples where I used Array instead of Table to express the same result, it ran markedly faster, especially as the dimension of table grew larger. So my…
Phil
  • 815
  • 1
  • 8
  • 15
23
votes
5 answers

Symbolic Matrices in Mathematica with unknown dimensions

Is there a way to do symbolic matrix algebra in Mathematica for matrices where the dimensions are unknown? For example, if I have an MxL matrix A and an LxN matrix B, I would like to be able to enter A.B And have it give me a matrix whose element…
jack
  • 285
  • 1
  • 2
  • 8
22
votes
3 answers

How to define a function by intervals in Mathematica?

How can I define a function f(x) in Mathematica that gives 1 if x is in [-5, -4] or [1, 3] and 0 otherwise? It's probably something simple but I just can't figure it out!
Dunda
  • 355
  • 1
  • 2
  • 7
22
votes
6 answers

HCL color to RGB and backward

I need an algorithm to convert the HCL color to RGB and backward RGB to HCL keeping in mind that these color spaces have different gamuts (I need to constrain the HCL colors to those that can be reproduced in RGB color space). What is the algorithm…
Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93