# 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.

42 views

### Why doesn't this function definition work?

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

### How to set a values inside a custom function [duplicate]

I have a custom function like this stringLength[string_] := StringLength[ ToExpression[StringJoin[ToString /@ {del, string}]] = StringDelete[string, " "]] ...
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 ...
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: ...
394 views

### Writing functions with “Method” options

I'd like to implement several behaviors for a particular function using a Method option added to the function definition: ...
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 <...
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 ...
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 ...
96 views

187 views

### How to track Part of Symbol or How to symbolize Parts of Symbol without copying data

Let's create simple function: SetAttributes[h, HoldFirst]; h[data_] := Dynamic[Grid[data], TrackedSymbols :> {data}] test = RandomReal[1, {2, 2}]; h[test] ...
30 views

### Applying a function to the second element of a list [duplicate]

I'm trying to apply a simple function to the second element of a list: {#1, #2/5} &@{1, 2} But this returns an error message. ...
48 views

### Is there a way to make the Function construct accept a list as argument? [duplicate]

Is there a way to make the Function construct accept a list as argument ? Writing Function[{x,y},{x+y,x-y}] does not work, ...
30 views

### Using the Function construct in a table with parameters [duplicate]

I'd like to define a table of functions like so Table[Function[{x,y},{x + k y,x - k y}] , {k,1,10}] My intention is to have the first function defined with k=1, ...
246 views

### A function generating particle-in-a-box eigenfunctions

This function sequence is defined over $\left[-\frac{L}{2},\frac{L}{2}\right]$ (all elements are valued 0 outside this interval): \psi_n(x)=\begin{cases}\sqrt{\frac2{L}}\sin{\left(\frac{n\pi x}{L}\...
102 views

### PrimeNu counting function

Building on this question, what is the most efficient counting function for distinct prime factors? It would obviously be more efficient if Prime and ...
1k views

### Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
55 views

### Importing data, then plotting ListPlot. What's the most efficient way to write a code?

It should be a boring question to ask for someone, but this is very basic need which I haven't resolved by myself. I know I can use MapThread and pure function to make it short and beautiful, but even ...
53 views

### Using the Nest function — Confusion on my output

I have the following code and output where the original function is $f(x,a) = a^2 - x^2$. ...
50 views

### Convert string to function with an argument

I am trying to build an expression by first writing it out as a string and then using ToExpression to convert it to an expression. However, I cannot figure out how to make expression recognize x as an ...
137 views

### Are these two functions equivalent?

I checked several cases and saw that two functions are equivalent in these samples. However, are the two equivalent in all cases? Is there a way to check that? Explicit function: ...
50 views

### First position of incremental series

I am still a beginner and maybe I want to do something too complicate! After 29 cycles I obtained the following events list: ...
41 views

...
58 views

### Multi-case function: many single-case delayed assignments; or one Which[]?

A function needs to cope with many different forms of input, such as different heads (Plus, Times, ...