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
2 votes
2 answers
70 views

Piecewise based on the length of the list

I want to create a piecewise function that depends on the length of the list. Let's say I have a list, and a corresponding piecewise function: ...
user avatar
  • 703
0 votes
1 answer
51 views

Create list with integer partitions satisfying some conditions

I want to create a function PartSet[N_,M_] of two positive integer variables which outputs a list of all pairs of integer partitions for all integers up to $M$ ...
user avatar
  • 1,287
4 votes
1 answer
121 views

How to add ticks for mesh?

I'm trying to reprocedue this plot with Mathematica and got some problems. ...
user avatar
  • 1,750
11 votes
1 answer
241 views

Association vs Pair - Creation performance, Selection performance

Suppose that we ...
user avatar
  • 2,451
4 votes
1 answer
68 views

Replacement, PatternTest, Module related Question

Let's see how MMA handles following type of expression : Replace[L, {pattTest1->rhs1, pattTest2->rhs2, pattTest3->rhs3}, {1}] Specific example : ...
user avatar
  • 2,451
3 votes
1 answer
78 views

Classifying elements, by the value of a fixed function, using Replace

Let L be a list of several lists. And the length of each list is less than 1000. You can create L by ...
user avatar
  • 2,451
1 vote
1 answer
89 views

While inside a function body does not work as expected [closed]

I'm trying to write a function that return a randomly created rational polynomial function that has a discontinuities points. I already have a function that generates random rational polynomial (...
user avatar
  • 69
0 votes
1 answer
65 views

get positions satisfying multiple criteria

Given a list L. It is mathematically proven that there is no element in L matching 2 or more patterns in ...
user avatar
  • 2,451
0 votes
0 answers
66 views

Packed/Unpacked array - what object/like 0 or 1?/how to check/ [duplicate]

In Mathematica, there is a concept called packed array. ...
user avatar
  • 2,451
3 votes
2 answers
90 views

How to remove duplicates from a pair with some conditions?

Here is a simpler example of my real problem. Assume that I have a groups which includes sublists as follows: ...
user avatar
  • 2,147
1 vote
0 answers
36 views

Using part of a user defined function

I've defined a simple function $f:\Bbb R^3\to \Bbb R^2$. Is it possible to use only part of it? ...
user avatar
  • 543
9 votes
4 answers
527 views

How can I use variables instead of slots in DeleteCases?

Here is a toy example to illustrate my problem. I have a list of 3-tuples and I want to delete elements from this list that satisfy a condition shown below. ...
user avatar
  • 1,750
4 votes
3 answers
480 views

How to simplify function with Abs?

I'm trying to remove Abs below. ...
user avatar
  • 1,750
1 vote
1 answer
93 views

Tallying over columns of matrix

Suppose I have a $300 \times 100$ matrix, with entries 0,1 or 2. The first row represents the initial state of a 100-parameter discrete dynamical system (each parameter taking only those three values) ...
user avatar
  • 21
3 votes
1 answer
53 views

RunProcess : Save directly to Mathematica Variable

I can convert mysource.jpg to myresult.jpg using an external program myprog.exe, and set a ...
user avatar
  • 2,451
0 votes
0 answers
53 views

How to DeleteDuplicates from a list of Rules having set to different values whereby we wish to drop the last occurrence?

About This Function This will eventually set default values for Options based on the end users preferences so that no OptionsPattern need ever be set. The symbol<...
user avatar
  • 1,787
5 votes
4 answers
290 views

How can I efficiently define functions with different names but doing the same stuff?

Recently I have met with with this interesting question:How can I efficiently define functions with different names but doing the same stuff? Somebody may want to ask me why I want to do things like ...
user avatar
  • 289
3 votes
2 answers
190 views

Why is the matrix "mat" not modified here?

Why is the matrix mat not modified here? I expected it changes with list1 and list2 so that <...
user avatar
  • 1,750
2 votes
2 answers
143 views

Double quotes as a 'function' (verbatim ToString?)

Can we construct a function F such that F makes any typed text into a string. Just like double quotes. ...
user avatar
  • 2,451
2 votes
1 answer
158 views

Define a new rule for multiplication

I am trying to implement a new rule for noncommutative multiplication: $$ x * q^n * y \to q^n * x * y, $$ where $\ast$ stands for noncommutative multiplication and x and y are random products in ...
user avatar
  • 45
4 votes
1 answer
103 views

Why is this region in RegionPlot3D wrong?

I believe this is simple, but I can't wrap my head around forming region for RegionPlot3D. I have been reading and trying to understand how to write the region but ...
user avatar
  • 1,750
5 votes
2 answers
1k views

Why does this triple integral take so long?

How can I compute this triple integral? I tried this but it has been running for a long time and not return result yet. ...
user avatar
  • 1,750
3 votes
3 answers
123 views

How to insert some number of parentheses into an expression to get smallest integer result?

Assume that I have an expression like this (without evaluating) expr = 1/2/3/4/5/6/7/8/9/10 You can insert some number of parentheses into the expression above to ...
user avatar
  • 2,147
4 votes
5 answers
245 views

How to define functions using a list of polynomials?

I feel stupid for not being able to do this and I think it is just a syntax error. Let's say i have the following list: L={x,xy,x^2+y,xyz,x^2} How do I define 5 ...
user avatar
  • 553
2 votes
2 answers
68 views

How to make function return True if two functions and domains are same?

(Please see the edit part for the real problem) I have two expressions which are same but written in different ways. ...
user avatar
  • 1,750
0 votes
0 answers
12 views

How to use tools like Template Input and Literal Input when filling out the ResourceFunction submission notebook?

I found no examples or instructions on how to use these. Yes Check button at top does a fine job of showing any missing content, invalid cells, and of course all ...
user avatar
  • 1,787
3 votes
3 answers
99 views

How to test a recursive formula using Mathematica?

Through taking the derivative of $\binom{n}{k}$ w.r.t $n$ repeatedly, I found the recursive formula: $$\frac{\partial^a}{\partial n^a}\binom{n}{k}=\sum_{j=0}^{a-1}\binom{a-1}{i}\frac{\partial^j}{\...
user avatar
8 votes
3 answers
486 views

Replace 'n'-th occurence with number 'n'

How can I replace n-th occurence with number n for string/for list? For string : ...
user avatar
  • 2,451
1 vote
3 answers
98 views

How to return unevaluated variable?

I'm not sure if this problem has been asked before as I don't know the keyword to search for it. I have a function where return result contains variable b (just ...
user avatar
  • 1,750
0 votes
1 answer
49 views

Defining a general function f with slot-holder arguments #1, #2

I am trying to get a general function $f$ accept slot-holder arguments #1, #2, where the actual arguments are lists {a1, a2,...} and {b1, b2,....}. I thought that this would involve some combination ...
user avatar
7 votes
5 answers
512 views

How to split Abs functions into two?

I have a list of functions like this: ...
user avatar
  • 1,750
0 votes
0 answers
63 views

Why does my function for LocalSubmit successfully create a TaskObject with no errors but ignores my simple Print task?

tldr: for lazy readers (don't blame you im sometimes that way too) or those who found my details below a little bit vague my question is: why is my Print not ...
user avatar
  • 1,787
1 vote
2 answers
60 views

Unable to properly define an operator indexed by a natural number

I'm trying to define a differential operator indexed by a natural number $n$, with the definition varying depending on the parity of $n$. Here's what I wrote: ...
user avatar
1 vote
2 answers
89 views

Having trouble using # and & to define a function

Let's say I want to define a function indexed by an natural number $g$, which is given by $$f_g(x)=g+x$$ I could (I guess naively) write the following code to define it up until $g=19$ ...
user avatar
3 votes
1 answer
76 views

Imposing constraints on any undefined symbol appearing in a matrix automatically

I want to know how can I can I tell Mathematica that all symbols that appear in an object, e.g. a matrix, obey certain constrains, without having to write these conditions by hand. More specifically, ...
user avatar
  • 517
2 votes
2 answers
194 views

Integration by parts for deriving gamma function

Well, there is an integral that has quite a lot to do with $n!$, and that is the following : $f(n)$ = Integrate[x^(n - 1)/E^x, {x, 0, Infinity}] =$\int_0^{\infty } \...
user avatar
  • 649
1 vote
1 answer
26 views

Number of input parameters (nargin equivalent) for AceGen

Is there an equivalent to the MATLAB parameter nargin that can be used in AceGen? For example, consider a function that takes in two vectors and an optional scalar. ...
user avatar
0 votes
0 answers
29 views

How to track mapping of line segments inside and outside some regions?

I have 3 curves where each point of the first curve maps to the second and third curves as follows: ...
user avatar
  • 1,750
12 votes
1 answer
354 views

How can I blur/remove the borderline around text?

How can I make the borderline around the LaTeX expressions below more blurry, or can I remove it with some setting? ...
user avatar
  • 1,750
3 votes
1 answer
121 views

Why does RegionWithin return False in this case?

Is there any mistake here? I expect it returns True but the result is False. I have been checking but couldn't find the mistake. ...
user avatar
  • 1,750
0 votes
1 answer
43 views

How to define a mixed pattern consisting of string and regular patterns for function definition (using SetDelayed)?

I'm kinda stuck here, and I could really use some help: I want to define a function, let's call it quarterValue, that accepts a ...
user avatar
  • 122
4 votes
1 answer
87 views

Why does this RuleDelayed behave weird?

This is something that I couldn't explain. functions = {ConditionalExpression[Abs[1 - 2 x], x >= 1 || x <= 0], ConditionalExpression[1 + x, x >= 0]}; ...
user avatar
  • 1,750
2 votes
1 answer
94 views

Piecewise smooth rectangular pulse

I am wondering how to create a rectangular pulse with a non linear falling edge on one side, and straight line sloping from the falling edge (the red line). So far I have managed to get the plot ...
user avatar
  • 31
5 votes
3 answers
391 views

Formula for calculating equivalent parallel resistance

I'm trying to create a user-defined function that computes the equivalent resistance of $n$ resistors in parallel. As we know, such formula is: $R_\text{eq.p} = \dfrac{1}{\displaystyle\sum_{k=1}^{n} \...
user avatar
  • 433
6 votes
2 answers
197 views

How to select all curves on or outside a region?

How would you select all curves that are on boundary of the region or outside the boundary of the region(including lines with points on the boundary)? ...
user avatar
  • 1,750
4 votes
1 answer
120 views

How to find boundary of the intersection of two mesh regions in CW or CCW?

I have two lists of points as follow and they're not fixed. ...
user avatar
  • 1,750
3 votes
2 answers
291 views

How to define a function in Mathematica without overriding the previous definition?

I'm a beginner at Mathematica and trying to define a function for the Collatz conjecture, and here is my code: ...
user avatar
4 votes
3 answers
250 views

How to place labels of many curves in good positions?

Would it be possible to put labels like this for all curves from 1 to 19? It would also be nice if there are some way to put/adjust the position of labels manually for better positions. ...
user avatar
  • 1,750
4 votes
2 answers
115 views

How can I fill the region from the minimum value of all curves to the x axis

How can I fill the region from the minimum value of all curves to the x axis like this? ...
user avatar
  • 1,750
6 votes
6 answers
312 views

Grouping consecutive elements at specified positions

Let L1={1,2,4,6,8,9,10,14,15,17,21,22,72,76,80,96,106,116,117} Question1) Group from 10-th to 14-th elements in L1. So that the ...
user avatar
  • 2,451

1
2 3 4 5
45