mathematica-8

Avoid repeated calls to Interpolation

╄→гoц情女王★ 提交于 2019-12-04 03:47:10
I want to interpolate a function in mathematica. The function depends on a parameter a , in fact it is the inverse of a function F which also depends on a , so I build my approximation as follows, approx = Interpolation[Table[{F[0.1 n, a], 0.1 n}, {n, -100, 100}]] now I can simply call approx[x] to evaluate the inverse function at a point. Instead I would like to do something like this: Define a function which takes a parameter, G[x_,a_] = "construct the interpolating function, and return the value of the function at x" Then write G[x,a] to evaluate the function. Otherwise I would have to

Logarithmically spacing number

空扰寡人 提交于 2019-12-03 14:53:23
问题 I would like to test several values of intensity. I need them to be spaced logarithmically from 1 to 1000. Yet I just use 1, 10, 100, 1000, but I would like to have more data point, let`s say 10. How could I find 10 logarithmically spaced number between 1 and 1000 in Mathematica ? 回答1: If a is start, c is end and b is number of intervals: {a, b, c} = {1, 10, 1000}; t = (c/a)^(1/b) // N a*t^Range[b] 1.99526 {1.99526, 3.98107, 7.94328, 15.8489, 31.6228, 63.0957, 125.893, 251.189, 501.187, 1000.

Import data from URL

一世执手 提交于 2019-12-03 11:32:56
问题 The St. Louis Federal Reserve Bank has a great set of data available on a variety of their web pages, such as: http://research.stlouisfed.org/fred2/series/OILPRICE/downloaddata?cid=32217 http://www.federalreserve.gov/releases/h10/summary/default.htm http://research.stlouisfed.org/fred2/series/DGS20 The data sets get updated, some as often as daily. I tend to have an interest in the daily data (see the above settings on the URLS) I'd like to import these kinds of price or rate data streams

Formatting usage messages

时光毁灭记忆、已成空白 提交于 2019-12-03 07:47:48
问题 If you take a look at the Combinatorica package in Mathematica8 in (mathematicapath)/AddOns/LegacyPackages/DiscreteMath/Combinatorica.m you will find the definitions of functions. What I'm interested to know is how Mathematica knows how to format the usage messages. Something tells me that I'm not looking at the right file. In any case, lets try the following: Cofactor::usage = "Cofactor[m, {i, j}] calculates the (i, j)th cofactor of matrix m." This line is the 682 line in the file mentioned

NIntegrate - why is it much slower in Mathematica 8 in this given case?

蹲街弑〆低调 提交于 2019-12-03 05:17:35
问题 I have a Mathematica code where I have to evaluate numerically thousands of integrals similar to this one NIntegrate[ (Pi*Cos[(Pi*(-2*x + y))/(1 + y)] + (1 + y)*(-Sin[(2*Pi*x)/(1 + y)] + Sin[(Pi*(-2*x + y))/(1 + y)]))/(E^x*(1 + y)), {x, 0, 100}, {y, 0, 100} ] //AbsoluteTiming The integrand is a nice absolutely integrable function without singularities, which decays exponentially in one direction and as 1/y^3 in the other direction. The NIntegrate command was working fine in Mathematica 7, but

Import data from URL

偶尔善良 提交于 2019-12-03 01:50:57
The St. Louis Federal Reserve Bank has a great set of data available on a variety of their web pages, such as: http://research.stlouisfed.org/fred2/series/OILPRICE/downloaddata?cid=32217 http://www.federalreserve.gov/releases/h10/summary/default.htm http://research.stlouisfed.org/fred2/series/DGS20 The data sets get updated, some as often as daily. I tend to have an interest in the daily data (see the above settings on the URLS) I'd like to import these kinds of price or rate data streams (accessible as CSV or Excel files at the above URLs) directly into Mathematica. I've looked at the

Formatting usage messages

故事扮演 提交于 2019-12-02 21:16:53
If you take a look at the Combinatorica package in Mathematica8 in (mathematicapath)/AddOns/LegacyPackages/DiscreteMath/Combinatorica.m you will find the definitions of functions. What I'm interested to know is how Mathematica knows how to format the usage messages. Something tells me that I'm not looking at the right file. In any case, lets try the following: Cofactor::usage = "Cofactor[m, {i, j}] calculates the (i, j)th cofactor of matrix m." This line is the 682 line in the file mentioned above. Now if we run it in a mathematica notebook and we use ?Cofactor we will see the exact same

Doing probabilistic calculations on a higher abstraction level

老子叫甜甜 提交于 2019-12-02 16:46:36
To the downvoters: this isn't a question about mathematics, it's a question about the programming language Mathematica . One of the prime characteristics of Mathematica is that it can deal with many things symbolically. But if you come to think about it, many of the symbolic features are actually only halfway symbolic. Take vectors for instance. We can have a symbolic vector like {x,y,z}, do a matrix multiplication with a matrix full of symbols and end up with a symbolic result and so we might consider that symbolic vector algebra. But we all know that, right out of the box, Mathematica does

Integrating notebooks to Mathematica's documentation center

你离开我真会死。 提交于 2019-11-30 06:09:33
问题 If you have been using Mathematica for a while you probably have grown attached to the documentation center. There is always something new that you find in those pages. Let it be options for a function or just some examples that at some point did not seem useful to you. It is likely that you have written packages with your specialized functions that you use all the time. Sometimes you might think of a neat example to use with your function but it is likely that it ends up being forgotten

Minimizing NExpectation for a custom distribution in Mathematica

百般思念 提交于 2019-11-29 23:24:37
This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution following along the lines discussed by @Sasha in a number of answers over the past year. Code defining the distributions follows: nDist /: CharacteristicFunction[nDist[a_, b_, m_, s_], t_] := (a b E^(I m t - (s^2 t^2)/2))/((I a + t) (-I b + t)); nDist /: PDF[nDist[a_, b_, m_, s_], x_] := (1/(2*(a + b)))*a* b*(E^(a*(m + (a*s^2)/2 - x))* Erfc[(m + a*s^2 - x)/(Sqrt[2]*s)] + E^(b*(-m + (b*s^2)/2 + x))*