Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@acer Could you explain the differences between Physics:-Fundiff(..., f(t))Physics:-diff(..., f(t)), and perhaps also Physics:-Fundiff(e, f) where f(t) occurs in and "naked" f does not appear in e as an independent variable?

@primogen Given that Physics:-diff does what you want, I'm sorry that I led you astray about Physics:-Fundiff in the other thread. It's totally my fault. I don't have much knowledge of the Physics package.

@Rouben Rostamian  Your Answer corresponds closely to what I learned in PDEs classes in graduate school; although, at the time, I had great difficulty "swallowing" the deviation from standard (or perhaps I should say classical) mathematics. I believe, vaguely, that I was told that all can be made mathematically rigorous by replacing zeroes in certain places with constructions built up from

Z:= x-> piecewise(x=0, 0, exp(-1/x^2)),

a function that is very similar to 0 for real (all orders of its derivatives at equal 0). If you delve into the complex numbers, the arguments don't hold up---a fact that still unsettles me.

I can't add anything mathematically to the three Answers by PDE experts already given. I just want to point out some elementary issues with your syntax. Indeed, I was about to say that it was impossible to unambiguously interpret what you typed, but three experts have interpreted it the same way, so I guess that it's possible. However, neither Maple nor any other mathematical software that I am aware of will see it that way.

1. All functions require parentheses to separate the function's name from its arguments, even if those parentheses wouldn't be used in standard typeset mathematical printing. So, you need cos(y)sin(y)sin(x)sinh(Pi), etc.

2. Uppercase and lowercase letters are distinct symbols, with no inherent connection in meaning. In this case, most human readers, including me, can see that your U and u mean the same thing. However, Maple will not see it that way.

3. Specific to Maple: Follow Rouben's example on how to enter derivatives of unknown functions: diff(u(x,y), x, x), etc.

@Rohith Try this code. There are only two differences: 

1. I commented out the ModuleUnload procedure, which is the procedure that removes the added types when the module gets garbage  collected. My guess is that that garbage collection is happening at inappropriate times due to a bug in Maple 2018.

2. I added protection for Expression so that it can't inadvertently be globally assigned to.

termExtract:= module()
uses TT= TypeTools, IN= InertForm;
local
   TryRemoveType:= (T::name)-> if TT:-Exists(T) then TT:-RemoveType(T) else fi,
   TryAddType:= (TH::(name= anything))-> (TryRemoveType(lhs(TH)), TT:-AddType(op(TH))),
   AddedTypes,
   (* Removed 23-Oct-2018 because types were mysteriously missing.
   ModuleUnload:= proc()
      (TryRemoveType@lhs)~(AddedTypes);
      :-`print/Expression`:= ':-`print/Expression`';
      NULL
   end proc,
   *)
   ModuleLoad:= proc()
      protect(Expression);
      TryAddType~(
         (AddedTypes:= [
            #With recursive types, put base cases at beginning to avoid infinite loops!
            'Atomic'=     'Or'('name', 'numeric', 'InertRecip', 'Negated'),
            'InertRecip'= 1 %/ 'Atomic',
            'Negated'=    (-1) &* 'Atomic',
            'AssocOps'=   'And'('specfunc'({`%+`, `%*`}), 'patfunc'('anything'$4)),
            'Operators'=  'specfunc'('Atomic', {`%+`, `%*`, `%/`, `%^`}),
            'Expression'=     'And'('Operators', 'Not'('InertRecip'), 2 &under nops)
         ])
      );
      :-`print/Expression`:= Expression-> value({args});
      NULL
   end proc,

   #Associative operators with > 2 operands are regrouped pairwise.
   Fold:= E-> subsindets(E, AssocOps, OP-> foldl(op(0,OP), op(OP))),
 
   ModuleApply:= (E::string)-> 'Expression'(indets(Fold(IN:-Parse(E)), 'Expression')[])
;
   ModuleLoad()
end module:

 

Since your equation doesn't contain an undifferentiated y(x), it is equivalent to this first-order equation:

diff(Y(x),x)+(A/x+B/x^2+C)*Y(x)+D4*Y(x)^2/x+E*Y(x)^3+F/x+G/x^2+H/x^3 = 0

where Y(x) = diff(y(x),x) and D4= D. (I changed your to D4 to avoid conflict with the D, Maple's differential operator.) This simplification doesn't make dsolve able to solve the reduced equation symbolically, but you certainly can't call it "high order" anymore.

Would you be interested in a purely numeric solution?

@sand15 Since the OP said "discret uniform distribution", I interpreted the function as 1/(k+1), which I thought was the only reasonable interpretation under those circumstances. Since my code didn't directly use the function, I didn't comment on the typo (just as I didn't comment on "discrete" being misspelled "discret").

The method that you presented in your Answer is both correct and useful for arbitrary discrete distributions[*1]. I have no problem with that. 

The point of my Answer is that for the specific and very common case of a discrete uniform distribution whose support is a range of integers, it is easy and the usual Maple coding practice to generate samples simply by using rand[*2]. It may be possible to improve the efficiency a little by instead using RandomTools:-Generate. I think that the efficiency is reduced by using ProbabilityTable and Statistics:-Sample; however, I haven't tested that in Maple 2018, which may have introduced a substantial efficiency improvement for Sample used with custom distributions.

[*1]Actually, I did just notice a problem with your method, which I just put as a Reply to your Answer.

[*2]It is not as widely known as it should be that since the output of rand(m..n) for numeric m and n is a procedure rather than the random number itself, the following is an inefficient way to generate a sample of size N because it recreates that procedure for each number generated:
seq(rand(0...k)(), i= 1..N).
I didn't comment on this issue in my Answer (although I probably should have). Although my code handles this issue efficiently, it does so at the expense of some perhaps-unexpected complexity of the code.

@vv Those are great questions, and I was just about to ask similar questions myself, in a separate Question, as I just came up with the code in question today. The documentation of thismodule is very thin, and what I know is by expermentation. Surely its relationship to its parent module is much more complex than thisproc's relationship to its parent procedure; and surely its relationship to the :- and [] operators is more complex than other modules' relationship to those operators. And it usually can't be replaced by the named module that it refers to.

@shimaa sadk 

There is a simpler way that I didn't see before:

#Remove n randomly selected elements from list L:
RemoveRand:= (L::list, n::nonnegint)-> combinat:-randcomb(L, nops(L)-n); 

And here's an example of its use:

#Construct a random list:
R:= rand(-99..99):
L9:= sort(['R()'$9]);

        L9 := [-83, -82, -73, -44, -10, -4, 62, 80, 97]

#Remove 3 randomly chosen elements from it:
L6:= RemoveRand(L9, 3);

               L6 := [-83, -44, -10, -4, 62, 80]

 

@Carl Love I just posted a complete solution to this problem in the Posts section. My solution was elaborate enough, generic enough, and didactic enough that it seemed to warrant being put in Posts.

@eggoodaire Let me know if you need help putting those commands together. Please post if you work it out on your own!

Your Question doesn't make much sense to me, because if a list is sorted, and you remove some elements, then the remaining elements are still sorted! And why would you eliminate 0 elements 19 times?

@torabi Yes, I easily achieved that plot. I thought that you'd not be happy with the singularity, so I just said that there were "convergence issues". Since the interval is much smaller than a single period of your voltage function, it seems strange to me.

@primogen The derivative wrt a function can be computed by Physics:-Fundiff:

Physics:-Fundiff~(SimplifiedMassMatrixDot, theta[1](t))

Why are you using [diff] instead of diff? Not that there's anything wrong with [diff], but I'm curious Why do you find the the extra brackets useful? 

@yonasmibi Thanks. Both your transcription of the formulas into your code and my interpretation of your transcription were correct. We were simply confused because in English the word "rabbit" begins with letter R, which is used instead for the foxes in your model.

I will post a corrected procedure shortly.

@primogen When you save a Maple worksheet, it pretty much only saves what is needed to display what's on your screen. It doesn't save anything that you've obscured with the output-suppressing colon. So, you usually can't send that worksheet to someone else and say "See, that command didn't work. Please diagnose what I'm doing wrong," unless it's something trivial that can be diagnosed just by looking at the input.

Check out Acer's worksheet also. He achieved a substantial simplification of your Matrix using commands combine and simplify

First 299 300 301 302 303 304 305 Last Page 301 of 708