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
1 answer
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" ...
Anton's user avatar
  • 345
1 vote
1 answer
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: ...
knzhou's user avatar
  • 165
0 votes
0 answers
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 ...
JDRobin's user avatar
  • 55
5 votes
4 answers
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 ...
eldo's user avatar
  • 61.9k
5 votes
6 answers
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} ...
eldo's user avatar
  • 61.9k
0 votes
0 answers
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 ...
emnha's user avatar
  • 2,461
4 votes
8 answers
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 ...
eldo's user avatar
  • 61.9k
4 votes
2 answers
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 ...
emnha's user avatar
  • 2,461
0 votes
0 answers
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: ...
iron's user avatar
  • 1
1 vote
1 answer
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: ...
Pedro Hablespanyos's user avatar
0 votes
1 answer
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 ...
Dinesh Shankar's user avatar
4 votes
1 answer
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 ...
martin's user avatar
  • 8,668
3 votes
1 answer
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. ...
Albercoc's user avatar
  • 976
0 votes
2 answers
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 ...
csn899's user avatar
  • 3,635
0 votes
2 answers
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 <...
Adriana LE's user avatar
0 votes
0 answers
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 ...
hana's user avatar
  • 2,318
1 vote
0 answers
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 ...
imida k's user avatar
  • 3,965
4 votes
2 answers
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 ...
imida k's user avatar
  • 3,965
2 votes
3 answers
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: ...
Igor Kotelnikov's user avatar
15 votes
1 answer
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: ...
martin's user avatar
  • 8,668
2 votes
1 answer
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 ...
user444's user avatar
  • 2,268
0 votes
1 answer
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: ...
csn899's user avatar
  • 3,635
0 votes
0 answers
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 ...
QFTheorist's user avatar
1 vote
1 answer
57 views

Why the first is evaluated while the second is not (Sum behaves differently from Integrate)?

...
Anixx's user avatar
  • 3,575
-1 votes
1 answer
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 ...
algebroo's user avatar
0 votes
1 answer
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:: ...
little star's user avatar
4 votes
1 answer
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 ...
user688486's user avatar
0 votes
1 answer
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 ...
Pooja Bhattacharjee's user avatar
0 votes
0 answers
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: ...
E. Chan-López's user avatar
8 votes
5 answers
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: ...
eldo's user avatar
  • 61.9k
0 votes
0 answers
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 ...
amon xu's user avatar
  • 31
6 votes
5 answers
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 ...
Delaram Nematollahi's user avatar
1 vote
1 answer
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 ...
JDRobin's user avatar
  • 55
2 votes
2 answers
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},~...
David Elm's user avatar
  • 375
3 votes
1 answer
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? ...
internet's user avatar
  • 703
2 votes
1 answer
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 ...
Epsilon's user avatar
  • 1,122
0 votes
1 answer
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? ...
hana's user avatar
  • 2,318
3 votes
1 answer
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 ...
math2021's user avatar
  • 719
1 vote
2 answers
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). ...
emnha's user avatar
  • 2,461
0 votes
0 answers
37 views

Manipulate with With and without - scope of variables

I am struggling with some basic concepts: Why this works: ...
atapaka's user avatar
  • 3,874
2 votes
2 answers
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 ...
ninPHX's user avatar
  • 23
1 vote
1 answer
65 views

Can not get OptionValue with SetDelayed variable

ClearAll[foo1]; foo1[OptionsPattern[]] := Hold[OptionValue[""]][[1, 1]] foo1[] gives function name foo1 But ...
matheorem's user avatar
  • 17.1k
2 votes
0 answers
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 ...
Michael Haring's user avatar
0 votes
0 answers
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 ...
Claudia's user avatar
  • 31
2 votes
2 answers
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 ...
hana's user avatar
  • 2,318
1 vote
1 answer
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 ...
Moo's user avatar
  • 3,136
2 votes
3 answers
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. ...
100xln2's user avatar
  • 427
0 votes
2 answers
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 <...
Amin Gholizad's user avatar
0 votes
0 answers
40 views

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

Initial state : ...
imida k's user avatar
  • 3,965
0 votes
0 answers
43 views

Palette that gets single keystroke as input

I could find many examples of user-made Palette with many buttons in it. And drawing-tools Palette is not user-made, but it accepts a single keystroke as input. (In ...
imida k's user avatar
  • 3,965

1
2
3 4 5
49