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
1
vote
0answers
102 views

What are the differences between these functions when used for NMaximize?

In short, the question is how to construct the function you want to optimize? ...
1
vote
1answer
423 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 ...
1
vote
0answers
218 views

How to input a dynamically changing parameter in NDSolve? [closed]

I am trying to solve a system of DEs with additional conditions, and one condition depends on a parameter. Let us consider the following example: ...
1
vote
1answer
98 views

How can I avoid a scoping problem when differentiating?

I simplify my real problem as follows: I define a rule function as Clear[rule]; rule[i_] := tt -> i; the real rule function is not this simple. I define a ...
1
vote
2answers
65 views

Replacement rule for terms that are separated by operators?

My main problem is how one can create a "transcending between operators rule" in the same term according to the minimal example bellow. Suppose I need to perform a replacement of the form ...
1
vote
1answer
93 views

How to modify the output result of an evaluation

For ease of notation, I have defined a function, $f$, that defines the permutation of Bosonic particles such that it has the following properties (the form of $f$ is irrelavent for this question): $\...
0
votes
0answers
42 views

A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those ...
0
votes
1answer
43 views

Tracking back a variable corresponding to an output

I have a function: ...
0
votes
1answer
125 views

ReplaceThen and ReplaceAt - Cross between ReplacePart, Replace, and Extract -- Request for Comment

REWRITE: Multiple edits were hurting clarity Overview: I'm doing some work involving injecting code into held expressions, and found that I was repeating myself in a couple areas related to the ...
0
votes
0answers
75 views

Function to determine number of trees surviving forest fire [duplicate]

How can I write two functions, each of which have as their argument an array mat of 0s (no trees), 1s (trees), 2s (burning trees), that can determine the trees that survived a forest fire, which run ...
0
votes
1answer
228 views

How to turn a subroutine into a function?

I've written a subroutine that takes in 6 matrices and after some manipulation returns back 3 new ones. I will use this subroutine fairly often in this notebook so I think it would be easier to turn ...
0
votes
1answer
129 views

ND on a function using NIntegrate

I need to numerically differentiate a function that takes a list as an argument and that uses NIntegrate in its definition. A simple example is ...
0
votes
1answer
75 views

How to have NonlinearModelFit not evaluate a function too early?

This is a follow up of my previous question How can I define the following function for arbitray values of the arguments? that received no attention so here I will try to be more concise with the ...
0
votes
1answer
108 views

How can I define the following function for arbitray values of the arguments?

Consider the following function a[m_, l_] = 1/Log[m/l]; with this function I define ...
0
votes
1answer
113 views

Given a sequence of expressions, how can I convert them all into functions?

I have a sequence of expressions 1, x, x^2, ..., x^5 I want to define a sequence of functions out of it, what should I do? Namely I want to define a vector of ...
0
votes
1answer
28 views

Limiting the Domain of a Function

Currently, I am trying to plot (using Mathematica) the following function: $$f(t) = \begin{cases} 0, & 0<t<1 \\ 1, & 1<t<2 \end{cases} $$ And, to try to plot this, I did some ...
0
votes
1answer
856 views

Convert string to function with an argument

I am trying to build an expression by first writing it out as a string and then using ToExpression to convert it to an expression. However, I cannot figure out how to make expression recognize x as an ...
0
votes
0answers
100 views

Applying a function to the second element of a list [duplicate]

I'm trying to apply a simple function to the second element of a list: {#1, #2/5} &@{1, 2} But this returns an error message. ...
-1
votes
4answers
312 views

Converting an expression to function [duplicate]

I have the following problem. I current can automatically create the variable positionPayload, for instance: ...

1
5 6 7 8
9