In Mathematica I could easily evaluate factorials, including large ones like 1000!
But in Matlab I can only evaluate up to 170!, because any number beyond that is greater than realmax, so the program gives me back infinity.
In another topic a user suggested that I should use the symbolic toolbox in this case.
My question is, how I do that? Is there any alternative way?

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 2 Sep 2014

5 votes

syms n
subs(n*factorial(n-1),1000)

4 commentaires

Getting the following in between numbers:
\\\r\n
Walter Roberson
Walter Roberson le 18 Fév 2018
You can char() the result and delete those \ and r and n characters.
The characters are caused by a bug in the Symbolic Toolbox in your release.
Venkata
Venkata le 18 Juin 2024
@Andrei Bobrov Any way to calculte beyond 1000?
Piyush Kumar
Piyush Kumar le 18 Juin 2024
Modifié(e) : Piyush Kumar le 18 Juin 2024
@Venkata, just found this link of a similar question. It has one answer by James. It suggests to use "vpi". I have tried that to calculate factorial of 1000 -
>> factorial(vpi(1000))
ans =
40238726007709377354370243392300398571937486421071463254379991042993
851239862902059204420848696940480047998861019719605863166687299480855890
132382966994459099742450408707375991882362772718873251977950595099527612
087497546249704360141827809464649629105639388743788648733711918104582578
364784997701247663288983595573543251318532395846307555740911426241747434
934755342864657661166779739666882029120737914385371958824980812686783837
455973174613608537953452422158659320192809087829730843139284440328123155
861103697680135730421616874760967587134831202547858932076716913244842623
613141250878020800026168315102734182797770478463586817016436502415369139
828126481021309276124489635992870511496497541990934222156683257208082133
318611681155361583654698404670897560290095053761647584772842188967964624
494516076535340819890138544248798495995331910172335555660213945039973628
075013783761530712776192684903435262520001588853514733161170210396817592
151090778801939317811419454525722386554146106289218796022383897147608850
627686296714667469756291123408243920816015378088989396451826324367161676
217916890977991190375403127462228998800519544441428201218736174599264295
658174662830295557029902432415318161721046583203678690611726015878352075
151628422554026517048330422614397428693306169089796848259012545832716822
645806652676995865268227280707578139185817888965220816434834482599326604
336766017699961283186078838615027946595513115655203609398818061213855860
030143569452722420634463179746059468257310379008402443243846565724501440
282188525247093519062092902313649327349756551395872055965422874977401141
334696271542284586237738753823048386568897646192738381490014076731044664
025989949022222176590433990188601856652648506179970235619389701786004081
188972991831102117122984590164192106888438712185564612496079872290851929
681937238864261483965738229112312502418664935314397013742853192664987533
721894069428143411852015801412334482801505139969429015348307764456909907
315243327828826986460278986432113908350621709500259738986355427719674282
224875758676575234422020757363056949882508796892816275384886339690995982
628095612145099487170124451646126037902930912088908694202851064018215439
945715680594187274899809425474217358240106367740459574178516082923013535
808184009699637252423056085590370062427124341690900415369010593398383577
793941097002775347200000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000
You can try for values beyond 1000.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by