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

@Muhammad Usman Please post the new re-executed worksheet. I'm sure that evalm was part of the problem, but it may not be the whole problem.

@asa12 Sorry, I don't know physics at that level, and I can't offer you the least bit of help.

@rhcp I just finished this code anyway. Try this. Certainly it works for the case at hand plus some more-general cases. Do you need it more general? Do you need anything explained?

restart;
Nstates:= 3:
x:= Vector[row](Nstates, i-> i-1);
q:= Vector[row](Nstates, i-> i-1); 

u:= (x,q)-> p*min(x,q) - w*q;
#`add` works better than `sum` in this context (finite,
#definite, nonsymbolic addition):
U:= (x,q)-> add(u(x[i], q), i= 1..Nstates)/Nstates;

#z:= w/p;

Ineqs:= 
   [seq(
      eval[recurse](solve(U(x,q[i]) > U(x,q[i+1]), w)[], [p= 1, w= z*p]),
      i= 1..Nstates-1 
   )]
;
ReverseIneq:= (ineq::{`<`, `<=`})-> `if`(ineq::`<`, `>=`, `>`)(op(ineq)):
 
`q*`:= unapply(
   piecewise(
      Ineqs[1] and z <= 1, q[1],
      seq([Ineqs[i] and ReverseIneq(Ineqs[i-1]), q[i]][], i= 2..Nstates-1),
      0 <= z and ReverseIneq(Ineqs[Nstates-1]), q[Nstates]
   ),
   z
 );
'`q*`'(z) = `q*`(z);

 

 

@rhcp You wrote:

  • I thought there might be an intuitive way to rearrange the inequalities for w/p, then substitute this expression with z, and finally translate all inequalities into one piecewise representation.

It can be done, but I don't know how intuitive you'll find it. One roadblock is that these transformations are only valid for p > 0, right? Many Maple commands will accept an assuming clause; that is, one can append assuming p > 0 to the command and it will make use of that. But the solve command makes this difficult, although not impossible.

  • Is there then one command with which I could merge these intervals into one piecewise expression programmatically, or do i have to rely on the 'manual way' by simply writing it in text as I would do in LaTeX?

What you state are two extremes, and the truth is somewhere in between. On the one hand, it is never necessary to do it the manual way, and I generally recommend avoiding that at all costs. On the other hand, I don't think that it's possible with one command unless I write that command for you, which I'm trying to do.

The data structure piecewise is perhaps the most awkward to work with of all of Maple's standard data structures, and solve is perhaps the most awkward of all the standard commands. Nonetheless, I'm sure that I can put something together for you, probably in an hour or two. But it'll require some effort on your part to understand how it works.

 

 

@rhcp What terminology don't you know? I will explain.

I assume that the current problem is only a "toy" problem and that you want to set this up to handle larger and/or more-general problems. That is why I asked about the order.

It seems that without loss of generality, I can substitute z= w and p= 1. This is by far the easiest way to get z = w/p. Is that okay?

@asa12 I know nothing about ket and only a miniscule amount about the Physics package.

But I see that you've used i for the complex unit sqrt(-1). In Maple, this is usually capital I, but you can change it to another symbol.

@asa12 When a Maple response uses a variable of the form _Zn, which wasn't specified by the user, the assumption is that the variable is integer.

You've used LinearAlgebra for years, so why do you revert to linalg here? LinearAlgebra does have the MatrixExponential command.

@rhcp In the case that there is a conflict between these options, do you want the piecewise sorted ascending with respect to q*, descending with respect to z, or something else? The standard way in Maple is ascending with respect to z with the lower bounds not explicitly stated, though it's easy to present in an other-than-standard format. And do you want the piecewise presented in terms of w/p or z?

@rhcp You'll need to upload and post your worksheet because what you've shown in your Question is too small for me to read, even at the maximum magnification.

@tomleslie As types, radical and anything^fraction are equivalent, and radical is more to the point; so, vote up.

Here are a few corrections, including returning 1 if the probability of the condition is 0 and returning FAIL if the unsimplified results from Probability give FAIL/FAIL.

Conditioned:= proc(
   event::{relation, set(relation)},
   cond::{relation, set(relation)}, 
   rv::
      {name= RandomVariable &under Statistics:-RandomVariable,
       {set,list}(name= RandomVariable &under Statistics:-RandomVariable)
      }
) 
uses St= Statistics;
local 
   Event:= `if`(not event::set, {event}, event),
   Cond:= `if`(not cond::set, {cond}, cond),
   RV:= `if`(not rv::{set,list}, [rv], [rv[]]),
   d 
;
   if nargs=3 then 
      (Event,Cond):= 
         subs(lhs~(RV)=~ St:-RandomVariable~(rhs~(RV)), [Event, Cond])[]
   fi;
   d:= St:-Probability(Cond);
   if d = 0 then 1
   elif d = FAIL then FAIL
   #union used rather than intersection because Probability considers a set
   #of relations to represent the intersection of the corresponding events. 
   else St:-Probability(Event union Cond) / d
   fi
end proc:

Probability cannot handle the multivariable situations that you want to consider. If you're only interested in spaces that are the product independent uniform distributions, I may be able to code something from scratch.

@BigBugBuzz I haven't seen any mention of an actual bug in Probability in this thread, just limitations. If presented with a problem too complex, it may return the symbol FAIL. Some of the more-complex problems may be easily done by numeric integration if an exact answer is not required. Do you require exact solutions?

@inteli 

You can select columns 3 and 6, for example, by M1B[.., [3,6]]. You can select rows 5 and 1, with 5 being on top, by M1B[[5,1], ..].

@Markiyan Hirnyk 

I am in Amsterdam, many thousands of kilometers from my home. I will fix the FAIL issues when I have access to a computer, which is likely Friday. I need a different power adapter for my computer due to the different electricity here, I've ordered it, and it's coming Friday.

I already said that FAIL/FAIL incorrectly simplifies to 1 and that I'd fix it when I had access to a computer. That you would mention it again in just a few hours is what we call "flogging a dead horse."

First 320 321 322 323 324 325 326 Last Page 322 of 708