Linked Questions

11
votes
2answers
3k views

How to pass variables by reference and by value [duplicate]

I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-...
10
votes
1answer
1k views

Modifying a List in a function in place [duplicate]

An example will be most specific: func[list_, column_] := list[[All, column]] = Map[#*2 &, list[[All, column]]]; This throws errors. I want to avoid doing ...
0
votes
1answer
1k views

How can I change variable passed to a function? [duplicate]

Sometimes I'd like to make a function, which would take an argument "by reference" instead of usual "by value". This is semantically similar to what e.g. AppendTo ...
1
vote
1answer
609 views

Change input variable in a function [duplicate]

I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way: ...
2
votes
2answers
143 views

How to set a values inside a custom function [duplicate]

I have a custom function like this stringLength[string_] := StringLength[ ToExpression[StringJoin[ToString /@ {del, string}]] = StringDelete[string, " "]] ...
3
votes
1answer
160 views

How to pass multiple results calculated in a module to global variables? [duplicate]

For example, I defined a user function with a module and what this function does is take the values of two global variables ga and ...
1
vote
1answer
109 views

Circumventing the default scoping: Assign a variable inside a function [duplicate]

I'm currently trying very hard to assign a variable inside a function. Therefore I'm using a function like this, which should reassign a predefined variable. ...
0
votes
1answer
115 views

Part assignment is not a symbol [duplicate]

read some related posts and found no solution. For a list defined like this m = {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.0, 1.5, 1.6}; when I define this function ...
0
votes
0answers
76 views

Calling Clear within a function [duplicate]

I want to create a function that when it is called clears the value of a parameter. For example I want to keep the value of a parameter and then clear its valueby calling a function: ...
2
votes
0answers
32 views

How to modify a global large array in a function [duplicate]

Assuming variable x is a long list, which needs 1GB memory to store. I want to modify x in a function, such as let x[[10]]=1, using ...
452
votes
37answers
96k 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 ...
25
votes
5answers
5k views

How to pass a symbol name to a function with any of the Hold attributes?

Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...
20
votes
2answers
728 views

When should I, and when should I not, set the HoldAll attribute on a function I define?

I have seen a number of examples on this site (such as in syntax highlighting and checking evaluation status) in which functions definitions are preceded with ...
8
votes
2answers
2k views

Define a function with a function for an input

I want to create the functions $even[f]$ and $odd[f]$ which will apply the formula $even[f(x)] = \frac{f(x)+f(-x)}{2}$ and $odd[f(x)]=\frac{f(x)-f(-x)}{2}$ for an arbitrary $f$. I tried using <...
6
votes
3answers
6k views

Passing a matrix as a function argument

I am trying to do the following: ...

15 30 50 per page