9
votes
3answers
107 views

Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
0
votes
0answers
72 views

How to save the results in an identical Excel file (.xls) in each iteration of a Do loop

Assume the following code (Below code is just an example to clearly illustrate my problem): ...
0
votes
0answers
88 views

A problem with functions and Infinite expression 1/0 encountering

Following code (function) makes integrals and then replace f[x] with Cos functions and calculate the definite parametric ...
0
votes
1answer
105 views

A problem with set values

The following code is just an example to clearly explain my problem. Assume that : ...
0
votes
1answer
84 views

How to produce functions [closed]

I want to produce n functions. For example, assume that by giving n=3, 3 definite integrals will be created, like the following: ...
1
vote
1answer
113 views

How to replace a list with the result list after each iteration [closed]

I have some initial values such as L1 list: L1={10,20,30,40,50}; I want to use the L1 ...
0
votes
1answer
47 views

How to put some values from a list into a function in a Do loop

I want to program a code in MATHEMATICA in order to calculate some values in different iteration. For example, assume this list: list={1,2,3,4,5} Now assume that ...
1
vote
1answer
103 views

Requesting explanation of FitModel code

I am struggling with understanding the code given in this original post I understand how the tests are conducted, both of them. However, I do not understand this part: ...
0
votes
1answer
100 views

Holding Input Windows

I am creating a Mathematica document which contains a list of proofs in various fields of Mathematics so that I can easily review whenever I would like. First, I create a large set I call 'proofs' ...
4
votes
2answers
263 views

Can Mathematica functions have static variables?

In C, one can have variables that are declared static. These are not re-initialized every single time a function is called. ...
8
votes
3answers
181 views
-4
votes
1answer
110 views

Programming Multipolar Expansions in Spherical Tensors

We have that a density matrix can be written in a basis of spherical tensors: $\rho =\sum _{K=0}^S\sum_{q=-K}^K \rho _{\text{Kq}}^{(S)} T_{\text{Kq}}^{(S)}$ for example for a 3x3 matrix, $S=1$, ...
1
vote
1answer
194 views

Gram Schmidt inner and outer products

I know the Gram-Schmidt orthogonalization generates an orthonormal basis from an arbitrary basis. I need help with: Write a program that inputs a list $\{b_1,\dotsc,b_n\}$ of linearly independent ...
16
votes
12answers
1k views

Pick elements of largest absolute value

For example, given list = {{1, -3, -5}, {2, 1, 6}, {0, 2, 4}, {-9, 2, 6}} should return: {-5, 6, 4, -9} Updated I found ...
2
votes
1answer
85 views

Map and Scan ignore HoldFirst

I am trying to write a simple function that takes a list of data and outputs it to a file. I'd like the name of the file to be the same as the variable that holds the list. It seems that giving a ...
8
votes
1answer
132 views

Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
8
votes
1answer
120 views

Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?

Consider the following expression: Block[{Print = CopyToClipboard}, doSomething[]] Now all calls to Print from ...
34
votes
9answers
7k views

Generating a Sierpinski carpet

I am trying to draw a Sierpinski_carpet. I have code that works, but I think there is a more elegant way to do than my way. Maybe I couls use Tuples or ...
11
votes
3answers
922 views

What is Mathematica's equivalent to MATLAB's filter function?

The MATLAB code filter(0.5,[1, -0.5], [1:10]) is equivalent to Rest@FoldList[(#1 + #2)/2. &, 0, Range[10]] I don't ...
4
votes
2answers
155 views

How to achieve Set+Part like behaviour in custom Set function?

So I've been toiling away on my DataFrame package. I've been trying to get Set to work with it, but it seems it either can't be done (ie via ...
2
votes
1answer
147 views

Rookie mistake in defining a function with Modules?

I can't figure out what's wrong with this piece of code. I'm trying to define a function that counts the occurrences of x, y and ...
2
votes
3answers
267 views

How do I construct a pure function to extract data fields from records that are strings?

How can I get from data segment format to the final segment format with a pure function? The data fields are fixed length. There are no separators between the fields. a) list ...
6
votes
2answers
2k views

How to define a differential operator?

I have a linear differential operator, for instance, $L\left (\partial _{t} \right )=\partial _{tt} - 3\partial _{t} + 2$. I use it in 2 different ways: apply the operator to a function: $L\left ...
1
vote
0answers
193 views

Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using NDSolve. The result from this is e.g. either ...
12
votes
1answer
273 views

Modules that initialize themselves on first call

I use a lot of functions that extract a specific data item from a file with many data items. I want these functions to load data (slow) and return the item (fast) on first call, but just return the ...
4
votes
2answers
2k views

Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual ...
19
votes
4answers
643 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 ...
14
votes
1answer
237 views

How to make a function like Set, but with a Block construct for the pattern names

How can we define a function that works like f[x_]=ComputeSomething[x] and treats x as a variable that does not have a value? ...
42
votes
6answers
2k views

Functions vs. patterns

Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
21
votes
3answers
1k views

Sum over n variables

What is the most painless way to sum over n variables, for example, if the range of summation is $i_1 < i_2 < i_3 < \dots < i_n$, where $n$ is an argument of the function in question? Is ...