Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Consider creating a Matrix with an initializer function, like this:

v:= Matrix((5,9), (i,j)-> F(V__dot[i], DD[j]));

where F represents any operation that you want. In your case, I think that you want

v:= Matrix((5,9), (i,j)-> V__dot[i]/(Pi/4)/DD[j]^2);

While entering the command, you should use Shift-Enter to get to the next line. Only use Enter when the command is complete. Thus, in the code portions of most worksheets, Shift-Enter would be more commonly used than Enter.

Download DirectSearch from the Maple Applications Center. I gave a more-complete Answer to your simultaneous Question on StackOverflow.

I'm on my mobile right now. I'll give your problem a more-thorough look when I get to a real computer. 

Use the solve command. See ?solve. If the equation is too complicated to solve symbolically, you can still get a numeric solution with fsolve if the equation has no symbolic parameters. 

A slightly ugly solution is to use $ in prefix form:

Array(`$`(1..3, n));

But, then again, everything is ugly in 2-D input, so maybe it doesn't matter. You should use 1-D input. To change your default format to 1-D input: Using the menus, do

  • Tools => Options => Display => Input display => Maple Notation
  • Interface => Default format for new worksheets => Worksheet
  • Apply Globally.

Good Question; Vote Up.

I don't have a great amount of experience with the Units package, but my experience so far has been that trying to assign units to symbolic entities (such as your t and x(t)) is clunky at best and ultimately frustrating and perhaps not worth the effort. That being said, here's what I managed to come up with for your situation:

restart:
with(Units:-Standard):
x:= t-> 'procname'(t)*Unit('m'):
t:= ()-> 'procname'*Unit('s'):
#Note that diff is overloaded/replaced by the with(Units:-Standard).
diff(x(t),t());

This produces precisely the result that you requested, but note that the second argument to diff is t() rather than t.

The first proc procedure in your code is not assigned to anything. It needs to be assigned to p, as in p:= proc(....

Fixing this error will get you the first three plots. Another error occurs after that, and I haven't figured that one out yet.

Good Question; Vote up.

Here's a simple recursive conversion of tables to sets followed by Maple's normal equality check (which works well for sets but not for tables). The conversion to sets is different from that performed by convert(..., set) because it includes the indices.

TableToSet:= T-> `if`(T::table, {op(2, thisproc~(T))[]}, T):
TablesEqual:= (A::table, B::table)-> 
   evalb(TableToSet(A) = TableToSet(B))
:

 

The following performs your test for any number of variables. The variables are passed in a list as the second argument.

MyTest:= (
   F::list(algebraic), 
   V::depends(And(list(name), satisfies(V-> nops(V)=nops(F))))
)->
   andmap(
      k-> ormap(depends, [F[..k-1][], F[k+1..][]], V[k]),  
      {$1..nops(V)}
   )
:

(The code has been simplified by Boolean algebra since its original posting.)

I strongly recommend that you stop referring to the objects that you're working with as "monomials". By doing so, you cause confusion for all mathematically educated people reading these posts, and you end up making yourself sound foolish. It causes confusion because monomial is a precisely defined mathematical term, and your objects don't fit the definition.


restart:

MyTypes:= {algebraic, ''[algebraic $ _], 'Vector(_, algebraic)''' $ _= 2..3}:
TypeTools:-AddType(MyType, MyTypes):

MyProc:= proc(
     A::depends(
          And(
               MyType, 
               satisfies(A-> andmap(T-> A::T implies B::T and C::T, MyTypes))
          )
     ),
     B, C   
)
     if A::algebraic then
          #option 1
     elif A::[algebraic $ 2] then
          #option 2
     elif A::[algebraic $ 3] then
          #option 3
     elif A::'Vector(2, algebraic)' then
          #option 4
     else #A::'Vector(3, algebraic)'
          #option 5
     end if
end proc:

Here's a method that's much simpler than the module method that I already posted as an Answer. This method puts all of the illegal-input checking into the procedure header (what's also called the "argument processing").

If you do want to put this procdure into a module, then you'll need to be careful how you handle the user-defined type. It needs to be global, and thus handled in a similar fashion to the user-defined types in the module that I already posted (which avoids clobbering any previously defined global of the same name).

 

You've run up against yet another syntax difference between the 2-D input format and the 1-D input format. In 1-D input (which Tom Leslie is using), the range operator can be either two or three dots: A..B means the same thing as A...B, regardless of whether A and/or B are symbols or numbers. But in 2-D input (which you are using), if B is an integer, then the third dot is interpreted as a decimal point, so 10...50 becomes 10 .. 0.50. Since the final value is less than the starting value, seq correctly returns the null sequence, which appears to you as if Maple "doesn't do anything."

My primary advice is to just use 1-D input (aka Maple Input). The 2-D input has many subtle and annoying nuances like this. If you want to continue using 2-D input, then always use two dots rather than three for the range operator.

Here is a complete implementation as a module. Please let me know if you have any questions. If you want to save this to a library, it may need a minor change: MyTypes might need to be global. If it doesn't work when saved to a library, let me know.

restart:

MyModule:= module()
uses TT= TypeTools;
global _T1, _T2L, _T2V, _T3L, _T3V, _MyType;
local
     MyTypes:= {_T1, _T2L, _T2V, _T3L, _T3V},
     AllMyTypes:= MyTypes union {_MyType},

     ModuleLoad:= proc()
     local
          g, #iterator over module globals
          e
     ;
          #op([2,6], ...) of a module is its globals.
          for g in op([2,6], thismodule) do
               e:= eval(g);
               if g <> e and e in AllMyTypes then
                    error "The name %1 must be globally available.", g
               end if
          end do;
          TT:-AddType(_T1, algebraic);
          TT:-AddType(_T2V, 'Vector(2, algebraic)');
          TT:-AddType(_T2L, [algebraic $ 2]);
          TT:-AddType(_T3V, 'Vector(3, algebraic)');
          TT:-AddType(_T3L, [algebraic $ 3]);
          TT:-AddType(_MyType, MyTypes)
     end proc,

     ModuleUnload:= proc()
     local T;
          for T in AllMyTypes do TT:-RemoveType(T) end do
     end proc,

     MyDispatch:= overload([
          proc(A::_T1, B, C)
          option overload;
          local r:= "A, B, C are T1."; #unnecessary; just an example.
               #statements to process this type
          end proc,

          proc(A::_T2L, B, C)
          option overload;
          local r:= "A, B, C are T2L.";
               #
          end proc,

          proc(A::_T2V, B, C)
          option overload;
          local r:= "A, B, C are T2V.";
               #
          end proc,

          proc(A::_T3L, B, C)
          option overload;
          local r:= "A, B, C are T3L.";
               #         
          end proc,

          proc(A, B, C)
          local r:= "A, B, C are T3V.";
               #
          end proc
     ]),

     ModuleApply:= proc(
          A::And(
               _MyType,
               satisfies(A-> andmap(T-> A::T implies B::T and C::T, MyTypes))
          ),
          B::_MyType, C::_MyType
     )
          MyDispatch(args)
     end proc
;
     ModuleLoad()    
end module:

#Example usage:                                          
MyModule(x,y,z);

 

The elementwise operator ~ can be used like zip, but for arbitrary arity. In this way it is more powerful than any single spelled out command in Maple such as map, zip, map2, etc. Observe:

Vals:= [x= [1,2,3], y= [4,5,6], z= [7,8,9]]:
f~(eval([x,y,z], Vals)[]);

     [f(1, 4, 7), f(2, 5, 8), f(3, 6, 9)]

I think that you'll be able on your own to apply this to your situation. However, if you need further assistance with that, just ask.

I agree with all that Tom said. In addition, if you're trying to use color to precisely encode numeric information in a plot, then having transparency and directional lighting (directional lighting is a default) makes that numeric information very difficult to read. So, in that case, I'd use this:

plots:-display(
     plottools:-cuboid([0,0,0],[1,1,1]),
     transparency= 0,
     colorscheme= ["xyzcoloring", (x,y,z)-> x^2 + y^2 - z^2],
     lightmodel= NONE
);

If your use of color is primarily aesthetic, then ignore this Answer.

Use add, not sum, because add allows a step value for the index. Also, your exponent is the inverse of what it should be. It should be (i-1)/2. So, the corrected command is

add(2*q*cos(2*i*x)/(i*Pi)*(-1)^((i-1)/2), i= 1..35, 2);

First 206 207 208 209 210 211 212 Last Page 208 of 395