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.

Filter by
Sorted by
Tagged with
3 votes
3 answers
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: <...
John's user avatar
  • 43
9 votes
3 answers
576 views

How to plot a point with two colors?

How can I use this type of marker for this? ...
hana's user avatar
  • 2,832
2 votes
2 answers
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 ...
emnha's user avatar
  • 2,293
2 votes
1 answer
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 ...
John Bechhoefer's user avatar
1 vote
2 answers
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 ...
coussin's user avatar
  • 301
3 votes
3 answers
395 views

Better way to do such iteration

Consider such an iteration function ...
matrix42's user avatar
  • 6,697
3 votes
1 answer
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 ...
internet's user avatar
  • 217
3 votes
3 answers
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: ...
Andrew's user avatar
  • 9,987
1 vote
1 answer
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 ...
Jürgen Böhm's user avatar
5 votes
5 answers
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 ...
Robin Hansen's user avatar
3 votes
3 answers
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 (...
Robin Hansen's user avatar
15 votes
4 answers
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 ...
Moo's user avatar
  • 2,702
2 votes
1 answer
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: ...
Granger Obliviate's user avatar
0 votes
1 answer
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; ...
Math View's user avatar
2 votes
3 answers
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 ...
Math View's user avatar
1 vote
1 answer
90 views

Trying to understand weird behavior in function? [closed]

I wrote this function: ...
Red Banana's user avatar
  • 5,111
2 votes
2 answers
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. ...
Adalbert Hanßen's user avatar
0 votes
1 answer
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}$: ...
NC520's user avatar
  • 387
2 votes
2 answers
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 ...
sjtumlin16's user avatar
2 votes
2 answers
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 ...
John Bechhoefer's user avatar
1 vote
2 answers
107 views

How to have index of summation equal to all $n$-tuples $\left(b_i\right)_{i\le n}$ with $\sum ib_i = n$ and $b_j$ fixed?

Let $T_n$ denote the set of $n$-tuples $\left(b_1, \ldots, b_n \right)$ of non-negative integers such that $$\sum_{i=1}^{n}ib_i=n.$$ I am trying to simplify the sum (whose indicies depend solely on $n,...
The Substitute's user avatar
1 vote
1 answer
111 views

How to do a 5x5 system using Cramer's rule? [closed]

I need to know how to do a 5x5 system using Cramer's rule.
Khaled Mohamed's user avatar
1 vote
1 answer
131 views

A square board of size n*n [closed]

I would like to Randomly generate n^2 natural numbers in an interval from 1 to n. Then consider placing each number on the cell with the same number (you can imagine the board numbered naturally, row ...
SkySystem's user avatar
4 votes
1 answer
124 views

Is there analogy of function MapIndexed (Map) for Nest?

We have Map and its upgraded variant MapIndexed. Is there analogy for Nest? I know there is ...
azerbajdzan's user avatar
  • 5,935
0 votes
0 answers
51 views

How to assign a variable in mathematica to just the output of an expression?

So, say I wanted to assign a function J[x_, y_] :={D[system, x], D[system, y]}//Transpose where system is some system of ...
Timotheum's user avatar
2 votes
1 answer
63 views

Print out how many times to calculate the sum of the squares of its digits until answer is 1 or 4

I am trying to write a recursive function, toscare1[], that takes as parameter a positive natural number. Then calculate the sum of the squares of its digits, thus creating a new number; then, we ...
SkySystem's user avatar
0 votes
0 answers
41 views

Derive a function and then make a fast version for execution

I would like to derive a (complicated) equation of motion and integrate it efficiently numerically. I can do this "by hand" by copying the resulting function in a new function and then ...
John Bechhoefer's user avatar
0 votes
0 answers
58 views

Kronecker Product for arbitrary number of spins

I want to write a function that can perform the following kronecker product: ...
Gabriele Stevanato's user avatar
0 votes
0 answers
17 views

Generating a 3 variables polynomial with constraints on 2

This post is a follow-up of Generating a 2 variables polynomial with constraints. I would like to generate automatically a polynomial in three variables $(s,t,u)$ which is symmetric under the exchange ...
Rubilax96's user avatar
0 votes
1 answer
43 views

Generating a 2 variables polynomial with constraints

I would like to generate automatically a polynomial in two variables $(s,t)$ which is symmetric under the exchange of those variables. There are three kinds of terms; at order $k$, we have $$(s+t)^k, \...
Rubilax96's user avatar
0 votes
1 answer
66 views

Why did this code break on me? [closed]

Code was executing normally till I got an error message "Tag Times in (x\ Sin[4\ x])[x_] is Protected." ...
SkySystem's user avatar
5 votes
1 answer
151 views

Using Reap Sow to define unsorted union [closed]

In the documentation of Reap under "Applications" paragraph there is this example: ...
azerbajdzan's user avatar
  • 5,935
3 votes
1 answer
86 views

Antiderivative of a piecewise function evaluates wrong inside a subroutine

It's very helpfull to use antiderivative of a given function in the form Derivative[-1][fun][t]! Here my example with a simple piecewise function: ...
Ulrich Neumann's user avatar
3 votes
1 answer
151 views

A workaround needed to overcome the Derivative function anomaly in Mathematica 13

Edits: Additional illustrations are provided for comparison with D[] in Mathematica 12, as clarifying examples, supplemented at the end. An erroneous Derivative ...
ghogoh's user avatar
  • 313
6 votes
3 answers
380 views

How to create all possible graphs that connect all vertices?

How can I generate all labelled connected simple graphs on n vertices? In the image below, I drew examples with number of vertices ...
hana's user avatar
  • 2,832
4 votes
1 answer
128 views

How to evaluate this InverseFunction?

Solving an ODE problem DSolve[{y'[x] == x*(y[x]^2 - 1)^(2/3), y[1] == 3/2}, y[x], x] ...
user64494's user avatar
2 votes
4 answers
178 views

Quick and efficient way to create graphs from a list of list

I want to generate a list of edges from a list: (the size of the list can be changed, just 4 for this example) From the list above, I can generate 24 permutations like this. ...
internet's user avatar
  • 217
6 votes
2 answers
343 views

How to generate a horizontal histogram with words?

I have a dataset of the type: ...
SAC's user avatar
  • 1,295
1 vote
0 answers
65 views

What's the cleanest way to Plot a derivative, or ignore an outer scope in general? [closed]

As the title says, what's the cleanest way to plot a function's derivative in Mathematica? The two best methods I could find were either to define the function beforehand and then use prime notation, ...
Aggs123's user avatar
  • 11
3 votes
1 answer
111 views

How to plot electrical graph from given edges with some constraints?

I'm trying to create a graph like this automatically with edges given and need some help. The graph doesn't need to be exactly same but I would like to make some constraints for the generated graph. ...
hana's user avatar
  • 2,832
1 vote
1 answer
70 views

How to add customized symbols between nodes without affecting the graph?

Is it possible to add some customized symbols between nodes (just for presentation) without affecting the graph? This is an example where I added symbols of resistor, capacitor, and inductor between ...
hana's user avatar
  • 2,832
3 votes
2 answers
129 views

Function to create a connection list

Let assume that i have a list of connections between nodes like this: input = {1 <-> 10, 2 <-> 3, 4 <-> 5, 6 <-> 7, 8 <-> 9}; The ...
hana's user avatar
  • 2,832
1 vote
2 answers
141 views

I want Mathematica to evaluate $\int(1 + \delta (x - \text {x0})) p[x] dx$ as $p[x0]+\int p[x] dx$, where $p[x]$ remains unspecified

I define the simple function: Simp[h_] := Integrate[h[x] p[x], {x, -∞, ∞}] where the function p[x] is continuous, but I want ...
Roy S.'s user avatar
  • 11
4 votes
3 answers
568 views

Can a pure function be constructed whose argument list is a matrix?

Can a pure function be constructed whose argument list is a matrix? Using Function, I know it's not possible, but I'd like to get something like: ...
E. Chan-López's user avatar
1 vote
1 answer
61 views

Default value for function inputs - Not allowing use of one input to define another

I am trying to define a function with a lot of input variables, and some of the inputs are used to define other input variables. If I define them outside of the function and then pass them in I don't ...
Maksymilian5275's user avatar
1 vote
1 answer
77 views

How to define functions using $Z_2$ coefficients and $Z_N$ variables, e.g, realizing $1+1=0$?

A minimal example is to realize the following: $x+x = (1+1)x = 0$, and $x^{N+1}y^{N+1}=xy$, where $N$ is a given positive integer.
SimMach's user avatar
  • 113
0 votes
1 answer
78 views

Mathematica function defining problem

The "F" function is defined as mentioned, but when I call the function F inside the code, "F" can't compute value using the function F, just give F_0, F_1, etc. Can somebody guide ...
Asim's user avatar
  • 1
0 votes
0 answers
45 views

How to double sum or triple sum up over the list of functions?

I'm dealing with a summation problem by now using a list of function $F(x; \theta_i)$. The function is defined as \begin{align*} F(x; \theta) = 1 - \Phi[\Phi^{-1}(1 - \frac{x}{2}) - \theta] + \Phi[-\...
0o0o0o0's user avatar
  • 121
0 votes
1 answer
51 views

Simulate a binomial distribution experiment

I am trying to write a user-defined function to simulate a binomial experiment as following: ...
EconMatrics's user avatar
-1 votes
1 answer
80 views

How to create this function? [closed]

Let vowels:= {"A","E","I","O","U"} Let alphabet be some CharacterRange, i.e.: ...
nilo de roock's user avatar

1
2
3 4 5
47