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
0
votes
0answers
33 views

How to specify specific (custom) function arguments

Suppose that I want to have a function that is evaluated only when a user-specific, predefined flag is given out of a list of possible flags. For example ...
4
votes
1answer
148 views

How to find the function range of this?

How can I function range of the function x/(-1 + 2 x) over the domain (0 <= x<= 1)? I tried this but ...
0
votes
1answer
70 views

How to create nice looking circuit from its connection information?

I'm trying to write code to create a circuit from its connection information. For example, in the image below you see an incompleted circuit with two batteries, one resistor and one capacitor. The ...
0
votes
2answers
57 views

How to define specify parameter functions of a Sturm-Liouville operator & plot its effect on specific functions?

I have a Sturm-Liouville operator: $$\mathcal{Ly(x)}=-\frac{\mathrm{d}}{\mathrm{d}x}\left(p(x)\frac{\mathrm{d}}{\mathrm{d}x}y(x)\right)-q(x)y(x)$$ but I do not yet know the parameter functions $p(x)$ ...
-1
votes
0answers
30 views

Functions which assign an order pair to an order pair in in mathemtica [closed]

I need to write the following function in mathematica: Let $C=[0,1]\times[0,1]\subset\mathbb{R}^2$ and set $T:C\rightarrow C$ $$ T(x,y)=(\frac{x}{4},\frac{x}{3})\ \text{if}\ (x,y)\in[0,2)\times[0,2]...
3
votes
1answer
43 views

Distributive Concatenation

I'd like to have an (obviously noncommutative) operator ** that always takes linear combinations of some (undefined) F with any ...
5
votes
2answers
99 views

Using Piecewise to create a periodic waveform

I want to create a piecewise function that repeats after t=T. ...
1
vote
0answers
79 views

Numerical Integration Function issue

I am trying to plot a function which takes as arguments two other functions and performs an integration. I originally defined it analytically as so: ...
5
votes
2answers
151 views

Is Function broken is this example?

This program f[x_] := g[Function[a, x]]; g[fn_] := Module[{h}, h[a_] := fn[a]; h[0]]; f[999] returns Function[0, 999][0] but ...
1
vote
0answers
45 views

How to test for arguments for a pattern that is of a positive Integer OR Infinity so that both filter through to the definition on RHS?

How can I filter an argument of a function so that definition works on positive Integers (y >= 0) or Infinity? It will ...
0
votes
0answers
50 views

Manipulating matrices obtained by NDSolve

For example, Matrix U is obtained by ...
3
votes
1answer
117 views

Using function as argument to another function [closed]

I want to define a function which takes another function and evaluate it with a shared independent variable like so: T2[Tf_] = Integrate[Exp[t] Tf[t], t] But if I ...
2
votes
1answer
65 views

Change the definition of an interpolated function

I have a little question. I used the built in function 'NDEigensystem' to solve a differential equation; the results of this operation give me several functions; so I type in imput one of this like: <...
8
votes
0answers
54 views

Does ArgumentsOptions do anything we couldn't do without it?

ArgumentsOptions was new in version 12.2. I looked at the application on that page, and it makes code very difficult to understand. What if anything does ArgumentsOptions do for us that we couldn't do ...
1
vote
1answer
53 views

Trying to implement Newton's interpolation polynomial - not evaluating divided differences

I'm trying to find Newton's interpolation polynomial for a given function and a set of points. However, I'm having some issues with finding the divided differences (in this case I've notated them with ...
1
vote
1answer
59 views

Use symbol to replace function

I'm trying some transformations and they are getting complicated. It's common in physics to replace functions by symbols so you term get shorter. Lets say I have transformation ...
1
vote
2answers
109 views

How to group elements of a tuple into groups of 6 elements each?

I have a large tuple and I want to elements of the tuples into groups of 6 elements like this: ...
-1
votes
1answer
88 views

Create Predicate Function like PrimeQ :: fibonacciQ, pythgoreanQ

Yes, just define the function. i.e. Use the Fibonacci numbers. What are good practices to perform it? (Vague, let's get specific.) Create list of Fib.s 0, to 1,000,000. Make function _Integer ...
0
votes
2answers
63 views

How to declare that a function is arbitrary then specify them later? [duplicate]

I need to evaluate an expression, sum in this case, involving an arbitrary function. Below is a simplified version of what I wanted to do: ...
1
vote
0answers
79 views

Use self-defined operator symbol simplify formula

Mathematica is very useful and powerful in symbol compute, but some output isn’t concise if we didn’t simplify. Can i predefined some operator? eg. Lie bracket. Here is a minimum example. Suppose ...
1
vote
1answer
29 views

Interpolation of a set of points that include a non-numeric real constants

I have a set of data like: matrix=Table[{x,y,x+y*c1},{x,0,1,0.1},{y,0,1,0.1}] where 'c1' is a real constant. I'm trying to create an interpolation function called '...
0
votes
0answers
47 views

Detecting whether a function is initially defined with the form R[x,y] or R[x_,y_], etc

I have a very long code that may have errors in definition of functions and I want to trace these errors. Is there any attribute or function to detect whether a function is initially defined in the ...
1
vote
1answer
64 views

Changing part of the name of the function

Is it possible in Mathematica to replace the part of the name of the function to give the same arguments to another function? In fact, I have a lot of functions with the following name pattern: ...
1
vote
1answer
31 views

How can I extract a list of terms with functions in terms of a specific variable

I have an expression in the following form: a f[x] + b Exp[g[x, y]] + r[z] f[y] + f[y] Sin[h[x, y, z]^2] + r[z] Log[t[z, y]] I want to extract an expression ...
2
votes
2answers
197 views

Defining a function recursively

I want to construct polynomials (or just function) $f_n$ from $f_{n-1}$ using mathematica. For some kind of reason, I didn't manage to do this. So basically something like a recurrence table, but for ...
4
votes
3answers
157 views

Permutation avoidance function

It is common for me to see if a permutation of 1,2,...,n, avoids some fixed permutation pattern. For example, the permutation [1,4,2,3,5] contains the pattern 1,3,2, as the elements [1,4,3] appear in ...
2
votes
1answer
81 views

What's wrong with SetDelayed? The body of the function works alone, while setdelayed to it as $f[x\_]:=func$ gives the wrong answer

So I was writing a function to get the poincare map of a given dynamic system, for example, the duffing oscillator. I obtained the time series in advance, then take the poincare map based on this time ...
1
vote
0answers
51 views

How to make a function in terms of constants to inherit the attribute of being constant

I have defined two variables a and b: SetAttributes[a, Constant]; SetAtributes[b, Constant]; I have defined a function c as ...
1
vote
2answers
42 views

How to assume some variables to "not" be a function of other variables at the time of defining a function [closed]

I have a function with the following definition: F[x]=Exp[q*w*x]; I want to take total derivatives of F. How can I define that q and w are not dependent on x at the ...
1
vote
1answer
45 views

How to separately pass elements of a 3D list as part of the arguments of a function

Hi I have a function which its arguments have the form F[a,b,c,d,e] but the 2nd to 4th arguments are in a list of the form R={{{b,c,d},{e,f,g}},{{h,i,j},{k,l,m}}} how can I pass these elements as ...
2
votes
2answers
53 views

Partially Orderless Arguments in Functions

I am a Mathematica beginner and I'm trying to implement a function of type f[i1_,i2_,i3_,i4_] such that it is orderless in the first two arguments and in the last ...
0
votes
0answers
47 views

How to define a function without giving explicit formula

I want to have a function and I need to do some complex calculations to obtain an equation and then I want to assign the values to the function and then solve this equation to obtain the unknown ...
1
vote
0answers
150 views

How to Create an Efficient Word Square Algorithm?

I am working on the Wolfram Challenge Babbage Squares. I have looked at the following resources in order to come up with an idea for how to find all the possible word squares: Word Squares and Beyond ...
1
vote
0answers
49 views

Loops Not Working- Kernel Crashes and Values Incorrectly Updated

I haven't used Mathematica in a while so any help is very greatly appreciated. I am trying to run a program with nested for loops that runs two function evaluations in the inner most part of the loops....
0
votes
2answers
29 views

How to turn FindFit result into function within a Module context

I'm trying to construct a 'normal' function (with formal parameter) from the FindFit result within a Module context. While this works on a global level: In := ...
1
vote
1answer
54 views

How to create a simple transformation function on lists using short form of ReplaceAll?

I can easily do this with Map so the real goal of this exercise is to get a better grip on using transformation rules. Please help with this. The outputs should be ...
0
votes
0answers
42 views

Silly trouble expressing recursive formulas?

I am trying to code the following formulas: I did it in the following way: ...
0
votes
1answer
64 views

NIntegrate seems to not recognize multiplication of Piecewise function and f[t_]:= function, Why?

Considering inputs: vti={0, 1.5, 2.4, 5.0675, 7.735, 10}; Vscc=1.5; PSA=0.025; f=0.6; m=10; I defined a function "pwtemp2", using "FC1" and &...
2
votes
1answer
70 views

Is there a comprehensive list of most common or most important native Message-s (w/tags) for errors and Failed?

Yes I understand how to use Messages[symbol] but that doesn't help much. I have no idea which important ones I may have missed in my search or even how many exist. ...
0
votes
0answers
60 views

Recursively rewrite function

Let's imagine I already have a function like myfac[0] :=1 myfac[n_ /; n>=0] := n myfac[n-1] this home grown factorial. Now I want to equip it with tracing (and ...
0
votes
1answer
50 views

Could anyone help me to plot the following function? [closed]

Unfortunately Mathematica is not able to run the following program area[d_]:=Pi*d^2/4 Q=80/1000 v[d_]:=Q/area[d] [Nu]=10^-6 Reynolds[d_]:=v[d]*d/[Nu] [Epsilon]=0.04/1000 CW[[Lambda],d]:=1/Sqrt[[Lambda]...
0
votes
0answers
20 views

(Laplace Coefficents) Integral function definition

TLDR: need help defining two functions involving integrals in the form of "Laplace Coefficents". My intention is to define functions that involve Laplace Coefficents. In particular, if $$b_{...
0
votes
0answers
30 views

Suppressing tensor indices and function labels of a function

I am trying to do some GR calculations, and want to write a code which shows the expressions symbolically using compact indices, rather than write all the quantities in detail. More precisely, ...
2
votes
1answer
49 views

Why is Style ignored in my custom Echo error function?

To highlight the type of error that occurred the function echoError (via err) should display type of error in color: ...
4
votes
1answer
223 views

Using Mathematica to derive analytic form of single variable function

I am interested in finding an analytical form of the following function $f(n)$ defined as: $$f(n):=\sum_{\{\bar{K}\}}\prod_{l<j}^{n}e^{ik_lk_j},$$ where $\{\bar{K}\}$ is the full set of binary ...
2
votes
1answer
70 views

Defining function with arguments in a specific pattern similar to Graphics[]

I'm trying to define a function that is of this form: ...
7
votes
1answer
200 views

How to set deeper patterns in arguments within function definitions. For example if an argument must be a list of 1 or more strings

Suppose I want to define a function whose argument must be a List of only Strings and List must have at least one member. I know how to require that the Head must be a List but how does one qualify ...
0
votes
2answers
66 views

Integrate of simple equation but is not solving!

I have this simple integral but I don't know why Mathematica can't solve it?! FullSimplify[Integrate[x/(-x^2 + a x + b)^(1/2), {x, Sqrt[b], Sqrt[R^2 + b]},Assumptions -> {a > 0, b > 0}]]
1
vote
1answer
108 views

Condition (/;) not working correctly on a function with optional arguments and options

I have read this post: How to avoid collision between optional arguments and options, and use Mr.Wizard's method to solve this problem. But when I add conditions to optional arguments, it seems that ...
0
votes
1answer
42 views

Creating and defining a family of functions with indexed variables?

I am trying to do the following: Create a list as Table[Subscript[\[Beta], i] _, {i, 1, dim}] And then use this list to define a function: ...

1
2 3 4 5
43