# 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,438 questions
Filter by
Sorted by
Tagged with
1 vote
61 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" ...
• 345
1 vote
115 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: ...
• 165
101 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 ...
• 55
324 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 ...
• 61.9k
346 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} ...
• 61.9k
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 ...
• 2,461
493 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 ...
• 61.9k
862 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 ...
• 2,461
40 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
1 vote
70 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: ...
78 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 ...
253 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 ...
• 8,668
83 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. ...
• 976
118 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 ...
• 3,635
69 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 <...
55 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 ...
• 2,318
1 vote
46 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 ...
• 3,965
196 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 ...
• 3,965
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: ...
• 8,668
313 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 ...
• 2,268
79 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: ...
• 3,635
60 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 ...
• 289
1 vote
57 views

...
• 3,575
54 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 ...
• 99
68 views

### A problem of Mathematica function with different parameters in the same model

I'm simulating a graph of a function, and have made a preliminary attempt with mathematica, my test code is as follows:: ...
• 103
103 views

### Function[0], Function[,0], and Function[{},0]: Is there any inherent distinction in the "academic" sense?

Note that Function[,0] is by default interpreted as Function[Null,0]. The following three calls all give ...
• 485
70 views

### Interpolation error to generate a two variable function

I am facing some issues with performing an interpolation. From the image, you can find the values in three columns, the 1st column is x, the second column is ...
47 views

### Handling "vars appears twice in a nested scoping construct" Warning in Custom Function

I've been developing a custom function that serves to simplify the body of other Function's in Mathematica. Here is my function definition: ...
• 19.4k
425 views

### Apply a function row- and columnwise

I want to a apply a function to the 2nd row and 2nd column of an association: ...
• 61.9k
87 views

### How to compute the infinite continued fraction?

I am reading the article "Eigenvalues and eigenfunctions of spin-weighted spheroidal harmonics in four and higher dimensions", which is on https://arxiv.org/abs/gr-qc/0511111. I want to ...
• 31
393 views

### How can I change elements in a matrix to a combination of other elements?

Suppose I have a list like { {x1,y1,z1}, {x2,y2,z2}, {x3,y3,z3}, ... } and I want to change it to ...
1 vote
88 views

### Plotting the electric field of the Lienard-Wiechert potentials

I am having a very rough time trying to properly define and then vectorplot the expression for the electric field of the Lienard-Wiechert potentials I have been trying to code. Up to this point, the ...
• 55
77 views

### Help with Syntax to Make Iterative Arithmetic-Geometric Mean Like Functions

In the arithmetic-geometric mean, we combine the arithmetic mean and the geometric mean like so, $$a_0=a,~b_0=b$$ $$a_1=\frac{a_0+b_0}{2},~b_1=\sqrt{a_0 b_0}$$ $$\vdots$$ a_{n+1}=\frac{a_n+b_n}{2},~...
• 375
133 views

### How can I modify this code to turn the button red when it's pressed?

How can I modify this code to turn the button red when it's pressed? ...
• 703
143 views

### Trick to apply function on a variable and store output in the same variable

Is there any Mathematica shorthand notation for this var=AnyFunction[var] Where I apply a function on the variable var and want ...
• 1,122
58 views

### How to automate graph display for large datasets?

Large outputs are automatically truncated. For example, How can I apply this to displaying graphs? ...
• 2,318
170 views

### Is it possible to ask Mathematica to obtain the function describing the upper and lower boundaries of a combinations of functions?

Assume that I have three one-variable non-periodic functions $f(x),g(x),h(x)$ for $x>0$. The question is: is it possible to ask Mathematica to obtain the function describing the upper and lower ...
• 719
1 vote
66 views

### Selecting interesting graph positions with a button press/click or something similar

Assume that I have a graphList as shown below (a simple working example). ...
• 2,461
37 views

### Manipulate with With and without - scope of variables

I am struggling with some basic concepts: Why this works: ...
• 3,874
176 views

### How to make delayed function evaluate to zero

I have a function y[r_] := D[otherfunction[r],t] + D[r,t]; where $r$ can pick up a time dependence depending on the problem. When it does not I am having issues ...
• 23
1 vote
65 views

### Can not get OptionValue with SetDelayed variable

ClearAll[foo1]; foo1[OptionsPattern[]] := Hold[OptionValue[""]][[1, 1]] foo1[] gives function name foo1 But ...
• 17.1k
79 views

### Large Structured Programming with Compile

Is it possible or wise to build a large program structure with only Compile? With FunctionCompile it is possible to create ...
38 views

### Issue with piecewise functions and lists of rules

I have a list of data that I am connecting with a simple piecewise function. I then want to evaluate the piecewise function at a different list of points. I can do it the long way, but I am wondering ...
• 31
89 views

### Looking for solutions to filter out one-sided angle pairs in line intersections

I posted something here a while ago, but I think it's a bit messy and difficult to understand. So, I'll create a new post to explain the concept and what I want in a different way, hopefully making it ...
• 2,318
1 vote
63 views

### Find minimum of integral with two variable terms

I wanted to see an approach to solving this problem with Mathematica: https://math.stackexchange.com/questions/4723531/how-would-you-attack-this-problem Determine real numbers a and b so that the ...
• 3,136
294 views

### How can I create a function that takes Sets as input?

The function takes a list of integers as an input and spits out a vector of length l that contains 1 at the positions that are specified in the list, else zeros. ...
• 427
42 views

### Use elements of an array in a function [closed]

I have an array that I am importing from a mat file lets call it $A$. I want to define a function like F[n_,m_] = m A[[1,n]] But when I do this, I get an error <...
40 views

### Dynamic of the content of a certain cell (using NotebookRead)

Initial state : ...
• 3,965