Questions about the use of built-in Mathematica functions, including pure functions.

learn more… | top users | synonyms

8
votes
1answer
214 views

Prevent Export from overwriting files

Export["filepath1",Expression1] works for me, but if filepath1 already exists, it will be overwritten. I'd like ...
52
votes
4answers
3k views

Using a PatternTest versus a Condition for pattern matching

My last question to the site resulted in several answers that involve using pattern matching in Mathematica, a feature I wasn't very familiar with at the time. I am currently reading Mathematica ...
123
votes
7answers
5k views

What are the use cases for different scoping constructs?

Mathematica includes three functions that I know of which can be used to effectively (if not actually) define a variable and give it a value within a local scope: ...
32
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 ...
16
votes
1answer
253 views

In 10.1.0 BenchmarkPlot doesn't work?

In Mathematica 10.1.0 BenchmarkPlot from the GeneralUtilities package doesn't work; copying Taliesin Beynon's initial use of the function on this site: ...
2
votes
3answers
136 views

truncated square wave input

I'm investigating the response of some dynamic system on Mathematica and I want to generate a tailored square input like the one in the following picture: Does anyone know how to generate such input ...
2
votes
1answer
70 views

Computing large nested values

Is it possible to compute a value for n=10^9; Nest[# + Log[#] &, 2., n] for large n? $10^9$ seems to be the max for me - ...
0
votes
2answers
70 views

Continuity of function-example

I'd like to examine the continuity of the following function: f[x_] := Limit[(n^x - n^(-x) ) / (n^x + n^(-x) ), n -> Infinity] I know that this function isn't ...
0
votes
3answers
87 views

beginner's question: change a parameter while get variable answers [duplicate]

I'm new to Mathematica from R, since R is not quite good at dealing with the following problem. Say, i want to solve the function a x - 10 = 0. Each time I change the value of a, say, from 1 to 10 by ...
0
votes
0answers
47 views

Errors when changing variables

I have the following function : K[r_, h_] = -(D[h[r], {r, 2}] + D[h[r], r]/r + D[h[r], r]^3/r)/(2 (1 + D[h[r], r]^2)^(3/2)) In order to adimension it, I am ...
16
votes
0answers
230 views

Performance problems in new Sequence functions

The new-in-10.1 Sequence* family of functions should provide newly optimized methods for handling sequence problems. Happily in some cases they do! For example ...
1
vote
2answers
93 views

Get the sum with cases

I have the following list: list = {{1, 2}, {2}, {3, 4, 1}, {5, 4}, {3, 3}, {a, b, c}, {e, f}, {g}, {}, {Sin[a], Cos[b]}}; I should use ...
5
votes
1answer
85 views

Handy dates conversion

I feel like something very basic is missing me, $dateformat = {"Year", "Month", "Day", "Hour"}; date = DateString[$dateformat] DateString["Date"] ...
5
votes
2answers
142 views

Using MovingMap to calculate percentage changes

MovingMap (new in version 10) applies a function to discrete data over a moving window. This is very convenient for calculating the percentage change of a series. ...
8
votes
2answers
255 views

What does IndexBy do and how exactly does it work?

I just saw the function IndexBy in the autocomplete suggestions and I was curious to know exactly how it works. Unfortunately, there's no trace of it in the ...
1
vote
1answer
78 views

How to construct a kernel from a function?

I would like to convolve an image with a mathematical function. I understand that I need to have the mathematical function in a matrix form. How can I build it? Thanks
2
votes
2answers
96 views

Creating a Cayley's table of square

I'm interested in creating a Cayley's table of square using Mathematica. I'm not a programmer but occasionally resort to using Mathematica to simplify my work insofar as the programming doesn't take ...
1
vote
1answer
104 views

Understanding `FixedPoint`

I understand that FixedPoint[(# + 2/# )/2 &, 1.] can be written ...
0
votes
0answers
24 views

Fibonacci series up to 300 terms [duplicate]

I tried to generate a list of Fibonacci numbers up to 300 terms and gets a runtime error. f[0]=0; f[1]=1; f[x_]:=f[x-1]+f[x-2]; Table[f[x],{x,1,300}] Is there ...
0
votes
1answer
52 views

Question about a catalytic equality?

I have a question on math.SE that explains how I came up with these equations. ...
-2
votes
3answers
64 views
3
votes
1answer
72 views

Why minimization does not work with symbolic array as arguments

If I try to minimize with constraints a function of several variables, with Gamma regularized function involved in the constraints it seems to works, as shown below (this is just a dummy example ...
-3
votes
2answers
83 views

Random Polynom Plot [closed]

I should write a module "RandomPolyPlot[n, amin, amax]" which calculates all roots (nulls) of a n-th degree polynomial function. Then I should illustrate it on the complex plane. I also should ...
1
vote
2answers
73 views

How to stop FullSimplify from returning Root objects

I have several expressions in a series, such as 1/4 (-(1/4) + Sqrt[5]/4 + I Sqrt[5/8 + Sqrt[5]/8]) (-1 - Sqrt[5] + 2 Sqrt[7/2 + (5 Sqrt[5])/2]) If I run ...
-3
votes
2answers
84 views

Write a function, write a pattern [closed]

I have the following list: list = {{1, 2, 4}, 6, 7, 8, {8, 2}, {3, 4}, {4, 5}, {1, 2, 3, 1}}; (a) I should write a predicate-function in combination with an ...
0
votes
0answers
28 views

Why don't we use SetDelayed when we use placeholder to declare a function? [duplicate]

On the answer of http://stackoverflow.com/questions/4272067/what-does-mean-in-mathematica Typically when we declare f(x)=x^2 function, it is: f[x_] := x^2 But ...
0
votes
0answers
40 views

How can I put the results of TrigReduce function into a more convenient form? [duplicate]

a1 D11 Cos[n x] + a0 a1 D11 Cos[n x] + 1/2 a1 a3 D11 Cos[n x] + 1/2 a2 a4 D11 Cos[n x] .......for example this expression can be written like ('expression') * ...
6
votes
2answers
96 views

Optional arguments with lists as function parameter

I'm developing a function f which should support optional arguments {x_, y_} in list form. A simple example looks like this: ...
2
votes
1answer
106 views

How to run code in a saved file when it is opened

I have a Mathematica file that I saved. In it, I have multiple functions that I've defined and have evaluated a number of the functions with different arguments. I would like to be able to open the ...
1
vote
1answer
67 views

Defining a Function

I've been reading about functions in Mathematica and playing with this for hours, but I'm clearly missing something. The following code correctly calculates "fail", the number of failed scenarios. I ...
1
vote
1answer
157 views

Create a function with Dt[x] as a variable

I have a function (for example F[x_]:=Cos[x]). I want to define a function like Fdot[x_,xdot_]:=Dt[F[x]] where xdot represents Dt[x]. For example, to define Fdot one might naivley try ...
2
votes
1answer
115 views

How do I download and export data from many weather stations?

I tried this code, which downloads data from several weather stations. ...
1
vote
0answers
27 views

Import names into notebook namespace

I have function that at some point has list of strings (e.g. {"apple","pear"}) and I want to declare (initialize) those variables in notebook namespace to default value (e.g. 0) so I could execute in ...
0
votes
1answer
84 views

How can I use nonlinear model fit with multiple variables? [closed]

I have a data set with four entries. the first three entries correspond to variables in the fit x,y, & z. The fourth entry corresponds to the function value. I am trying to fit this data to a rate ...
0
votes
1answer
65 views

How to properly use conditionals inside NDSolve

Currently I am working with Mathematica to learn the program, and I'm confused what exactly is wrong with this code. ...
0
votes
0answers
44 views

StringLength function [duplicate]

allWeatherStations = WeatherData[]; fullformStations = FullForm /@ allWeatherStations; Tally[StringLength /@ fullformStations[[All, 1, 2]]]. This code not working. ...
-1
votes
1answer
124 views

need help to price a european option using finite difference method [closed]

I am writing a function to price European option using backward induction finite difference method. The function is expected to price a European option taking Stock (stock_), age (time_), volatility ...
19
votes
5answers
1k views

Moving maximum function?

How can I construct a moving maximum function? For example, if I have a list of 12 values: { 5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7 } and I want to maximize over 3 ...
0
votes
1answer
52 views

Replace element of matrix based on rule which invloves other element of same matrix

I am trying to replace 1s row of matrix d iteratively from right by multiplying last element in 1st row with (1-int*dt) to generate 2nd last element. The replacement continues till I reach the 1st ...
4
votes
2answers
125 views

Coarse-graining in numerical integrations

I have been working recently in a coarse-graining problem I found when using NIntegrate: I am trying to evaluate the function $$f(a)=\int_0^{\infty}x\,e^{-(a^2+b^2)x^2}\text{d}x$$ numerically as a ...
0
votes
0answers
55 views

How to replace a part of array based on certain rules which involves usage of other array

I am trying to replace outermost column of array "fd" in below code. fd is matrix of dimension (nas1,nts) which is initially filled with 1. I want to replace outermost column of fd with result of Max ...
2
votes
0answers
59 views

What is the difference between GenerateDocument and TemplateApply[NotebookTemplate[

Abstract GenerateDocument[ _NotebookObject ] seems to do the same what TemplateApply[ NotebookTemplate @ _NotebookObject ] ...
4
votes
0answers
86 views

Using an external Pattern breaks Format

I noted while writing this answer that using an external Pattern on Format doesn't work: ...
1
vote
2answers
168 views

How can I create function which contains an ODE system and its numeric solution?

I have created a function like the following, which contains an ODE system. And I want to know the effect of different parameters. ...
0
votes
2answers
199 views

FindShortestTour to solve Traveling Salesman Problem

I'm trying to write my own code to find the shortest route but I'm lost on how or where to start. Does anyone have any idea how the FindShortestTour function works? What type of algorithm or structure ...
9
votes
1answer
302 views

solve ODE with divergencies

The solutions of the second order differential equation $$\frac{1}{\eta}\frac{d}{d\eta}\left(\eta \frac{df}{d\eta}\right)+\left(1-\frac{s^2}{\eta^2}\right)f-f^3=0$$ is shown in Fig. 5.2 below, for ...
15
votes
6answers
1k views

Will Version 9 functions all work in Version 10?

Having developed a substantial code base in Mathematica 9, leads me to ask these important questions prior to downloading and installing Mathematica 10. Will any Mathematica functions from the ...
21
votes
3answers
827 views

DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?

Déjà vu: a new-in-v10 function should provide a better solution to an old problem, but my enthusiasm is curbed when I run timings. This time the function is ...