Tagged Questions

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.

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 ...
57 views

How may I repeat this procedure n times?

This is the procedure ...
125 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 ...
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 ...
111 views

Why a function returns two different values if copied into a Notebook or imported with Get from a Wolfram Mathematica Package?

I have some Mathematica code that shows a behaviour I really cannot understand. The code only contains a bunch of function definitions. If I paste it in the Notebook Front End and I evaluate it, I ...
52 views

What I make wrong with Module command;

I have a differential equations that I have to solve in two parts.e.g: ...
56 views

Derivative in my package return 0

I'm writing my package (.m) in Mathematica and when I'll call the function returns 0 instead of right output. Here's my code: Package.m ...
43 views

Greatest common denominator command. Can you explain why this command works?

Can you explain how this function works? mysteryFunction := Fold[#/#2 /. {n_~_~_ -> #/n, _ -> #2} &, #, {##}] &
280 views

Simpler way to type Derivative[1, 0][u][0, x]

Though not unbearable, I always feel a little nervous when typing partial derivatives at a specified place e.g. $u^{(1,0)}(0,x)$, which happens a lot when setting initial/boundary conditions for PDEs. ...
60 views

Custom units Compatible with Conversions [closed]

I am writing a Mathematica Palette to work with units, and am wondering if anyone knows a way to define new units outside of the standard ones that come with Mathematica 9. I do know of the ...
73 views

How to use recursion to find a logical dual

I want to make a little function that goes through a propositional formula and gives it's dual. Here is what I currently have: ...
36 views

How to define a general linear function [duplicate]

I'm trying to work with a general linear function in Mathematica. I would like to assign some sort of rules to a function, say Tbar, to evaluate linearly. Basically what I would like to do is have ...
39 views

Getting a list of function definition parameter values [closed]

If I define a function over certain values: f[0] = 1 f[1] = 2 f[2] = 3 How do I get the list of parameter values that it's been defined on? ...
62 views

Distinguish hashtag # operator when using multiple functions [duplicate]

I would like to do this list = Append[list[[#]],Map[list2[[1, #]] & , list[[#, 4]], {2}]] & /@ Range[Length[list]]; But I would like to substitute ...
127 views

Syntax f[x_][y_]

Need to understand the principle of the distinction between f[x_,y_] and f[x_][y_] It seems also that z[x_, y_][a_, b_, c_][α_, β_] := a (x + y)^b + c/(α-β) ...
63 views

User-defined density plotting function with a functional argument: extracting variables from the function and plotting in a circular region

I would like to customize the function DensityPlot and use it in a package as a function called MyDensityPlot: The functions ...
38 views

How is Attributes protected and yet can still be set?

The Attributes function itself has the attributes: Attributes[Attributes] ...
195 views

How to construct the RHS of Wick's theorem

I've been trying this for a few days now, but I just can't seem to find an efficient (speed-wise) functional way to code the following task. Context: I would like to construct an expressions that is ...
179 views

Number by permutation

I want a function that compute number of permutation in lexicographical order. E.g. ...
477 views

How to generate this structure of a list without While and the like?

I need to create a list that holds, for given integer d, the elements $1,\ldots,d,d+2,\ldots,2d,2d+3,\ldots,3d,3d+4,\ldots,d^2$ where $\ldots$ is just denoting ...
38 views

Plot is empty (probably) due to poor function definition

I am trying to plot my response $x(t)$ as a function of system parameter $M_0$. Here is my code to regenerate my problem ...
98 views

For loop works at top-level but not in a function

Why does this work: For[i = 1, i <= Dimensions[list][[1]], i++, list = Insert[list, i, {i, 3}]] But this doesn't: ...
169 views

Sets and sums of different elements

Consider the set S={w,x,y,z}. If the set of all possible sums of any three different elements from S is {-1,3,5,8}, then what is the set S? How could I solve this function using Mathematica?
79 views

Remove part within square brackets for function

So I've defined a variable as follows: q = {{x[t]}, {Φ[t]}} V=0.5*x[t]^2*m^2+0.5*Φ[t]^2*I I've had to differentiate with respect to time so: ...
78 views

How to obtain the Derivative of a pure Function of variable number of arguments?

Here is a function f that takes a variable number of arguments: f = Times[##]*Log[1 - Times[##]] & I now want to ...
49 views

How to calculate a continuous function once and access values later?

I have a function that involves a numerical calculation: h[v_]:=NIntegrate[f[x]*Log[p[x, v]], {x, -Infinity, Infinity}] I need to visualize how well a bunch of ...
52 views

AbsoluteTiming of nested integration gives strange result

I found somewhat strange behaviour of nested integration timings. Consider the following code: ...
54 views

Equivalent (?) definitions of function gives different answers

I have a function as follows: ...
42 views

Why doesn't this function definition work?

I am trying to define a following function (which is a convolution integral) ...
100 views

Plotting a periodic function [duplicate]

My question is the following: how can I plot a function repeatedly? By following some topics here I found some basic information about using Fourier series. This is what I made: ...
79 views

Finding roots of a function that includes Bessel functions [duplicate]

I'm fairly new to Mathematica so forgive any stupid mistakes. Here's my function: ...
89 views

Write complex number in terms of absolute value and phase

I have a long vector and some of the values (19 out of 64) are complex. I got them using the Mathematica Rationalize function, so the complex ones are written in the a+bi form. Is there a function I ...
92 views

How to turn a subroutine into a function?

I've written a subroutine that takes in 6 matrices and after some manipulation returns back 3 new ones. I will use this subroutine fairly often in this notebook so I think it would be easier to turn ...
107 views

n fold convolution of a function via a recursion function

I wanted to write a recursion function to calculate the n-th convolution of a function f[x_]. I wrote the function ...
59 views

Considering special cases in general definitions

I want to calculate some coefficients $\qquad B_k = 2\int_0^1 u(x) \cos(k\pi x)\,dx$ for $0<k\in\mathbb N$ and I am doing this in the following way: ...
56 views

break down the function

I am using Series function, but I found that it cost too much time. Since the Series function is Taylor expansion and I only need first order, I want to break down the code, so I can make it faster <...
49 views

Passing a list to a nested vector function

In order to apply a newton-rhapson algorithm to solve a set of nonlinear vector equations such as these, f[x_, y_] = {x^2 - 3*y + 6, (y + 1)^2 - x - 33} I need ...
89 views

Partial Function Evaluation [closed]

How can I evaluate only part of a stack of function calls? In particular, given f[x_,y_,z_]=x+y+z;, say, I'd like to define a function ...