Skip to main content

Posts

numerics - A problem about function N

Toady,I have a problem about N ,described as below: For example N[1/3, 5] (* ==> 0.33333*) and N[1/3, 5] can make the result keep five significant figures. data= RandomReal[{0, 2},8] (* ==> {0.952811, 0.834171, 0.309447, 1.41046, 1.46811, 0.385663,1.50229,1.82034}*) However,I want to make the data Keep four significant figures,so I use the function N[#, 4]& N[#, 4]&/@data (* ==> {0.952811, 0.834171, 0.309447, 1.41046, 1.46811, 0.385663,1.50229,1.82034}*) Unfortunately,it failed. My trail: I copy the result,and paste in a input: 0.9528112485377731`, 0.8341711402854446`, 0.3094468949977962`, 1.410457480346131`, 1.4681075372399688`, 0.38566305213741137`, 1.502289805503937`, 1.820341132427437` I wipe out the symbol `,and data1= {0.9528112485377731, 0.8341711402854446, 0.3094468949977962, 1.410457480346131, 1.4681075372399688, 0.38566305213741137, 1.502289805503937, 1.820341132427437}; N[#, 4]&/@data1 ==>(Wrong result,still keeping six significant f...

polynomials - How to express the original ideal elements in the Groebner basis?

Suppose I call GroebnerBasis[{f1, f2, ...}, {x1,x2, ...}] The output is a list {g1,g2,...} For each $g_j$, there should be an expression $g_j = \sum f_i h_{ij}$ for some polynomials $h_{ij}$. How do I make Mathematica output the $h$'s? In case there is a better approach, I'll tell you my actual goal. I have polynomials $\{ f_1, f_2, \ldots, \}$ which generate an ideal $I$, and an element $q$ which I know to be invertible in the quotient ring $\mathbb{R}[x_1, x_2, \ldots]/I$. I want to generate an explicit polynomial representative for $q^{-1}$. My plan is to compute the Groebner basis of the ideal $\langle f_1, f_2, \ldots, q \rangle$, which will be $\{ 1 \}$, and find the expression $1 = \sum f_i h_i + pq$; the answer is then $p$. Calling PolynomialReduce[1,{f1, f2, ..., q}] does not have the intended effect because {f1, f2, ..., q} is not a Groebner basis. Answer Here is how I would go about finding the reciprocal as a member of that quotient ideal. I'll demonstrate w...

list manipulation - How can I select elements that are true

I have a list of lists. For example, list = {{0,1,0,1,true},{0,0,0,0,false},{0,1,1,1,true},{1,1,1,1,false},{2,2,2,2,false}} I'd like to find all lists that have the fifth element set to true . I'm looking for a general method that works for any lists in this format. How can I do this? In the above example, the result that I'm looking for would be: {{0,1,0,1,true},{0,1,1,1,true}} Sorry for such a basic question. I looked through the documentation for lists, and couldn't find a way to do this. I'm still fairly new at Mathematica . Answer There are several options and this is probably a duplicate although I can't seem to find it. A few of them to try out and learn: list = {{0, 1, 0, 1, true}, {0, 0, 0, 0, false}, {0, 1, 1, 1, true}, {1, 1, 1, 1, false}, {2, 2, 2, 2, false}}; Cases[list, {__, true}] Select[list, Last@# === true &] DeleteCases[list, {__, false}] Pick[list, list, {__, true}] /. {} -> Sequence[] all of which return (* {{0, 1, 0, 1, t...

fourier analysis - FourierTransform and Partial Derivatives?

I have a function of three variables $f(x,y,z)$, and it obeys a linear partial differential equation. I'm checking my by-hand calculations with Mathematica. I want to convert the PDE into the Fourier-spectral domain, but Mathematica isn't playing nice. I find the following behavior baffling. FourierTransform[D[f[x, y, z], x], {x, y, z}, {kx, ky, kz}] -I kx FourierTransform[FourierTransform[FourierTransform[f[x,y,z],x,kx],y,ky],z,kz] FourierTransform[D[f[x, y, z], y], {x, y, z}, {kx, ky, kz}] FourierTransform[Derivative[0, 1, 0][f][x, y, z],{x,y,z},{kx,ky,kz}] FourierTransform[D[f[x, y, z], z], {x, y, z}, {kx, ky, kz}] FourierTransform[Derivative[0, 0, 1][f][x, y, z],{x,y,z},{kx,ky,kz}] Essentially, it's like Mathematica uses $\mathcal{F}\left[\frac{\partial f}{\partial x}\right]=-i k_x \mathcal{F}\left[f\right]$ for the first argument $x$, but does not use the same rules/identities for partials w.r.t. second and third arguments, i.e. $\mathcal{F}\left[\frac{\partial f}{\par...

plotting - Recovering data from an existing plot

I have some plots in an old Mathematica notebook that I'd like to re-create in Matplotlib (for stylistic consistency with the rest of the plots in my thesis). Unfortunately, I've lost the data that I used to generate these plots. Since the plots are still intact, is it possible to extract the coordinates of the data points from them? I know that I can use "Get Coordinates" from the context menu on the plot, but this is tedious and imprecise! They were generated in version 8 or 9, I think. This is the code that I used to generate the plots: MoneyPlot[dataSets_, Vs_, fs_] := Show @@ {ListLogLogPlot[dataSets[[1, 1]], PlotStyle -> dataSets[[1, 2]], Joined -> True (* Some more options *) ]}~Join~ Table[ListLogLogPlot[data[[1]], PlotStyle -> data[[2]], Joined -> True], {data, dataSets[[2 ;;]]}]; Answer As explained by anderstood , if you don't have the plots named, you need to copy and paste the figure into an input cell...

filtering - Can Mathematica delete some of the 0's from a list?

I have a list: {1,2,3,0,0,4,5,0,0,0} . I want to delete the 0 's occurring after the last positive integer. In other words, I want Mathematica to return: {1,2,3,0,0,4,5} . Answer The easiest way would be to use {1, 2, 3, 0, 0, 4, 5, 0, 0, 0} /. {a___, 0 ...} :> {a} /. is synonymous with ReplaceAll . It tries to replace values on the left hand side with the rules on the right hand side. In this case {a___, 0...} is the pattern; a___ matches zero or more elements, and 0... matches zero or more zeroes. :> {a} takes the a that corresponds to the matched expression and returns it.

list manipulation - quantilization (if that is a word)

Suppose I have a list of data, and a list of quantiles ( {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9} is a perennial favorite), and I want to assign to each element the quantile it is in (so for Range[100], the first ten numbers will be in the 0th quantile, I guess, the second ten in the first, and so on). Now, there is a way of doing this by ranking all the data by PermutationList[FindPermutation[Ordering[mydata]]] , and then operating with the ranking, but this seems clumsy. Any slicker way?