# 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,415 questions
Filter by
Sorted by
Tagged with
35 views

### Change the function-defined solution domain to fit NDSolve original Interpellation domain

Given a system of coupled non-linear equations, I used NDSolve to solve it in the domain of: $$-10^{50} \le r \le 10^{50}$$ ...
1 vote
95 views

### How to construct a custom-made matrix conditional on a set of rules?

The following code does what I intend to achieve; however, it is too cluttered for a simple matrix operation. I like to reduce the code to a one-line code as a ...
36 views

### Creating function with array input with desired coefficient and evaluate it

I had asked the same question before here Creating a list of functions with desired coefficients but did not get the desired answer, may be I was not clear in my question. I have defined this function ...
88 views

### Creating a list of functions with desired coefficients

I have defined this function to results some list of functions, however its not returning what I want ...
161 views

### First argument -h is not a valid variable

I am trying to simpligy my life by defining a function that gets the series expansion of $f(x+h)$ and $f(x-h)$ (at $x=0$) by the following code, ...
1 vote
73 views

### Map list of strings to appropriately nested functions

I have a list of strings consisting of sequences of "+" or "-"'s. For example, let's take the list ...
123 views

### Can I write a function that describes a hysteron?

Is there a way to write a "function", or as the answer below refers it better as a memory, that has the following output: k=0 if the last time x was outside the range (a,b), it was x<a. ...
31 views

### Defining a function for FunctionCompile[]

Lets say that I have the definition EQN4 that is determined from some calculation. If I run it in a cell, I get the following output: ...
69 views

### Define function to test arguments and set value to 0 (application 0 Log  = 0)

I have an expression that has the form f1[a, b, c] Log[ f2[a, b, c] ] Now if f1[a,b,c] and ...
36 views

### How to calculate this hierarchy in Mathematica?

A hierarchy can be defined as follows: $F_0(n) = 1$ when n = 1, 0 for all other values $F_{\alpha+1}(n) = \sum_{i=1}^nF_\alpha(i)$ $F_{\alpha}(n) = F_{\alpha[n]}(n)$ when $\alpha$ is a limit ordinal ...
79 views

### How can I Save function defintion without its DownValues?

I use functions that memorize their values like this one: ...
119 views

### Write Integral in Ostrogradsky's Method Form

Lets say we want to integrate $$\tag{1}F(x) = \frac{3 x^5-x^4+2 x^3-12 x^2-2 x+1}{\left(x^3-1\right)^2}$$ One approach might be to write it in partial fraction form and then integrate each fraction ...
71 views

### How to make a polynomial output be used as function for input?

I basically made a code interpolating a set of data that gives me the polynomial for the interpolation. Here's the sample interpolation I did. ...
41 views

### Defining function through a formula

I would like to define a cocycle on a group that maps into the unit circle. That is, I want to be able to define a function $f:G\times G\to\mathbb{T}$ such that $f(e_G,a)=f(a,e_G)=1$ for all $a\in G$ ...
1 vote
37 views

### Is it possible to use the Finite Fields package to define the elements of GF(4) in terms of the irreducible polynomial $P$?

I am new to the Finite Fields package and am finding the package tutorial confusing. I am wondering, if I am working over GF, is there a way of finding the elements of GF in terms of the ...
86 views

### How to code retarded time in Lienard-Wiechert potential equations?

I have been making strides on my project with the help of others here but have run into another snag: I am having difficulty in expressing the Lienard-Wiechert potentials with retarded time. For ...
110 views

### Interpolation of missing matrix values

Problem statement I want to replace missing matrix values, denoted by an integer 0, with the Mean of their surrounding values. ...
1 vote
85 views

### Nearest inside Minimize

How to use Nearest inside Minimize? The following returns errors but if # - {a, b} is ...
297 views

### Plotting multiple parametric 3D curves without using the Show command

How can I plot multiple parametric 3D curves on a single graph without the need to combine them using Show? Additionally, is there a way to clearly distinguish ...
122 views

### Evaluation control in function definition: Total interferes with Evaluate

Here is a simple example to illustrate my problem: ...
98 views

### How to express a retarded time function?

I have been messing around with Lienard-Wiechert potentials and am having some trouble properly expressing my retarded time function. As of this moment the function looks like so ...
123 views

### Creating a plot for a summation function

I have this potential function which I believe is representative of a grounded cube in a 3D plane. I'm not entirely sure if this is it, but here is the general solution of the function: v(x,y,z) = G(...
114 views

### How can I effectively input more than two list arguments into a function?

I am trying to input more than two list arguments into a function. For example, I have written the following code: ...
1 vote
59 views

### Appying Function To All Elements Of A Long List vs Over List's First Element Gives Different Results

So, I have two lists, and a function. If I apply my function to both lists in a "listable" manner, I have one result, but if I apply it to lists' elements one-by-one, in a "map" ...
1 vote
112 views

### Succinctly plotting a function defined in terms of many intermediate functions

I'm trying to plot a function that is in turn defined in terms of a lot of other functions, which each have a lot of variables. Here's a stylized example of the kind of thing I'm trying to do: ...
97 views

### Why won't this magnetic field plot?

I have been having some longstanding trouble in getting a 2D vector plot of a magnetic field to show up. For context, I am working with Lienard-Wiechert potentials and as such trying to plot the curl ...
320 views

### Show positions of duplicated matrix elements

1. Problem statement I want to replace duplicated elements within a matrix with a placeholder value. 2. Example data ...
340 views

### Swap lists and sequences

I'm looking for a function which does the following: ListSequenceSwap[{6, {1, 2, 3}, 4, 5, {2, 2}, {4}}] {{6}, 1, 2, 3, {4, 5}, 2, 2, 4} ...
81 views

### Is there a way to optimize it for larger n?

This is Domen's code from my previous thread here. I think it covers all the cases that I mentioned there and works well for small values of n. However, for large ...
482 views

### Delete list elements above a certain threshold

1. Problem statement Going from right to left, I want do delete all elements after they have occured n times. The solution I found seems to work reliably, but is ...
567 views

### How to calculate equivalent resistance for a network of same-value resistors?

Let's assume I have n identical resistors. I can connect them either in series or in parallel (let's disregard bridge connections for now). Now, I want to list all ...
36 views

### Commutator for Solving Coefficients in a Hamiltonian

I am relatively new to Mathematica but I understand the basics. I want to solve for coefficients by commutator constraints and I have problems implementing the commutator. The setup is the following: ...
1 vote
60 views

### How to remove terms with negligible constant from expression? [closed]

I'm working on a Notebook that requires the integration of multiple expressions (sometimes numeric, sometimes analytic). These expressions are normally of the form: ...
74 views

### Using Part[[i]] to defined a function

I would like to define a function like this f[x_, v_] := Part[m, 4, 1] where m = {{x^2}, {x^3}, {x^6}, {v x^4}}. but I can't ...
225 views

### Okhsl colour space

I am trying to recreate the Okhsl colour space from here. Below are the hue-saturation plots desired: I can create something similar (code adapted from here) with ...
72 views

### Function to Save/DumpSave without specifying full path

I am trying to create a function that saves a set of symbols into "test.mx" and is easy to use. ...
112 views

### Can't we find the range of values for this formula?

This algebraic expression is as follows: s=a/(a + b + c) + b/(b + c + d) + c/(a + c + d) + d/( a + b + d) where the parameters a, b, c, and d are all greater ...
60 views

### Understanding SetDelayed, ":=" [closed]

Consider the example below, p = {1, 2, 3}; x = {x1,x2,x3}; fun[x_] := {{1, 0, 0}, {0, 1, 1}} . (p + x); fun2[x_] = {{1, 0, 0}, {0, 1, 1}} . (p + x); I expected <...
51 views

### Comparing graphs in mathematica: shape vs. name

I'm trying to identify and remove duplicate graphs when contracting vertices. To illustrate this, I'll start with two simple graphs where I'm trying to create a function that can recognize them as ...
1 vote
43 views

### Graphics3D with projected/flat eye view? [closed]

Following image can be perceived as a cube (a regular hexagon with 3 internal line segments) : But in mathematica, it is not possible to make such shape with rotation. Examples of some close state of ...
191 views

### Graphic3D, white face, black edge in any view?

Graphics3D[ Cuboid /@ Complement[Tuples[{1, 2, 3}, 3], {{1, 2, 3}, {3, 1, 3}}], ViewPoint -> {45.42, -83.46, 31.83}, Boxed -> False] Above code generates ...
81 views

### What is the best way to redefine a function that has type ambiguity 0/0 at an isolated point?

Consider the following Green Function of wire turn producing magnetic field: ...
1k views

### Visualizing gravity warping the fabric of spacetime

What is a stable way of creating a set of points that are attracted to a single moving point? I have tried the following: ...
202 views

### Solving Schrödinger equation for Dirac comb potential (kicked rotor)

I need to solve the Schrödinger equation for a Dirac delta potential. I could not find the correct way to write the time-dependent potential and how to solve the time-dependent equation for it. The ...
77 views

### Is there any other good way to convert an algebraic expression into a specified form?

The original algebraic formula is: ((-a^2 + b^2) k)/Sqrt[(1 + k^2) (b^2 + a^2 k^2)] To convert to: ...
57 views

### Using compile with indexed variables

I have the following piece of code which I made faster by using compile. I make the following definitions ...
1 vote
57 views

...
53 views

### Difficulty in Proving Symbolic Equality in Mathematica [closed]

I'm currently working with the Mathematica software to verify the symbolic equality between two mathematical expressions. However, I've encountered a challenge where Mathematica's symbolic ...