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

3
votes
1answer
50 views

Evaluating a list of randomly sampled triplets with a function of three variables

I'm new to Mathematica. I need to generate a list of 1000 triplets of random numbers {r, p, t}, so that 0 < r < 1, ...
-4
votes
1answer
68 views

Apply If function to FoldList [on hold]

I have defined the following function: cpdz[c0_, m_,s_, r_, t_, n_] := If[c0 > 0, c0*(m*c0\s - (m - 1)*Exp[r*t/n]), c0*Exp[r*t/n]] for s I have a set of ...
-1
votes
1answer
69 views

How to plot a function containing $\pm$ and unlimited solutions $n$? [duplicate]

I have $$y=n\pi\pm\arcsin(\sin(x)), n\in\mathbb{Z}$$ How can one define and plot such a function in Mathematica for multuple $n$ at the same time?
0
votes
1answer
27 views

Using set of lists in if function? [closed]

I have the following function: a3[m_, C_, St_, Stt_] := If[C > 0, (m*C)/St*Stt, 0] now my input for C, St and Stt are different set of lists. So I tried to ...
0
votes
0answers
25 views

Nest function with an incremental parameter? [closed]

Usually, if we use the Nest[] command, it nests the function directly as in Nest[f,x,3] ...
0
votes
0answers
27 views

Pass list title as argument? [duplicate]

I have a function that works with a list and outputs it. Is it possible to also get the name of the list as an argument? Right now my code is ...
0
votes
2answers
84 views

Defining the Hirota operator

The Hirota $D$-operator (derivative) is mathematically defined as follows: $$D_x^n f\cdot g=\left.\frac{\partial^n}{\partial s ^n} f(x+s)g(x-s)\right|_{s=0} $$ An example of this operator acting on ...
2
votes
2answers
94 views

Recursion: How can i program this expression?

i have the following expression: Vt[EA_, V0_, Cm_, B_] := EA + (V0 - Cm)*B For EA and Cm ...
11
votes
6answers
397 views

Create a polynomial of a given degree

In Mathematica, how can I create a polynomial function in given variables of a given degree with unknown coefficents? That is, I am looking for a function ...
1
vote
0answers
35 views

Can you define “| |” to be the same as “Abs[ ]”? [duplicate]

When calculating the modulus of a complex number in Mathematica, the standard (and probably least-ugly) way of doing it is by using the Abs[ ] function. When doing ...
4
votes
2answers
76 views

Local modification of built-in command via UpValue

I have a computationally intense function f that returns a matrix. Sometimes only the diagonal is needed, which is faster to compute, thus there's a syntax for f to ...
3
votes
1answer
103 views

How to make a custom function as inbuilt

I have a custom function like following: ...
0
votes
1answer
40 views

Defining a function when the variables do not appear explicitly in the definition of the function

I am trying to take the curl of a vector field which is the a product of a scalar field (Psi) and a coordinate vector, {r,Theta,Phi}. After taking the curl I want to calculate the magnitude of the ...
3
votes
2answers
69 views

Using Solve[ ] inside a Module

I want to use Solve[] inside a Module. If I make the variables solved for local to the module, they are treated differently than ...
4
votes
2answers
71 views

Grouping/precedence for “/@” operator

This returns errors: {#[[1]],#[[3]]} & /@ {#[[1]],#[[2]],#[[3]]} & /@ {{"A","B","C"},{1,2,3}} Part::partd: Part specification A[[1]] is longer than ...
1
vote
1answer
45 views

Function with declaration of variables [closed]

Is it possible to create a function with declaration of variables inside. For instance ...
7
votes
1answer
286 views

How to split text without spaces into list of words? [duplicate]

What is the best approach to a problem like this in Mathematica? I can only manage this: ...
0
votes
0answers
15 views

Define a function as an evaluated integral [duplicate]

I have the following integral which I evaluate analitically ...
0
votes
1answer
38 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
vote
0answers
51 views

Line-crossing Algorithm Implementation (pt. 2) [closed]

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 ...
1
vote
1answer
71 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 ...
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
57 views
1
vote
1answer
81 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 $$ ...
3
votes
0answers
91 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 \...
8
votes
1answer
102 views

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

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
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 ...
3
votes
1answer
70 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 ...
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 ...
-3
votes
1answer
135 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 ...
4
votes
2answers
109 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 ...
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: ...
5
votes
2answers
95 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: ...
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 ...
1
vote
0answers
39 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
35 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: ...
15
votes
3answers
301 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 ...
3
votes
1answer
75 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
2answers
152 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. ...
-2
votes
1answer
44 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 ...
2
votes
0answers
61 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{...
3
votes
2answers
61 views

Catch parameter order and error using functional form

Question: Why does this fail? In:= (Catch[#] &)[Throw[17]] ...
4
votes
1answer
113 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",...
6
votes
4answers
110 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?
6
votes
1answer
120 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: ...
-5
votes
1answer
58 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 ...
3
votes
0answers
63 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 ...