Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The other Answers seem to be not seeing the forest because of the trees. They suffer from unneeded specificity and are a bit difficult to generalize. Suppose that you have a set (or list) of prefixes P and a set (or list) of suffixes S. Then what you want is a function (indexing or suffixing in this case) double-mapped over the setwise exponentiation S^P (i.e., the set of all functions (in tuple form) from P to S). It can be generated by

P:= [CPC, SIZE, SH]:  S:= [h, m, l]:
seq(rtable((1..nops(S)) $ nops(P), ()-> index~(P, S[[args]]), order= C_order));

The order= C_order only affects the overall order of the sequence of tuples and may be omitted if you don't care about that.

The above generates indexed names (i.e., of the form A[B]) rather than suffixed names (of the form A__B). If you'd rather have suffixed names, then change index[*1] to ((p,s)-> p||__||s). But note that programmatically generated suffixed names are always global, no matter how they are created and regardless of the lexicality of their components.

[*1]Indeed, index could be replaced by any function whose domain is P x S. The canonical choice would be `[]` (the sequence-to-list operator). Whatever function is used, it gets mapped over every tuple of S^P (which I referred to above as double-mapping over S^P itself). It's important to realize that the fundamental combinatorial structure being generated is S^P, and the double-mapped function is simply an afterthought.

Use 4 distinct exact numeric values of (values of rand() should work well). Evaluate each of the Qs at a different t value, then use regular solve on the resulting system of 4 equations. If you have extraordinarily bad luck, there might not be a unique solution due to  duplication of an equation. In that case, just use another set of values.

Another one-liner, completely different from John's, is

add~([entries(ListTools:-Classify(content, [op(p)]), nolist)]);

Suppose that you have a list or set of equations such as [x(t) = 5, y(t) = 10] and that list or set is assigned to E. Then all that you need to do is 

eval([x(t), y(t)], E),

and you get [5, 10].

Usually what is done is to form one equation for each coordinate dimension and then solve the resulting system of nonvector equations. If you elaborate or give a small example, I can say more.

Here's a module for simplifying any collection of any real intervals (expressed with RealRange and/or as discrete sets of points) combined arbitrarily with any of the set operators `union`, `intersect`, and/or `minus`.

SimplifyIntervals:= module()
local
   x::identical(x),
   ModuleLoad:= ()->
      TypeTools:-AddType( #recursive type: put base cases 1st!
         'RealIntervals', 
         Or(
            specfunc(RealRange),
            set(realcons), 
            'specop'('RealIntervals', {`intersect`, `union`, `minus`})
         )
      ),
   Deconstruct:= (IN::RealIntervals)->
      if IN::specfunc(RealRange) then convert(x::IN, relation)
      elif IN::set(realcons) then Or((x =~ IN)[])
      elif IN::`minus` then And(thisproc(op(1,IN)), Not(thisproc(op(2,IN))))
      else `if`(IN::`union`, Or, And)(map(thisproc, [op(IN)])[]) 
      fi,   
   ModuleApply:= proc(IN::RealIntervals)
   local pts, ints;
      (pts,ints):= selectremove(type, [solve(Deconstruct(IN), x)], realcons);
      `union`(sort(ints, key= (p-> `if`(op(1,p)::realcons, op(1,p), op([1,1],p))))[])
  	  union {pts[]}       
   end proc
;
   ModuleLoad()
end module:

Example:

IN:= (((RealRange(-infinity, 1) intersect RealRange(Open(-1), infinity))
   minus RealRange(-1/3, 1/3)) minus {0}) union {-2,2};

SimplifyIntervals(IN);

(I tried to make a procedure `simplify/intervals`, but simplify just ignored it when I used simplify(IN, intervals). Any idea why?)

 

You seem to have ignored the z column of your matrix A. So your 3 planes can't be correct if they're supposed to represent A.<x,y,z> = 0.

Here's a way that does the computations and plots the planes and the line of intersection all in one command:

A := <1, 1, -2 | 3, 4, -7| -5, -8, 13>;
plots:-display([
   plot3d(
      #Solve each row for z using matrix operations:
      [seq(-A[..,..2].<x,y>/~A[..,3])], x= -8..8, y= -20..20, 
      plotlist= true, color= [blue, red, green], style= surface, transparency= [.3,.3,.1]
   ),
   #The line:
   plots:-spacecurve(LinearAlgebra:-NullSpace(A)[]*t, t= -3..3, color= red, thickness= 3)
],
   axes= frame, tickmarks= [[0=0]$3], labels= [x,y,z]
);

 LinearAlgebra:-NullSpace is essentially the same as your LinearSolve command, but returns the result in a more convenient form (a basis).

You had the right idea; there are only some minor syntax corrections needed. Try this:

restart:

Eqset:= {diff(x(t),t)=(-x(t)+x(t)^2-3*x(t)*y(t)), diff(y(t),t)=(-y(t)-5*x(t)*y(t)+y(t)^2)};
#The above line is your code, unaltered.

V:= x^2/2 + y^2/2;  #I removed the braces { }.
dV:= expand(eval(diff(V(t),t), Eqset)); #derivative wrt t (b/c Maple knows the symbolic chain rules)

plot3d(dV,x=-0.00005..0.00005,y=-0.00005..0.00005); #Your command, unaltered, now works.

 

(Today I learned... that plot3d allows functional variables such as x(t) and y(t) to be treated as scalars x and y.  Many Maple commands allow this, but I wasn't aware of its use in plotting commands.)

As you've suggested, it's theoretically possible to find some inequality involving x and t that'll guarantee that the other part is at most 10. But, why bother, unless you have some other reason for finding that inequality? You can just use min to explicitly set the maximum at 10, like this:

Y:= (x,t)-> min(10, -(11*sin(t/2+1.145)-10)*((x-37)^2)+(-3.5*sin(t)+ 1));

I think that it's best to make it a function of both x and t. If you insist on it being a function of alone, then just remove the t from the left side of the arrow. 

Note that it's not necessary (or desirable) to use unapply to create this function because there's no meaningful evaluation possible before values are given for x or t. But neither is it incorrect to use unapply. It's just a matter of using a tool that's much larger than what's required to do the job.

It should be done with fsolve rather than solve because fsolve gives you more control over the range. Like this:

restart;
Digits := 32;
t0 := 1;
eq := 1-w*v^2-2*v*exp(-t/v);
equ := eval(eq, v = -t/ln(u));
#Lines above are exactly your code.

us:= subs(_E= eval(equ, t= t0), w= _W, _W-> fsolve(_E, u= -infinity..1));
vs := w-> -t0/ln(us(w));
plot(vs, 0 .. 10, labels= [w, ``], view= 0..1);

Do

plot([rhs(f), Y, Y= 0..10], labels= [typeset(epsilon/`2`/Pi), Y]);

Using plot rather than implicitplot is usually preferable when either the equation can be solved for one of its variables or its two variables can be expressed as functions of a third variable.

I can't work with your equations because of the reason that I just wrote in the Reply above. But apparently you already have some means of solving them (which command?). So, just add one more equation that expresses that you want the sum of the variables to be 32. That can be done simply as follows. Suppose that the list of equations in your worksheet is named Eqns. Then do

Con:= add(indets(Eqns, name)) = 32: #Constraint
Sys:= [Eqns[], Con]:

And proceed to solve Sys by whatever means you were using to solve Eqns.

Of course, this idea is worthless if your unspecified solver reduces all constants (such as the 32) modulo 2.

Some evaluations, such as simple arithmetic with explicitly numeric operands, are always done regardless of the encapsulation with -> or proc ... end proc or '...'. These are called automatic simplifications. That's what's happening with 2+3. If you have a specific need to prevent such an evaluation, please ask, because there are some specialized techniques available.

Except for the few usually innocuous automatic simplifications, the expression on the right side of the -> is not evaluated at the time that the arrow expression is created. In the vast, vast majority of cases of automatic simplification, its use does not change the final result. Obviously such is the case with 2+3.

Regarding your second question: If you want to evaluate first, then turn the result into an arrow expression, the standard command for that is unapply:

unapply(int(1,y), x);

Note that x-> e and proc(x) e end proc are semantically equivalent for any symbol x and expression e (which likely (but not necessarily) depends on x).

The usual way is to run in "batch mode"; that is, run command-line Maple with its input coming from and its output going to files specified on the command line that initiates the Maple session. See ?Maple for details of command-line options.

Here's a way to do it, but I suspect that there's an easier way. Suppose that MkL, and have already been defined. Then do 

Z:= Matrix(M$2): #All zero
T:= 
   Matrix((2^(k-1))$2, (i,j)-> `if`(i=j, L, F), shape= triangular[upper]) + 
   Matrix((2^(k-1))$2, (i,j)-> `if`(i=j, 0, Z), shape= triangular[lower])
:
P:= Matrix((2^(k-1)*M)$2, (i,j)-> T[iquo(i-1,M,'r')+1, iquo(j-1,M,'c')+1][r+1, c+1])/2^k;

The difference between my Answer and Tom's is that I've deconstructed the blocks so that the result is a "flat" Matrix.

First 155 156 157 158 159 160 161 Last Page 157 of 395