MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

This challenge is an application of java.math that allows unlimited precision calculations. The primary reference sites are Java Math, Java BigDecimal, and Java BigInteger.

The usage of BigDecimal function multiply will be essential.

Java Math tutorial: (Simplified summary that is believed correct)

vd-decimal value, vstr-string, vi-integer value xBD=java.math.BigDecimal(vd); % valid vd,vstr,vi creates xBD a BigDecimal variable import java.math.*; % simplifies statements xBD=BigDecimal(vstr);

xmultiplyzBD=xBD.multiply(BigDecimal(z)); % multiply input requires BD type

To convert java to string of unlimited length can be achieved via java toString or Matlab char

xstr=toString(xBD) or xstr=char(xBD)

**Input:** N [1< N < 1000]

**Output:** Y (char variable of Y=N! or a BigDecimal variable)

**Related Challenges:**

2. nchoosek_large (full precision) 2. Next Prime 3. factor_large 4. Factorial

20 correct solutions
3 incorrect solutions

Last solution submitted on Jul 16, 2015

1 Comment

Alfonso Nieto-Castanon
on 5 Sep 2013

longer code but considerably faster non-java solution (0.05s for 1000!)

1 player likes this solution

1 Comment

Richard Zapor
on 4 Sep 2013

Solution 9 sees Alfonso step up and provide a concise method in the Best Factorial Solution in the Non-Java Category.

3 Comments

James
on 3 Sep 2013

We don't need no steenkin' Java. :-)

Richard Zapor
on 3 Sep 2013

Solution 6 is an expertly crafted non-java solution. Complexity Level- Outstanding. Time for 1000! vs Java ?

James
on 4 Sep 2013

The convolution method is considerably slower than Java, which is what you would expect. For the java vs. non-java solutions:
Java - Elapsed time is 0.138064 seconds.
This case - Elapsed time is 1.039240 seconds.

1 Comment