Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
1answer
4 views

Function and patterns. FixedPointList doesn't work with function

There is a function: Clear[sort]; sort[{a___, b_, c_, d___}] := {a, c, b, d} /; b > c; It perfectly works with NestList function: ...
-4
votes
0answers
49 views

Overwrite a function after each iteration of a loop [on hold]

I would like to replace one function with another one or, put differently, "overwrite" one function after each iteration of a loop. I am posting here the code without the loop construct but the idea ...
0
votes
0answers
43 views

How to generate nested expression?

I've found some related questions, but nothing has really helped me to do what I want to do. Given a list of variables L and a parameter ...
1
vote
1answer
56 views

Define a function for a Log[b] which gives 0 when a==0 [on hold]

I need a function aLogb[a,b] which: 1) Returns a Log[b] when a is a number, except it returns 0 when ...
0
votes
0answers
29 views

Specifying return in function [closed]

In the following function, I just want to return the piecewise part that I defined, but since I have some instructions before, the function returns a list where the second argument is the piecewise ...
0
votes
0answers
24 views

Define a delayed function with tested patterns for fitting

This question is a variant of "Define function using variable list" Fitting functions require a model function defined in terms of explicit symbols that should only evaluate given numeric inputs, and ...
0
votes
1answer
29 views

How to get a function from a list element? [duplicate]

I have a set of arguments in a list like: uy = {21/2 + y/2, 13.6667 + 0.666667 y, 20 + y} Now, I want to assign a function (call it 'f(y)') to an element of that ...
1
vote
1answer
38 views

Filter out terms that include any combination of F[X] and G[-X]

I have the following problem which is closely linked to a previous question I asked some time ago (Replacement rule for terms that are separated by operators?). In this specific instance, suppose I ...
1
vote
2answers
23 views
1
vote
4answers
95 views

Unable to find root for user-defined function

I created the function getSolution[xVal,yVal] for a geometry problem I'm working on and wish to solve it for getSolution[2,x]==0. I can plot it clearly showing the roots: However, when I attempt to ...
2
votes
2answers
56 views

How to Create an Efficient Step Function from Data

I have list of rules from where a DateListStepPlot can be created to visualize the problem: ...
0
votes
1answer
45 views

Simply define an arbitrary, real function [closed]

I know of a way to define an arbitrary function (say, a[x]) and then apply an assumption to it (say a[x] is real). My code is pasted below. ...
1
vote
1answer
56 views

Is there a function or a way of getting a remainder or modulus with equations with “surds”?

So I'm working with "surds", or radicals. I have expressions like $$7 + 5\sqrt{2} + 6\sqrt{3} + 7\sqrt{6}\tag{1}$$ and I want to take the "coefficients", for lack of a better word, and take their ...
4
votes
2answers
254 views

Find constant that allows an integral to be finite

I have a function which is a not-so complicated polynomial, depending on a parameter $c$: $$f(r,c) = \frac{-2 r^4-4 r^3-6 r^2-6 r-3}{8 r^3}-\frac{c \left(-2 r^2-2 r-1\right)}{4 r^3}$$ What I am ...
0
votes
0answers
27 views

Creating a special product function

I am having trouble working with lists inside functions with Mathematica. Basically, I have a list of numbers and a special way to multiply them. I want to have a function that is able to create a ...
5
votes
1answer
110 views

A list has been obtained from an outside soft (from COMSOL - to Mathematica). Let us make a continuous function out of it

Using COMSOL I have solved an equation. The solution in the form of nested list with the term {x,y,z} is here. This ...
0
votes
0answers
30 views

Series expansion of explicit functions

For the following input, zv[u_, v_] := v + zv1[ u, v]/u; mvu[u, v] := D[zv[u, v], u]; Series[mvu[u, v], {u, 0, 1}] the output is ...
0
votes
1answer
31 views

Derivative of function with large number of arguments

I have a function which depends on more than 30 parameters and I want to symbolically compute the derivatives with respect to the individual parameters. From the documentation of the ...
8
votes
2answers
584 views

return {} when the function is given {}

I have a function taking an array as argument and giving an output. However, sometimes my argument is {} (the empty array), then how can I get an output {} when my argument is {}? Actually, I want the ...
0
votes
1answer
67 views

Generalization of code is slower than particular case

I wrote the following Mathematica module: ...
1
vote
1answer
70 views

n derivatives on a function of n variables

I want to derive an expression with respect to each variable of a function $f: \mathbb R^n \rightarrow \mathbb R$. More precisely: $\left(\prod_{i=1}^n\frac{\partial}{\partial_{x_i}}\right) g(f(x_1,...
9
votes
2answers
369 views

Using vtx[] instead of vtx

There're two ways to generate a random tree as 1 and 2 below. Both work fine here. So what's the reason to use vtx[] instead of ...
1
vote
3answers
42 views

Redefine function after change of coordinates (variables)

I wish to define functions of (possibly) several variables and then apply variable transformations in order to obtain a more comfortable expression. But I run into trouble because I need to redefine ...
2
votes
1answer
95 views

Implement gradient method in functional programming style

I implemented the gm for quadratic function in Mathematica, but it looks like more in an OOP style, as the pic shows. How to rewrite it in Mathematica style? I tried with following code: ...
0
votes
2answers
52 views

What are equations on mathematica and differences between these errors? [closed]

These are the three errors I was given. I so far wrote the code which was computing the polynomial interpolation but now I am asked to find those three norms: norm error mean norm error maximal ...
1
vote
0answers
61 views

Is function polymorphism possible in Mathematica [duplicate]

Is there a way to have polymorphic function definitions in Mathematica? I looked around online and didn't anything discussing it.
2
votes
0answers
42 views

Speeding up the process of NDSolve[] when a user-defined function is involved?

I am trying to tackle a (1+4 dimensional PDE) model at which the solution of the first PDE (with some interpolations and changing the domain) would be used in the second PDE. In fact, I must choose ...
0
votes
1answer
30 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 ...
45
votes
2answers
5k views

Is there any algorithm that runs faster in Mathematica than in C or Fortran?

I'm just curious. My friend just told me that Mathematica is mostly for symbolic calculation and not efficient for Numerical computations. He told me that's the reason most of the people don't use ...
3
votes
2answers
292 views

How can I better manage memory usage when defining functions?

Suppose I have defined a numerical function F[x] that for each entry x, it takes a long time to calculate. Suppose that now I ...
2
votes
1answer
45 views

How use the same Compile function with different equations

Say I have 2 equations that take the same parameters and variables that I want to evaluate numerically in compiled code ...
0
votes
0answers
47 views

Derivative operator w.r.t a vector index and change of variables

Description and code lines: Define a scalar product to represent $A_i·A_j$ , $A_i ·B_j$ and $B_i ·B_j$, such that $A_i · A_i$ = 0. This is implemented in the following way: ...
-1
votes
1answer
46 views

Trying to define a function using indexed variables

I have a list of indexed variables, for example xx={x[2],x[4]} and an expression which is a function of those indexed variables, say ...
0
votes
0answers
20 views

Error after defining a piecewise function

I have the following code: ...
6
votes
1answer
90 views

Is it possible to make listable Experimental`NumericalFunction?

I have been playing a bit with the undocumented function Experimental`CreateNumericalFunction and I wanted to know if somebody found a way to make generated ...
2
votes
2answers
50 views

Turning an equation into a function in a module

I have defined a function like this: f[q_] := Module[{g}, g[x_] := Evaluate[q]; ... ] I am calling the function like this: ...
0
votes
1answer
29 views

For different value of input module is giving same result

I have a simple module written to extract a certain shape for a certain value of ω, but I am getting the same result for different input values into the module. 1.mode[1] and mode[2] looks exactly ...
0
votes
1answer
30 views

Finding a coefficient that satisfies and intersecting condition

Suppose I have the following polynomial: ...
6
votes
1answer
216 views

The differences amongst f[x_], f[x__], and f[x___] [closed]

This is probably very elementary but I have not used the following and I cannot find anything online, and I was unable to find something here. Can someone explain to me the differences amongst <...
0
votes
1answer
47 views

What is wrong with my function call? [closed]

I'm writing a function and when I execute it, I get a message saying: ... function has no opening ]. If I remove the right square bracket, I get a message saying: ... needs more input Here ...
5
votes
3answers
217 views

Number of list elements less than a given integer

I'm trying to make a function whose input is a list, and that outputs a list for which the nth element is the number of elements in the input less than n. So far, I have ...
3
votes
2answers
54 views

Duplicate Tuples in two different ways

Writing: n = 3; Tuples[{"min", "MAX"}, n] I get: {{"min", "min", "min"}, {"min", "min", "MAX"}, {"min", "MAX", "min"}, {"min", "MAX", "MAX"}, {"MAX", "min", "...
0
votes
1answer
49 views

Getting unexpected results form If expressions [closed]

I'm mystified by this: g[a_, b_, c_] := Module[{d}, d = If[(b < 1), b, b + 1]; If[a < b, d = 0.]; d*c] g[a, 20, 40] ...
3
votes
1answer
134 views

Wrong result by FindRoot

Slight background: I am trying to find the coexistence reduced pressure ($p_r$) of a Van der Waals fluid at a reduced temperature of 0.85, this requires finding the solution to the following system of ...
1
vote
1answer
52 views

How can I find the minimum and maximum output of a function and specify the valid ranges and steping of each variable? [closed]

I am a software developer, and it has been far too long since the last time I've needed to do any math this complicated. I've forgotten a lot of the proper terminology, which has made finding answers ...
3
votes
2answers
84 views

Construct a function that maps strings to functions

The main question is the last 5 lines (including codes) of this article. A[x_, y_] := Evaluate[ToExpression["x^2+y^2"]] A[3,4] Then the output becomes ...
0
votes
2answers
46 views

Using MinValue with NDSolve

A simplified example looks like this. The basic idea is to maximize fHelper by adjusting \[Alpha] for each ...
2
votes
2answers
54 views

Hiding variable names in function definitions

I have a problem where Table and similar functions' substitution variable name can conflict with names in my function it self. Here's a minimal example ...
0
votes
0answers
26 views

Defining a function from an evaluated function stored in a variable

I have the evaluation of a function b, stored in appo. Now I want to define a new function f ...