I have a simple question, for the specific project I am working on I would like mathematica to not evaluate extremely small decimals (of the order of ~10^-90) to zero. I would like a scientific notation return. When I evaluate similar expressions into WolframAlpha I receive a non-zero result.
For an example of a specific evaluation which returns non-zero in wolfram, and zero in mathematica:
Mathematica:
In[219]:= Integrate[dNitrogen, {v, 11000, Infinity}]
Out[219]= 0.
Compared to WolframAlpha:
I've tried searching around myself but oddly enough have only found solutions to the opposite of my problem -Those wanting when mathematica evaluates the small number to print as zero, this seems to involve some use of the Chop function.
Thanks for help/suggestions.
You should use NIntegrate instead of Integrate. By default it will give you the precision you're wanting, and it's also configurable through the PrecisionGoal parameter (and other parameters, see the NIntegrate docs for details).
Related
I am making some software that need to work with integers.
Also I need to apply some formula to those integers, repeatedly over time (example, do x/=z several times in a row for a indefinite amount).
All tools, algorithms and formulas I could think or find, or don't work with integers at all, or work as approximations at best.
For example the x/=z several times in a row for example, you can theoretically calculate what x will be in the 10th time by doing x = x/(z^10), but that will be wrong if the result is fractional, you can use floor(x/(z^10)), but the result will STILL be wrong.
Plotting software that I found also don't have integers at all, or has "floor()/ceil()" functions support, at best, and still the result would fall in the problem of the previous paragraph.
So how I do it?
Here's something to get you going for the iteration of x/=z:
(that should have ended in "all three terms are 0 with regard to integer division")
Now if x or z are negative, you can try and see whether this still holds; I did not invest the time to make the necessary case distinctions, but they should be fairly analogous.
As Karoly Horvath mentions in a comment, without a clear specification of the kinds of functions for which you would like to find a shortcut to replace iterative evaluation, helping you out won't be possible since there are uncountably many functions over the integers, and the same approach won't work for all of them.
My question is regarding integration. I have a complex function that needs to be integrated and its a definite integral. The thing is when I use Wolfram Alpha to integrate this function it gives me nothing i.e its unable to compute it. However if I remove the boundaries of integration i.e I make my integral an indefinite integral, Wolfram Alpha is able to compute. Now my question is
Can I take the result I obtained for the indefinite integral and just evaluate for the boundary limits to evaluate my definite integral ?
If my analysis is correct, then why wouldn't Wolfram alpha give the result anyways?
using Wolfram Alpha, if I try
integrate(exp(-v)/(1+sv^-1))
then I get the following result
-e^(-v)-e^s s Ei(-s-v)
While if I try
integrate(exp(-v)/(1+sv^-1),{v,1,+infinity})
I get nothing!
since you tagged this Mathematica:
by specifying an appropriate assumption on s we get the expected result:
Integrate[Exp[-v]/(1 + s/v) , {v, 1, Infinity}, Assumptions -> {s > -1}]
--> 1/E + E^s s ExpIntegralEi[-1 - s]
I don't know if alpha has some similar syntax to add assumptions..
additionally if we try a finite integral:
Integrate[Exp[-v]/(1 + s/v) , {v, 1, 2} ]
mathematica returns a conditional expression that tells us the result is valid for s>-1 or s<-2. For some reason it doesn't give such result for the infinite case however.
Yes, you can take the result obtained for the indefinite integral and use to calculate the definite integral. When I try to run your request at Wolfram Alpha, here's what I get:
As you can see in the highlighted portion at the bottom left of the above picture, Wolfram Alpha didn't complete your request because it exceeded the standard computation time. This is because they need to offer some extra features for Wolfram Alpha Pro users to pay for the service. One of this features is extended computation time.
Wolfram Alpha is a business, and this is one of the ways it makes money. See for yourself, it'll offer you the pro service if you click the "Try again with additional computational time" on the bottom right.
If you just break down the definite integration between first the indefinite integral (which it can handle) and then calculate the boundary values and take the difference, it seems to work fine:
This is mathematically correct because that is how definite integrals are calculated.
However your input has an sv in the dividend. Wolfram Alpha is taking it to mean s*v, which might not be what you meant—if sv is a variable on it's own, I suggest you rename it to s or something else. The point is that if s is indeed a variable, if you take a look at the plot in the answer, there seems to be a ridge due to the -∞ term, so for some values of s that ridge might be within your integration curve, and then the integral can't be calculated, as Bill pointed out in his comment to your question.
So I'm doing some benchmarking of a method for numerical optimization in Mathematica and I'm getting some inconsistent results when I use the Method->Automatic specification with FindMinimum. What I want to do is check what method it is choosing. I know I can use AbsoluteOptions[] to extract the choices from a some output, like a Graphics object, but this doesn't work with FindMinimum, ie
AbsoluteOptions[ Findminimum[ f[x], {x, 0.}, Method->Automatic ], Method ]
doesn't work. Can I do this?
I don't think there is a general way to find what method is used by numerical functions, other than reading the documentation. The documentation on unconstrained optimization is pretty good, though. There it says:
With Method -> Automatic, Mathematica uses the "quasi-Newton" method
unless the problem is structurally a sum of squares, in which case
the Levenberg-Marquardt variant of the "Gauss-Newton" method is used.
When given two starting conditions in each variable, the "principal axis"
method is used.
Additionally, for constrained problems the interior point method is used. If the problem is linear (objective and constraints) linear programming will be used. (LP itself has, I think, three methods that are used, depending on size and other features.)
I want to illustrate the stability of some numerical algorithms. I want to use Mathematica to round floating point numbers according to the usual rule, for example:
myRound[3/80.]=0.038 if I specify the precision to be 2-digit.
Another one
myRound[89/47.]=1.89
So given a precision number, how to write the myRound function? Please help. Many thanks.
You should look into NumberForm. For example:
NumberForm[89.0/47.0, 3]
Returns 1.89.
Acutally, it occurs to me that if you really want to illustrate round off issues, you should look into the ComputerArithmetic package. It's well documented, so I'll leave it at that.
I am not sure is this is what you would like:
In[34]:= customRound[x_Real] :=
Round[x, 10^Round[RealExponent[x]]*0.01]
In[35]:= customRound[3/80.]
Out[35]= 0.038
In[36]:= customRound[89/47.]
The function actually changes the number, as opposed to merely changing the way it is displayed.
I just started working with Mathematica (5.0) for the first time, and while the manual has been helpful, I'm not entirely sure my technique has been correct using (Full)Simplify. I am using the program to check my work on a derived transform to change between reference frames, which consisted of multiplying a trio of relatively large square matrices.
A colleague and I each did the work by hand, separately, to make sure there were no mistakes. We hoped to get a third check from the program, which seemed that it would be simple enough to ask. The hand calculations took some time due to matrix size, but we came to the same conclusions. The fact that we had the same answer made me skeptical when the program produced different results.
I've checked and double checked my inputs.
I am definitely . (dot-multiplying) the matrices for correct multiplication.
FullSimplify made no difference.
Neither have combinations with TrigReduce / expanding algebraically before simplifying.
I've taken indices from the final matrix and tryed to simplify them while isolated, to no avail, so the problem isn't due to the use of matrices.
I've also tried to multiply the first two matrices, simplify, and then multiply that with the third matrix; however, this produced the same results as before.
I thought Simplify automatically crossed into all levels of Heads, so I didn't need to worry about mapping, but even where zeros would be expected as outputs in the matrix, there are terms, and where we would expect terms, there are close answers, plus a host of sin and cosine terms that do not reduce.
Does anyone frequent any type of technique with Simplify to get more preferable results, in contrast to solely using Simplify?
If there are assumptions on parameter ranges you will want to feed them to Simplify. The following simple examples will indicate why this might be useful.
In[218]:= Simplify[a*Sqrt[1 - x^2] - Sqrt[a^2 - a^2*x^2]]
Out[218]= a Sqrt[1 - x^2] - Sqrt[-a^2 (-1 + x^2)]
In[219]:= Simplify[a*Sqrt[1 - x^2] - Sqrt[a^2 - a^2*x^2],
Assumptions -> a > 0]
Out[219]= 0
Assuming this and other responses miss the mark, if you could provide an example that in some way shows the possibly bad behavior, that would be very helpful. Disguise it howsoever necessary in order to hide proprietary features: bleach out watermarks, file down registration numbers, maybe dress it in a moustache.
Daniel Lichtblau
Wolfram Research
As you didn't give much details to chew on I can only give you a few tips:
Mma5 is pretty old. The current version is 8. If you have access to someone with 8 you might ask him to try it to see whether that makes a difference. You could also try WolframAlpha online (http://www.wolframalpha.com/), which also understands some (all?) Mma syntax.
Have you tried comparing your own and Mma's result numerically? Generate a Table of differences for various parameter values or use Plot. If the differences are negligable (use Chop to cut off small residuals) the results are probably equivalent.
Cheers -- Sjoerd