Questions tagged [faq]

Frequently Asked Question – a tag for original questions which have a multitude of duplicates

Filter by
Sorted by
Tagged with
8 votes
3 answers
644 views

How to clear up RAM without exiting kernel?

I am trying to implement the code which generates some table, works with it, extracts some numbers, add them to some other table, then clears the table (only the table and not the other elements of ...
user avatar
  • 3,542
5 votes
1 answer
157 views

With vs. Block scoping of parameters for Plot

A very basic question.. Why does Block work, but not With, to specify value of a parameter for a function to be plotted? ...
user avatar
  • 11.3k
4 votes
1 answer
146 views

How to preserve scaled circular shapes when combining graphics?

The following code g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], Disk[{5, 3}, Scaled[0.1]]}, Frame -> True] produces the following output I then ...
user avatar
7 votes
2 answers
714 views

Why changing to float-point value does't improve the speed?

I am testing the first tip of this article Use floating-point numbers if you can, and use them early. I've compared a pair codes and finding it's not helpful to use the float-point number during ...
user avatar
  • 683
4 votes
3 answers
188 views

Keep only rules that replace integers with other integers

Let's say I have a list of replacement rules: List1 = {2 -> 3, b -> 5.5, 6.57 -> 2, 3 -> 4.5, 1 -> -1, 0.03 -> 0.5, 9 -> a} The desired ...
user avatar
  • 43
7 votes
2 answers
333 views

Grid with Frame->All: How to not draw frames around empty cells?

If I have a grid of values that doesn't divide evenly, for example a list of 17 values, and split it into a 7x3 grid, then draw frames around each element: ...
user avatar
106 votes
4 answers
21k views

Why should I avoid the For loop in Mathematica?

Some people advise against the use of For loops in Mathematica. Why? Should I heed this advice? What is wrong with For? What ...
user avatar
  • 224k
11 votes
4 answers
2k views

Capital Letters that are built-in symbols

I'm trying to search for an answer to "What is the complete list of single capital letters that represent built-in Mathematica commands, symbols, or uses?" For example: C, D, E, I, N, O Is this ...
user avatar
  • 14.5k
8 votes
1 answer
573 views

Package functions and symbolic calculations

I'm writing my package (.m) in Mathematica and when I call the function it returns 0 instead of a right output. Here's my code: Package.m ...
user avatar
  • 101
2 votes
1 answer
1k views

Piecewise Function, Explanation of Extra Case

Consider: Can someone explain why the 0, True occurs? As a second question, I like to fill the endpoints as follows: ...
user avatar
  • 14.5k
29 votes
1 answer
31k views

What do the X and Y axis stand for in the Fourier transform domain?

In Wolfram Mathematica the function Fourier has the following declaration Fourier[list] And after a list is given to the ...
user avatar
52 votes
3 answers
5k views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
user avatar
  • 645
9 votes
2 answers
3k views

A problem about function N

Toady,I have a problem about N,described as below: For example N[1/3, 5] (* ==> 0.33333*) and ...
user avatar
  • 435
7 votes
4 answers
952 views

Efficient method for Inserting arrays into arrays

This is strongly related to the following Questions: Looking for a way to insert multiple elements into multiple positions simultaneously in a list Building matrices by attaching vectors (columns) ...
user avatar
  • 1,839
17 votes
5 answers
15k views

Matrix Multiplication in context of row and column vectors

I've been looking at some matrices in Mathematica and I've noticed something very weird: they're extremely temperamental when it comes to dot products! For example, if I have the following, ...
user avatar
24 votes
2 answers
7k views

Error entering equation in DSolve

I entered a command incorrectly as follows: DSolve[{y'[x]=y[x]},y[x],x] I am now experiencing: ...
user avatar
  • 14.5k
9 votes
1 answer
654 views

Understanding NDSolve::ndsz

I'm working on a largeish system of differential equations where I encounter the NDSolve::ndsz step size is effectively zero; singularity or stiff system suspected ...
user avatar
  • 1,147
41 votes
3 answers
35k views

How can I plot implicit equations?

If you enter the following into Wolfram | Alpha, you get nice graphs: graph 4 x^4 + y^2 = 2 How do you do this in Mathmatica? I realize that these are not ...
user avatar
  • 481
14 votes
5 answers
10k views

How to plot periodic function's graphic?

How to plot periodic function's graphic? For example, $f(t) = t$ when $-5<t<5$ and $f(t+10) = f(t)$. ...
user avatar
  • 435
4 votes
2 answers
2k views

Mathematica not plotting whole logarithmic function

I am trying to use the following input Plot[Log[E,x+1],{x,-50,50},PlotRange->50] however the output is: How can I adjust it so the line goes down to the <...
user avatar
  • 193
8 votes
1 answer
532 views

Preventing cell height adjustment when rotating 3D graphics

I have a large dataset of scattered x,y,z coordinates. I am trying to use ListPointPlot3D to identify outliers in 3D. This involves generating a plot and then ...
user avatar
  • 3,623
12 votes
2 answers
564 views

Unexpected behavior of rule matching a pattern

I am a beginner exploring the world of Mathematica. I expected the following code T[6, 5, 4, 1, 2, 3] /. {T[a___, 1, b___] -> Length[List[b]]} should return ...
user avatar
12 votes
3 answers
13k views

Replace very small numbers by zero in the output of a list

I have a long nested list, but many elements are numbers of order 10^-18 or less, e.g. ...
user avatar
  • 795
26 votes
5 answers
6k views

Extracting variables from an expression

I'm looking for a way to extract a list of variables from an expression, for example with an input like: ...
user avatar
  • 630
50 votes
5 answers
3k views

Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs

Using global variables the following turns an "expression" into a Function: expr = 2 x; Function[x, Evaluate[expr]] Of course ...
user avatar
  • 3,964
19 votes
4 answers
2k views

Splicing a list of arguments into a function with Sequence

Not sure if this has been asked, but I have a fairly simple operation that I don't know the syntax for. Say I have an array with some values, and a function f that accepts an arbitrary number of ...
user avatar
  • 5,977
524 votes
37 answers
119k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
38 votes
4 answers
10k views

How to modify function argument?

Usually in programming languages, function arguments are normal local variables, which can be modified. Is this not true in Mathematica? ...
user avatar
  • 1,993
11 votes
1 answer
4k views

White regions in DensityPlot?

When I try to supply my own ColorFunction Mathematica seems to partially ignore it, and the white color "burns through" if the function is too "sharp&...
user avatar
49 votes
4 answers
17k views

How do I work with Root objects?

I want to solve the trigonometric equation : $$(3-\cos 4x )\cdot (\sin x - \cos x ) = 2.$$ I tried Solve[(3 - Cos[4*x])*(Sin[x] - Cos[x]) == 2, x] It returns the ...
user avatar
  • 4,353
31 votes
4 answers
48k views

How do I identify the source of a "Tag times protected" error?

I have some code that looks like Table[ a = 1; b = {2, 3} c = i;, {i, 2} ] which gives an error: Set::write: Tag Times in c {2,3} is Protected....
user avatar
  • 5,172
33 votes
3 answers
8k views

How do I convert an argument list to a sequence of arguments?

I think this is a basic question, but I am having difficulty finding the answer in the documentation. Thread is not what I am looking for, I think. Suppose that I ...
user avatar
  • 9,415
10 votes
1 answer
665 views

Confused by (apparent) inconsistent precision

$$ e^{\pi \sqrt{163}} \approx 262537412640768743.99999999999925 $$ E^(Pi Sqrt[163.0]) N[E^(Pi Sqrt[163.0]), 35] NumberForm[E^(Pi Sqrt[163.]), 35] returns <...
user avatar
  • 6,616
31 votes
6 answers
4k views

How are parameters evaluated for a Plot in Manipulate

I am trying to get my head around how Manipulate evaluates functions in a Plot. I have read the introduction to Manipulate, and introduction to Dynamic, but I still ...
user avatar
  • 787
23 votes
3 answers
912 views

Nested definition: How can I define a function with a passed-in expression?

Here's a simplified version of what I'm trying to do: ...
user avatar
  • 18.8k
35 votes
1 answer
2k views

Why are all the lines commented when I create a Mathematica script?

When I created a Mathematica script, I found that all my lines were commented out (when opened with vi or gedit or any other ...
user avatar
  • 5,172
12 votes
2 answers
3k views

Evaluating an If condition to yield True/False

I would like to decide whether an option passed to my custom function has the value Automatic or something else. This is my attempt: ...
user avatar
45 votes
4 answers
4k views

Function in Table

I need a table with the elements made of pure functions and list elements. This is a simplified example: I need a list as: ...
user avatar
  • 4,685
59 votes
8 answers
95k views

Assign the results from a Solve to variable(s)

I understand Mathematica can't assign the results of a Solve to the unknowns because there may be more than 1 solution. How can I assign the 4 values of following result to variables? ...
user avatar
  • 6,616
42 votes
4 answers
4k views

Can a function be made to accept a variable amount of inputs?

I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
user avatar
  • 4,360
10 votes
2 answers
1k views

Programming with Dynamic

I don't understand the following: f[a_, b_] := a + b ls = {1, 2, 3}; MapThread[f, {ls, {10, 20, 30}}] This yields ( as expected ) {11,22,33} If I change ...
user avatar
11 votes
2 answers
798 views

Dr. StrangeNumbers or: How I Learned to Stop Worrying and Love Floating Point Arithmetic

The following is the program. ...
user avatar
  • 373
5 votes
1 answer
991 views

Change the height of a function being plotted

How do I alter the height of any function plot using the Plot function? Mathematica seems to limit the height of the plot up to the range of a function and distort ...
user avatar
  • 1,079
21 votes
7 answers
2k views

Combining values in one column (or part) when values in another column (or part) match

Consider the following: ...
user avatar
  • 4,221
52 votes
6 answers
11k views

Finding real roots of negative numbers (for example, $\sqrt[3]{-8}$)

Say I want to quickly calculate $\sqrt[3]{-8}$, to which the most obvious solution is $-2$. When I input $\sqrt[3]{-8}$ or Power[-8, 3^-1], Mathematica gives the ...
user avatar
  • 1,372
58 votes
4 answers
10k views

Can I simplify an expression into form which uses my own definitions?

This seems like a simple thing to do, but I couldn't find anything relevant from Mathematica documentation. So suppose I have an expression: a*b/(a + a*Cos[a/b]) ...
user avatar
  • 951
59 votes
8 answers
25k views

How to avoid returning a Null if there is no "else" condition in an If construct

I need to use If but with only one option that is if "a" then do "b", else do nothing. So I wrote If[a,b] but the problem is ...
user avatar
  • 701
32 votes
6 answers
17k views

Replacing composite variables by a single variable

To replace a single variable by another variable, one can simply use the the replace all (/.) operator (e.g., ...
user avatar
  • 1,347
42 votes
5 answers
47k views

Plotting Complex Quantity Functions

Trying to plot with complex quantities seems not to work properly in what I want to accomplish. I would like to know if there is a general rule/way of plotting when you have complex counterparts in ...
user avatar
  • 1,699
48 votes
4 answers
3k views

Funny behaviour when plotting a polynomial of high degree and large coefficients

I am trying to plot a polynomial of degree $29$ on the domain $[0,1]$, with fairly large coefficients: ...
user avatar
  • 1,473