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.

learn more… | top users | synonyms

0
votes
1answer
33 views

Set a minimum threshold value for a function

I have defined the following function in Mathematica al[z_] := (a/((1 + a*(b/(2 Pi))*Log[z/Mz]))) (a and ...
-1
votes
0answers
61 views

About changing the values of global parameters within a function [on hold]

For the code below: a = 1; b = 2; f[c_, d_] =: Module[{e, f, g, h, ...}, ...]; I have references to a and ...
1
vote
0answers
43 views

Line-crossing Algorithm Implementation (pt. 2)

This is a continuation of the problem I posted earlier with the line-crossing algorithm that I tried to implement in Mathematica. I took Kuba's suggestion, removing the underscore on everything ...
0
votes
0answers
88 views

How to compute this integration? [closed]

I would like to compute the following integral: Where: a and k are reals, with the assumptions: 0 < a, and 0 > k > -4. y and p are reals too. I tried to write it as ...
1
vote
1answer
66 views

Defined a function but it doesn't seem to work

I'm trying to implement the line-crossing algorithm on Mathematica and I seem to be having trouble getting it to work. More specifically, I would like to know what is causing the function to not ...
2
votes
2answers
81 views

Finding zero of nonlinear simultaneous equations [closed]

I'm trying to find the zero of nonlinear simultaneous equations defined in myfun1 and myfun2: ...
0
votes
0answers
34 views

Transform an expression into a function [on hold]

I have a matrix of the form Mat = {{2a, 7a},{5a, 3a},{a, 2a}} (the actual matrix is a hugely complicated one of size 64x64, but the idea is exactly the same). I ...
19
votes
5answers
367 views

Distributing function arguments with function compositions. How to compute $(f + g^2)(x) = f(x) + g(x)^2$?

Suppose I have two functions f and g. To compute $f + g$ evaluated at a point $x$, I know that one can use ...
0
votes
0answers
56 views

Defining a function that depends on the length of a number and the $n$-th digit

I have defined the functions F[i][x] for i={1, 2, 3}.. I want to write a number that has only the characters 1, 2, 3, and I want ...
-3
votes
1answer
130 views

Function just gets mapped without any evaluation [closed]

Variable definitions are as follows: eBEG=0.; epBEG=0.; aNEXT = 0; eNEXT=0.; actStrain=0.; epTRIAL=0.; sigTRIAL=Range[0]; sigEND=Range[0]; Constant definitions ...
1
vote
1answer
221 views

Orthogonalizing polynomials with inner product depending on parameters

I need to orthogonalize the polynomials $h_n(x)=x^{2n}(1+x^2)^{-4S}$ with $x\in\textbf{R}$, $2S\in\textbf{N}$ and $n\in\{1,3,5,\ldots, 4S-1\}$ over the inner product $\langle h_n,h_m\rangle=32\pi S\...
3
votes
0answers
89 views

How to get this terrible summation/product to run in Mathematica?

I've come across this formula and have no idea where to even start. (My assumption here is that $m,n$ are known and input into the expression to arrive at an answer.) $$f(m,n) = \sum_{\substack{0 \...
1
vote
1answer
80 views

integrating with multiple indicator functions depending on each other

I need to compute the following integral with three indicator functions, $I(x)$, $I_1(x_1)$ and $I_2(x_2)$, $$ \int_0^1\int_0^1I(x)\left( \ I_1(x_1)\,x_{1} + I_2(x_2)\,x_{2}-1 \right) dx_1 dx_2 $$ ...
8
votes
1answer
93 views

How does a construct like `i : func[arg_] := i = an expression using arg` work?

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
3
votes
1answer
67 views

Dealing with a large number of optimizations performed with parameters read in from a CSV file

I have a large CSV file (1.5M rows), with each row containing a set of parameters that I need for an optimization routine in Mathematica. I'm hoping to import the data, run the computation, and then ...
0
votes
0answers
30 views

Produce a function of parameters from a solution to parametric equation [closed]

I am trying to produce a very simple result, namely given some function $f(x,a)=0$ find a solution $x(a)$ and let it be a function that I later plot depending on $a$. However Mathematica does not ...
2
votes
1answer
55 views

Problem using Nintegrate and NDsolve

I am going to use Nintegrate to integrate the result of NDsolve and also a Table. How I can ...
14
votes
6answers
2k views

How can I plot this spirally surface?

I would like to plot a surface that looks something like this sand spiral. But I really have no idea how. Ideally I would like to be able to express this as a function in cartesian coordinates. I'm ...
2
votes
0answers
68 views

Confusing alternative definition of a function [duplicate]

I saw a function defined something like the following: f[n_Integer][r, θ] = Sin[n r π/L] Cos[n r L π θ/4] My question is, why did my professor define the ...
0
votes
0answers
50 views

Doing vector calculus with element-wise defined formulas and arbitrary-sized vectors [duplicate]

Currently I am trying to make Mathematica handle vector expressions defined element-wise. For example, But I can find no way to do this. Every way I tried requires a fixed-sized vector and returns ...
4
votes
2answers
107 views

How to define action of derivative (D) on a user-defined operator f

I have a symbolic function (which is in fact an operator) f[expr, x] where the second argument is a local variable for f (kind ...
10
votes
1answer
372 views

Is there a function to generate a minimal clique cover?

This is a graph problem known as the "Clique Edge Cover" or "Intersection Number" problem, and the goal is to find, from a given graph like $E=\{\{a,b\},\{a,c\},\{b,c\},\{b,d\},\{c,d\}\}$ and $V=\...
6
votes
2answers
5k views

Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual ...
5
votes
2answers
93 views

How do I construct a Pattern with Alternatives and PatternSequence without getting Pattern::patvar messages?

Bug introduced 8.0 or earlier and persisting through 10.4.1 [CASE:3631078] In Mathematica 8 and 9, defining this rule: ...
0
votes
0answers
31 views

How to use OptionValue inside a pure function [duplicate]

I want to define a function with OptionsPattern as argument which returns a pure function using OptionValue: ...
1
vote
0answers
70 views

Build basic Adobe Kuler-type construction: improving performance / speed

Adobe Kuler is a useful web tool to create colour palettes, but it is limited to 5 colours. I am trying to make a basic Kuler-type construction, but it is very slow, and crashes on my computer for > ...
0
votes
0answers
34 views

How to make FindMiniumum work with delayed function and NIntegrate [duplicate]

I can plot my function penalty[v] just fine, but FindMinimum doesn't work, it just complains non-numerical values from ...
2
votes
2answers
162 views

How to get `Series` to recognize user-defined function has pole

Edit for clarity: How does Mathematica's function Series know that Gamma[x] has a pole at ...
1
vote
0answers
36 views

Symmetrize a function

I am working with a function in several variables. I need a function which symmetrizes it. Namely in case of two variables it is f[x, y]+f[y, x]. For three variables it is $$f[x , y , z] + f[x, z, y] ...
0
votes
1answer
33 views

How to turn a function's input argument into a new function

I want to write a function via a module that takes a user's input and creates a function from the input within the module. That is something like Input: ...
1
vote
2answers
133 views

How do I get Series[] as a functional, rather than as an expression (i.e. to avoid the dummy variable)?

How can I write an equivalent to Series that doesn't require a dummy variable? Note that the series should be constructed before the evaluation point is supplied, ...
79
votes
4answers
5k views

Functions with Options

Suppose you want to create a function which has optional arguments. Maeder's book Programming in Mathematica covers the topic extensively up to version 3, but some things have changed/evolved since ...
15
votes
2answers
263 views

How to check the validity of an option value

I have a user-defined function, func, which takes the following form: func[arg1, arg2, options] Here is the actual code ...
4
votes
1answer
84 views

How to save the caching produced in processing

As my this previous post.I get a custom function which can help me got some function contain a certain option.And I have put it in my "init.m" file. ...
3
votes
1answer
74 views

Implementing the Cimmino method [closed]

What am I doing wrong? I am trying to implement the Cimmino method, an iterative method for the solution of linear algebraic systems. The final output should be a vector. Here is a description of the ...
6
votes
4answers
107 views

Multiple output cells, suppressed by semicolon

I'd like to write a function that outputs multiple cells, as in Multiple output cells, but not when the function is called with a semicolon at the end. Any idea how?
-2
votes
1answer
43 views

Calculate column number from alphabetic column reference in Excel [duplicate]

Here's a fun brain teaser. Can you give me a mathematical equation to calculate the column number of a Microsoft Excel column, given the alphabetic column reference? Let X, Y, & Z represent the ...
3
votes
2answers
60 views

Catch parameter order and error using functional form

Question: Why does this fail? In:= (Catch[#] &)[Throw[17]] ...
2
votes
0answers
57 views

Lyapunov Exponent as a function of parameter

I am working at Rossler system and I would like to ask you for some help. This system is described by equations: \begin{array}{ll} \dot{x} = -y - z \\ \dot{y} = x + 0.2y \\ \label{eq:UkladRosSP} \dot{...
4
votes
1answer
109 views

How to use the built-in function GraphElementData

Very surprise to me.I found this is a built-in function but it is undocumented.Such as this answer's "CurvedArc" and "Curvature",...
3
votes
1answer
465 views

Gâteaux (directional) derivatives and higher order differentials of a functional

I would like to calculate the Gâteaux derivative of a functional (i.e. a function depending on functions). A simple example for the Dirichlet functional: $L(u(x))=\int_0^1 \frac{1}{2} (u'(x))^2 dx$ ...
6
votes
1answer
116 views

Filters on image vs data

I was using GaussianFilter and realized that applying it to an array yields a different result from applying it to an image. For instance: ...
41
votes
5answers
1k views

Why is there no PositionFunction in Mathematica?

Too often I have seen the programs of inexperienced users greatly slowed by using Position in an iterative fashion, when far faster would have been to compute a ...
3
votes
0answers
62 views

How to build a ColorFunction that can take a non-numeric value? Blend returns an error

I'm trying to use an external package, defined here. This package has a private function called makeColorFunction that essentially works by taking an input color ...
-5
votes
1answer
57 views

What is this function aimed to do? [closed]

Table[Sum[tmatrix[[i, j]], {i, 1, 2}], {j, 1, 2}] apparently creates some sort of a table, and it evidently works on a matrix....although it is hard for me to understand what should it do beyond ...
8
votes
1answer
187 views

How to efficiently write code with many functions that have variable number of iterators/arguments/

I am finding myself having to code functions like this: $$\text{answer} = \sum_{k_0 = 0}^{\color{Blue}n_0} \sum_{k_1=0}^{\color{Blue}n_1}\cdots\sum_{k_{N-1}=0}^{\color{Blue}n_{N-1}} \frac{P_{k_0,k_1,\...
1
vote
1answer
57 views
10
votes
1answer
1k views

How does a Pringle lose its curvature?

Nom! As part of a bigger project, I've was writing some code to calculate the scalar curvature of surfaces of the form $z = f(x,y)$. This uses a general calculation of the scalar curvature to produce ...
1
vote
2answers
118 views

Function does not execute commands and fails to evaluate [closed]

The code I am trying to execute: hh[x_, y_] := x + y; hh[{3, 4}] The expected output: 7 However, on output I get ...