# Questions tagged [function-construction]

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.

2,337 questions
Filter by
Sorted by
Tagged with
182 views

### Building A Function Using Constants From a List

I want to build a function of the form $f(t)= C + \sum_i A_i*Sin(f_i*t+\phi_i)$ Where $(A_i,f_i,\phi_i)$ are amplitudes, frequencies and phases that I have stored in a text file. Here is my attempt: <...
576 views

### How to plot a point with two colors?

How can I use this type of marker for this? ...
106 views

### How to gather functions which intersect at the same point?

How to gather functions which intersect at the same point (real solution)? func = {2 x, x^2 + 1, (x^3 + 3)/2}; For example, with the list of functions above I ...
118 views

### Using the Apply construction

I am puzzled about the use of Apply (@@). Consider g = t; g1 = Function @@ {t, g} g2 = Function[t, g] Why does g2 differ from g1? I had thought they would be ...
1 vote
64 views

### Function defined through conditional pattern and derivative

If I define a function through a conditional pattern, its derivative is not defined in the whole domain of the original function... Minimal code to reproduce : for instance, I define ...
395 views

### Better way to do such iteration

Consider such an iteration function ...
98 views

### How to delete edges from a graph with some condition?

I want to delete an edge and its reversed edge from a graph (if they exist in the graph). It would be OK to use EdgeDelete[g, {edge, Reverse[edge]}] if these two ...
70 views

### Sort a list using a scoring list with Switch [duplicate]

I have a minimal working example (MWE) list called listToSort that is a list of string triplets: ...
1 vote
95 views

### Define a function on a MeshRegion

This looks like a simple question with the answer to be easily found, but unfortunately I could not find it either on the web or in the documentation browser. Let us assume we have a MeshRegion ...
2k views

### How can I ignore an argument?

I made some code (attached below). It is meant to make a list of random numbers that is not divisible by some value k. I wish to be able to not enter a value k, and have the code run regardless. It ...
388 views

### How to make a function take another function as an input?

I am quite new to mathematica, and I simply want to know how to make a custom function, take another arbitrary function as an input. I have attached code that shows what I am trying to accomplish (...
2k views

### Automating interesting ways to write 2023

Inspired by Interesting ways to write 2023, I was wondering if there are ways to automate the search for results using MMA. I tried ...
56 views

### Failing to define a function? [duplicate]

I am trying to define a function and it apparently is not working. Here is my small working example: ...
67 views

### Create a function that can assign values to different variables in Mathematica

Here I am trying to create a function that can assign values to different variables in Mathematica. Assume the function f[a _, b _, c _]; x1 = a; x2 = b; x3 = c; ...
83 views

### Constructing a function that returns two distinct values by Mathematica

I'm trying to enter a function in Mathematica that can take two inputs, a, and b, and return two outcomes based on those two numbers. I will assume the name of this function as Resultsf[a _,b _] the ...
1 vote
90 views

### Trying to understand weird behavior in function? [closed]

I wrote this function: ...
54 views

### Is it possible to combine a default value in a function definition with type-checking, in case the optional parameter is actually given in a call?

1.) In a function definition, e.g. ...
53 views

### Piecewise function with form determined by current value

I would like to create a piecewise function that determines the dynamics of a variable $x_t$ as follows: Given a starting value $x_0$ and a parameter $\hat{x}$: ...
92 views

### How does one pass an arbitrary expression (or expressions) to a function to later be evaluated? [closed]

This isn't my exact use case, but I think the answer will still be applicable to what I'm doing. I essentially want to create a function with which I can pass an expression (or list thereof), certain ...
163 views

### Returning an InterpolatingFunction

I am trying to write a function using Block that generates an InterpolatingFunction and then generates a second InterpolatingFunction that is a function of the first. I can return and use the first ...
1 vote
107 views