For questions on writing functions (pure or using Set/SetDelayed) for any purpose, including the features that may be incorporated in those functions, such as options, patterns and conditions.

learn more… | top users | synonyms

6
votes
4answers
207 views

Find function inverse

I'm trying to find the inverse of a function: (30*x^2 (1 - x)^2) (* where 0<x<1 *) I tried all the following options: 1. ...
3
votes
3answers
76 views

Defining a function that that evaluates a function to obtain a value not supplied as an optional argument

I have a function like this CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_] Now, I want to add a new parameter ...
2
votes
1answer
59 views

Using HoldFirst but not wishing to hold everything

I have a DynamicModule in which I go through some data analysis and keep or reject the results. Here is a toy example of what I am doing. ...
1
vote
1answer
82 views

Function returned an unexpected list

I was trying out a question in Wellin's Programming with Mathematica that says the following. Question: Given a set of points in the plane (or 3-space), find the maximum distance between any pair of ...
2
votes
0answers
49 views

How to make a new analytic function work seamlessly with Mathematica's analysis functions?

I am defining a new analytic function of six variables. I have algorithms to evaluate it numerically, and have amassed a large catalog of analytic properties. It is easy for me to program the ...
4
votes
0answers
147 views

Strange behaviour of MMA in derivatives of some standard functions

There are some peculiar things to be discovered in derivatives of some standard functions in MMA: Strange behaviour Example 1: Abs We have ...
3
votes
0answers
53 views

Listable on first level

I have some function which take List as input. f[l_List]:=someActions[l] I need apply this function to a list of lists. Now I ...
0
votes
1answer
43 views

Output a symbol from Module or Block

I have troubles to output an entire symbol, a function in this case, from a module or a block. For instance myf = Block[{f}, f[3] = 33; f[4] = 4; f] Then I want ...
1
vote
1answer
52 views

PDF for Normal-Gamma Mixture

The normal-gamma mixture is: ...
7
votes
2answers
160 views

Error computing sum of sum of digits

I've defined a function that computes the sum of the base-b digits of n: DigitSum[n_, b_] := Total[IntegerDigits[n, b]] Then I defined a function that computes ...
4
votes
2answers
116 views

How to understand the process of ListCorrelate when it in two-dimensional condition?

Toady,I learn a function ListCorrelate,and I can understand process of execution his result in one-dimensional. However,the ...
2
votes
2answers
78 views

How to make functions from datasets

I have a csv that encodes the results of plugging certain parameters (say, A and B) into certain functions (say, ...
1
vote
1answer
37 views

Specifying independence of a variable in a function

I am dealing with a function of a finite number of variables and among the operations I wish to do is to differentiate it repeatedly with respect with any of the variables. Now this function happens ...
2
votes
1answer
42 views

How do I tweak the input assistant to use string completion on my own functions? [duplicate]

I would like to be able to use Mathematica's string completion feature for subvalues of my own functions. I tend to go for functions that follow the pattern ...
1
vote
1answer
82 views

Passing function as argument

I've been mucking around with passing functions as arguments to other functions and via trial and error seem to have something that works. I was wondering if someone could have a quick look at some ...
2
votes
2answers
80 views

Local variables whose definitions depend on each other [duplicate]

Consider the following (pseudo-)function definition: f[l_] := Let[{ a = Length[l], b = First[l], c = b/a, }, c*10] So for ...
0
votes
1answer
41 views
5
votes
3answers
208 views

difficulty abstracting the OptionValue pattern

I am building lots of functions that use Options and OptionValue and wanted to reduce the redundancy in the expressions that ...
3
votes
2answers
70 views

How to define a nestable Baseform function, BaseForm output becomes BaseForm input

Mathematica won't change a number's BaseForm recursively: 63969 // BaseForm[#, 16] & // BaseForm[#, 8] & // BaseForm[#, 2] & Well, I inspected former ...
7
votes
2answers
172 views

Account for powers of 0 and 1 when defining function

I have a function that I am defining as (assume m,n,a,b are non-negative integers): myfcn[x_^m_ p_^n_, x_^a_ p_^b_] := basefcn[m, n, a, b]; and then extending to ...
7
votes
2answers
343 views

Mapping data on Archimedes' spiral

I would like to map my data on Archimedes' spiral and preserve the distance between points on the curve. The test data consists of 20 evenly spaced {x,y} ...
3
votes
5answers
246 views

How to add periodicity to condition?

Is it possible to set the following function f[a], where a can be any real number? $$ f(\alpha) = \begin{cases} 1 ...
6
votes
1answer
93 views

Functional-Style Partial Application and the Accumulator Pattern?

Following up on Functional-style Fixed-Length Queue Object?, I want to generalize it to a functional-style accumulator pattern. Lots of things look like accumulators, loosely defined as binary ...
2
votes
1answer
217 views

Make a scatter plot

Considering I have weather data for last 10 years for London, how can I make a scatter plot that will show the previous day's temperature as a function from today's temperature?
2
votes
1answer
173 views

Finding average error of the data

Considering I have some data, and I want to fit the data to a linear fit and find the average error from the linear fit, how can I do that using Mathematica? I have ...
2
votes
1answer
93 views

Extract data from WeatherData as a list of associations

Given weather data for 2013 and 2014 as follows: ...
1
vote
2answers
217 views

Error with “Newton's method” in Wellin's Mathematica book

In Wellin's Programming with Mathematica book, here's one of his implementations of the Newton method, where the iteration runs until the error tolerance is reached. ...
1
vote
1answer
56 views

Remove curly brackets _completely_ to map a function to the elements of a list [duplicate]

Most list manipulations can be done with Flatten, Partition and Take. I didn't managed to ...
1
vote
1answer
73 views

How can I write a function which takes another function of a variable and the variable itself as arguments and gives a list of critical points?

This is an exercise from Power Programming with Mathematica by Wagner. I need a function which takes a function and a variable as arguments, like this: critpts[f_,x_]:= and then on the rhs I've got ...
5
votes
4answers
148 views

Defining a function with parameters as variables

I have an expression V = (a[1] + a[2])b[1]. How would I define a function of a[1], a[2] and ...
1
vote
1answer
28 views

Interpolation function evaluation and timing

Lets define two identical functions $f$ and $g$ in a slightly different way ...
1
vote
2answers
43 views

How to define a variable updating function? [duplicate]

I tried to program a Sudoku solver when I suddenly ran into this problem: I need a function which effectivley does this: ...
0
votes
1answer
29 views

Why would this function work only when I make a copy of the variable? [duplicate]

Why would this function work with a copy of the function variable: ...
1
vote
1answer
44 views

How to Solve a Sequence in Mathematica [duplicate]

Given the input and the output, how do you interpolate a function in Mathematica? For example if you know that $f(1)=\frac{1}{2}$, $f(2)=\frac{1}{3}$, $f(3)=\frac{1}{4}$,... how would you solve for ...
9
votes
1answer
141 views

How can I export my learned ClassiferFunction[] and PredictorFunction[]s?

Mathematica 10 provides beautiful high-level machine learning functionality. Sadly, the learned functions once created are rather opaque objects. I need to use them in other projects, so here is my ...
2
votes
1answer
95 views

Why is either Listable or HoldFirst not working?

Starting with a fresh kernel, I evaluate the following: ...
18
votes
2answers
1k views

Best practice of passing a large number of parameters to functions

I have a number of functions which all take a large number of parameters. I am wondering which is the best practice of passing these parameters to those functions. I could of course simply specify the ...
0
votes
2answers
47 views

Defining a function from a list [closed]

I have a list of 49 numbers, and I would like to define a function f such that f(n) is simply the nth number in the list. How can I do this?
3
votes
1answer
56 views

Manipulate inside a function definition slows down when passed a large data set

I'm working with large data sets (>1gb) which I'm visualizing with Manipulate[]. The following example works fine for me with no additional memory overhead: ...
9
votes
4answers
222 views

Recognizing special cases of a defined function for permuted arguments

I have a number of ugly ways to implement the following pattern recognition task, but I'm looking for something elegant to keep my notebook tidy. I need to define a function of six variables ...
0
votes
2answers
56 views

Eigenvectors inside a maniupulate function

I am trying to make a physics application and it requires that the eigenvectors be taken for a 3x3 matrix. It is my intention that Mathematica never have to deal with the matrices symbolically. ...
0
votes
1answer
79 views

multiple generators for iterative construction of fractal

The code below is an attempt to use more than one generator (in this case two) to generate a fractal using the standard iterative procedure involving generators. Only the first two stages of the ...
5
votes
3answers
394 views

What is the right way to write a function that includes other functions?

I want to include multiple sub functions: $b(x) = 10x$ $w(x) = s + b(x)$ $c(x) = x^2$ into two main functions: $ua(x) = w(x)-c(x)$ $ub(x) = w(x)-c(x)^2$ As a reaction to this answer, I wrote ...
2
votes
2answers
75 views

Adding a tree to a list of trees within a loop [duplicate]

I'm trying to write a function which for a list of trees checks if a given tree is isomorphic with any of the listed, and if not - adds it to the list. I tried to use both ...
9
votes
3answers
119 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 ...
1
vote
1answer
42 views

Overloading ClearAll[] to take no arguments

I use the command ClearAll["Global`*"] so much that I thought it would be nice to have a function that called it. Since by default ClearAll requires an ...
2
votes
1answer
50 views

Having variables appear aqua in user defined function [duplicate]

In many of the inbuilt mathematica function, variables appear aqua like in: However, when creating your own function, variables no longer have that green coloring and are instead colored like an ...
1
vote
1answer
37 views

Q-Multinomial Coefficient [closed]

How can one compute the q-Multinomial Coefficient as a function of q,m and a list {n1,n2,n3,...} in Mathematica? See http://mathworld.wolfram.com/q-MultinomialCoefficient.html for the definition.
4
votes
1answer
110 views

Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...
3
votes
3answers
158 views

Function that prints a different value than it returns

I want to create a function something like this: test[x_] := (Print[1]; Return[2];) Except it prints 1 when executed as ...