Carl Love

Carl Love

28050 Reputation

25 Badges

12 years, 335 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Matt C Anderson Okay, either Maple 13 or Maple's 2D Input doesn't allow ()-> if .... Change this section of code:

(()-> if M > MLim then "Memory"
           elif T-st > TLim then "Time"
           elif k > Count then "Length"
           else "No"
           end if
 )()

to

proc()
     if M > MLim then "Memory"
     elif T-st > TLim then "Time"
     elif k > Count then "Length"
     else "No"
     end if
end proc()

Don't forget the () at the end.

@paulinastm If you decrease the list length, then listM needs to be reinitialized before doing the shorter list. The easiest thing is to just begin your code with restart. That'll inilialize everything. To just initialize listM, do

listM:= 'listM';

The second form that I posted doesn't use listM, so it doesn't have this problem.

Here's an extension of the idea to arbitrary bases. Let me know if this won't run in your Maple 13. If so, I'll try to modify it.

Lychrel numbers, arbitrary base

https://en.wikipedia.org/wiki/Lychrel_number

Carl Love 2016-Oct-09

 

Based on http://www.mapleprimes.com/posts/206867-The-Growing-Sequence-Of-196 by Matt C Anderson.

 

Revnum:= proc(n::nonnegint, {base::And(posint, Not(1)):= 10})
description
     "Reverse the digits of a number in any base and"
     "return results as an ordinary integer."
;
local L,S;
     if base=10 then #Use faster StringTools method.
         parse(StringTools:-Reverse(sprintf("%d", n)))
     else
         L:= ListTools:-Reverse(convert(n, ':-base', base));
         convert(L, ':-base', base, base^nops(L))[]
     end if
end proc:

 

Lychrel:= proc(
     n::nonnegint,
     {Count::posint:= infinity}, #max list length to compute
     {TLim::positive:= 99}, #time limit (seconds)
     {MLim::posint:= 2^30}, #memory limit (bytes)
     {base::And(posint, Not(1)):= 10}
)
local
     st:= time(), T:= time(), M:= kernelopts(bytesalloc),
     N:= n, r:= Revnum(N, ':-base'= base),
     L:= Vector([N]),
     k
;
     for k from 2 to Count while r <> N and T-st <= TLim and M <= MLim do
          N:= r+N;
          L(k):= N;
          T:= time();
          M:= kernelopts(bytesalloc);
          r:= Revnum(N, ':-base'= base)
     end do;
     userinfo(
          1, Lychrel,
          (()-> if M > MLim then "Memory"
               elif T-st > TLim then "Time"
               elif k > Count then "Length"
               else "No"
               end if
          )(), "limit reached."
     );
     convert(L, list)
end proc:
  

infolevel[Lychrel]:= 1:


LS:= Lychrel(708, TLim= 10, base= 5):

Lychrel: Time limit reached.

nops(LS);

3202

ilog10(LS[-1]);

1009

 

Download Lychrel_number.mw

@Carl Love I thank you very much for doing the honorable thing by restoring the original Question.

@Carl Love I thank you very much for doing the honorable thing by restoring the original Question.

@nm I agree strongly about the need for more examples on the help pages. However, here on MaplePrimes, there have been hundreds, perhaps thousands, of Questions about third-order BVPs.

I will Answer your Question below, but you must promise to not ever edit or delete the Question.

@maria182 Please don't ever remove a Question after it has been Answered!

Please don't ever remove or substantially edit a Question that has already been Answered!

Note that the given Answer now makes no sense following your now-"sterilized" Question. I find this incredibly disrespectful to the person who took the time to Answer.

@taro The :- is not attached to the procedure header it comes after; rather, it's attached to the variable it comes before. It means that the following variable is a global variable even if it has a name that would ordinarily be overridden by a local variable or module export of the same name.

@maria182 Like I said above, you need to use exp(...) rather than e^....

t2 := inttrans:-invlaplace(exp(-s)/(s*(1-exp(-s))), s, t);

@maria182 Okay, here is how it can be done with linalg:

Wronsk:= (sol::list(algebraic), x::name)->
     linalg:-det(convert([seq(diff(sol, [x$k]), k= 0..nops(sol)-1)], matrix))
:
Wronsk([exp(x), cos(x), sin(x)], x);

I recommend that you inform your instructor "I saw on MaplePrimes that Maplesoft has been discouraging the use of linalg for many years. It has been replaced by other packages."

@cookee In the vast majority of cases, eval and subs give the same results; however, eval "knows" math and subs does not. So, it's safer to use eval for mathematical expressions and to reserve subs for low-level operations. See ?eval for some examples of when eval and subs are different.

@acer Yes, starting at 2 and using simply the "add x to g" approach leads to divergence to Float(infinity). But some other starting values converge. I think that one of the point of the exercise may be to learn that using this approach will never converge to the root near 2, but many starting values will converge to the other root.

@woodpeck If you need help implementing Acer's correction of your algorithm, I think that the best way is to simply add x to g inside the procedure.

Post an updated procedure when you have one. I have an improved procedure, but I want to see where you get with it before I post it.

First 380 381 382 383 384 385 386 Last Page 382 of 709