Mathematica doesn't work with big numbers - wolfram-mathematica

I'm pretty new to mathematica, and for example, when I type: "= 56 * 22" it gives me the result, but when I try to to compute the product of bigger numbers, mathematica says that "no interpretations available". For example when I type: "= 32187382163872163652187352187352187538217538652138585287432185218735873512853872153875213875218735218765382175387521321398765219387621987369218763982176398721693872169387621938762193876219873621986398213 * 672136873621873621873682176387216387216487632876438274687326487326874632876487632874687564328763287648732684753287463287483274587325487532874587324576532765324476532645873268732687463287458325871587621876218763872168736218736218736876218763876432767632979328463".
Is there any limit in mathematica for the input size? What I'm doing wrong? I use mathematica 8. I was googling and I didn't find anybody experiencing something similar or any number limit for mathematica.
Thanks in advance

Related

Converting Logarithmic Bases and Approximating Exponents

I'm studying for an algorithms final. There are some sample questions that I'd like to know how to solve. No calculators are permitted, and the methods used are more relevant to computer science than algebra. I'll try to be as specific as possible, because researching this has only led me to change-of-base formulas that require a calculator.
What is (approximately) the Log base 2 of 130,000,000?
What is (approximately) the Log base 4 of 1,000,000?
I'd also appreciate it if someone would explain base conversions without a calculator to me. Thank you. If this post is inappropriate, I'll remove it without hesitation.
Edit: Answers delivered in log(x)/log(r) will not be considered correct. Thank you.
What you need to do is make your own table during the exam.
2, 4, 8, 32, 64, 128, 256,512, 1024, ....
Find the power of 2 that is closest to the value you looking for. If you are asked for Log2(1000), you'd see the closest is 1024 (2**10): Ans: 10.
log base r (x) may be evaluated as log(x)/log(r)

Confirmation required: gnuplot does not change intital fit values

after using gnuplot for years and experiencing many user-related issues, I thought I'd finally know how to fit a function to a dataset.
Today I tried to fit a simple
y = m * x² + b
function. However, gnuplot did not change my 'm' value. It does change 'b' to the correct value however.
I have my dataset uploaded and here is my gnuplot script with which I'm trying to fit, maybe someone can reproduce this on his machine and confirm, that it is not a fault of my computer but some kind of faulty code in the script, or it may even be a bug (I highly doubt that).
set xtics 0.000001
set format x '%10.1E'
set xrange [0:2E-07]
#fit
f(x)=a*(x**2)+b
a=380812
b=1
fit [0:2E-07] f(x) 'GDAMitte1.txt' using ($1+7.6E-06):2 via a,b
plot 'GDAMitte1.txt' using ($1+7.6E-06):2, f(x)
I've pasted the dataset here: http://www.heypasteit.com/clip/29LU
I'd be very thankful for an answer to that, even if it's just a confirmation, that it doesn't fit on your machine as well. Thank you.
Btw: The initial value I've set is pretty much the one it has to be after the fit, but it's not as exact of course. Should be good enough though for gnuplot to get where to go to.
This is because two parameters are of greatly different magnitude, check help fit tips.
You should replace the function with one that has a prefactor built in:
f(x) = a *1e5 * (x**2)+b
a=3.8 # instead of 380000
b=1
fit ....
From gnuplot version 5.0 on, gnuplot by default internally prescales all parameters, so this problem with calculating the residuals should no longer occur for any function, provided your initial values are not off too much.

Image processing (Matlab): index exceeds the matrix dimensions

well, I am new to matlab programming and I have been battling on the indexing issues. I am currently working on image processing which so far drive me crazy. anyways, lets jump to the questions.
I have the following code
perm=randperm(size(X,2));
CX=X(:,perm(1:nclus));
I tried to run the code but it triggers an error saying " Index exceeds the matrix dimensions. To my humble knowledge I think it is because the (:,perm(1:nclus)) is higher than the matrix dimensions. I would like to know how can i solve this problem.
Note that X: is the input points in the columns
nclus: number of clusters.
I highly appreciate if you guys clarify to me the error cause and the possible solution for it.
Thank you
Sami
Guessing that you just want to get nclus random columns from a 2 dimensional matrix X, try this:
perm=randperm(size(X,2));
CX=X(:,perm<=nclus);
The error that you experience should not come from X being called with too many dimensions, it is probably because the dimensions of perm are exceeded. Try running this line by line:
perm = randperm(size(X,2)); %Should be ok
idx = perm(1:nclus); %Probably fails
X(:,idx)

MATLAB script to generate reports of rounding errors in algorithms

I am interested in use or created an script to get error rounding reports in algorithms.
I hope the script or something similar is already done...
I think this would be usefull for digital electronic system design because sometimes it´s neccesary to study how would be the accuracy error depending of the number of decimal places that are considered in the design.
This script would work with 3 elements, the algorithm code, the input, and the output.
This script would show the error line by line of the algorithm code.
It would modify the algorith code with some command like roundn and compare the error of the output.
I would define the error as
Errorrounding = Output(without rounding) - Output round
For instance I have the next algorithm
calculation1 = input*constan1 + constan2 %line 1 of the algorithm
output = exp(calculation1) %line 2 of the algorithm
Where 'input' is the input of n elements vector and 'output' is the output and 'constan1' and 'constan2' are constants.
n is the number of elements of the input vector
So, I would put my algorithm in the script and it generated in a automatic way the next algorithm:
input_round = roundn(input,-1*mdec)
calculation1 = input*constant1+constant2*ones(1,n)
calculation1_round = roundn(calculation1,-1*mdec)
output=exp(calculation1_round)
output_round= roundn(output,-1*mdec)
where mdec is the number of decimal places to consider.
Finally the script give the next message
The rounding error at line 1 is #Errorrounding_calculation1
Where '#Errorrounding' would be the result of the next operation Errorrounding_calculation1 = calculation1 - calculation1_round
The rounding error at line 2 is #Errorrounding_output
Where 'Errorrounding_output' would be the result of the next operation Errorrounding_output = output - output_round
Does anyone know if there is something similar already done, or Matlab provides a solution to deal with some issues related?
Thank you.
First point: I suggest reading What Every Computer Scientist Should Know About Floating-Point Arithmetic by David Goldberg. It should illuminate a lot of issues regarding floating-point computations that will help you understand more of the intricacies of the problem you are considering.
Second point: I think the problem you are considering is a lot more complicated than you realize. You are interested in the error introduced into a calculation due to the reduced precision from rounding. What you don't realize is that these errors will propagate through your computations. Consider your example:
output = input*C1 + C2
If each of the three operands is a double-precision floating-point number, they will each have some round-off error in their precision. A bound on this round-off error can be found using the function EPS, which tells you the distance from one double-precision number to the next largest one. For example, a bound on the relative error of the representation of input will be 0.5*eps(input), or halfway between it and the next largest double-precision number. We can therefore estimate some errors bounds on the three operands as follows:
err_input = 0.5.*eps(input); %# Maximum round-off error for input
err_C1 = 0.5.*eps(C1); %# Maximum round-off error for C1
err_C2 = 0.5.*eps(C2); %# Maximum round-off error for C2
Note that these errors could be positive or negative, since the true number may have been rounded up or down to represent it as a double-precision value. Now, notice what happens when we estimate the true value of the operands before they were rounded-off by adding these errors to them, then perform the calculation for output:
output = (input+err_input)*(C1+err_C1) + C2+err_C2
%# ...and after reordering terms
output = input*C1 + C2 + err_input*C1 + err_C1*input + err_input*err_C1 + err_C2
%# ^-----------^ ^-----------------------------------------------------^
%# | |
%# rounded computation difference
You can see from this that the precision round-off of the three operands before performing the calculation could change the output we get by as much as difference. In addition, there will be another source of round-off error when the value output is rounded off to represent it as a double-precision value.
So, you can see how it's quite a bit more complicated than you thought to adequately estimate the errors introduced by precision round-off.
This is more of an extended comment than an answer:
I'm voting to close this on the grounds that it isn't a well-formed question. It sort of expresses a hope or wish that there exists some type of program which would be interesting or useful to you. I suggest that you revise the question to, well, to be a question.
You propose to write a Matlab program to analyse the numerical errors in other Matlab programs. I would not use Matlab for this. I'd probably use Mathematica, which offers more sophisticated structural operations on strings (such as program source text), symbolic computation, and arbitrary precision arithmetic. One of the limitations of Matlab for what you propose is that Matlab, like all other computer implementations of real arithmetic, suffers rounding errors. There are other languages which you might choose too.
What you propose is quite difficult, and would probably require a longer answer than most SOers, including this one, would be happy to contemplate writing. Happily for you, other people have written books on the subject, I suggest you start with this one by NJ Higham. You might also want to investigate matters such as interval arithmetic.
Good luck.

Query on Lambda calculus

Continuing on exercises in book Lambda Calculus, the question is as follows:
Suppose a symbol of the λ-calculus
alphabet is always 0.5cm wide. Write
down a λ-term with length less than 20
cm having a normal form with length at
least (10^10)^10 lightyear. The speed
of light is c = 3 * (10^10) cm/sec.
I have absolutely no idea as to what needs to be done in this question. Can anyone please give me some pointers to help understand the question and what needs to be done here? Please do not solve or mention the final answer.
Hoping for a reply.
Regards,
darkie
Not knowing anything about lambda calculus, I understand the question as following:
You have to write a λ-term in less than 20 cm, where a symbol is 0.5cm, meaning you are allowed less than 40 symbols. This λ-term should expand to a normal form with the length of at least (10^10)^10 = 10^100 lightyears, which results in (10^100)*2*3*(10^10)*24*60*60 symbols. Basically a very long recursive function.
Here's another hint: in lambda calculus, the typical way to represent an integer is by its Church encoding, which is a unary representation. So if you convert the distances into numbers, one thing that would do the trick would be a small function which, when applied to a small number, terminates and produces a very large number.

Resources