dharr

Dr. David Harrington

8355 Reputation

22 Badges

21 years, 9 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr

@arashghgood I'm confused about what you want. You talked about residues - do you want to do a contour integration? if so of what function - Q, deq? - which contour? upper half plane? That can probably be done.

How exactly was the plot in c made? I think by numerical solution of the same differential equation? if you want to exactly replicate that then it would be helpful to know the method, stepsize, hardware precision, exact initial conditions.

Perhaps a step back to tell us where is problem came from and what you want out of it would be helpful.

@arashghgood You can try stiff methods other than the default resenbrock one, e.g. lsode. You could put Digits higher for more accuracy, but it will get very slow. In combination with the transformation method to add a small imaginary part you may get closer to what you want. I don't really understand what you are expecting - near a sigularity inaccuracy seems inevitable.

@arashghgood Stiff method seems to work here, without transformation. (just plotting real and imm parts of Q)

Download ODE.mw

Edit: at least for the second case. For the first, it varies depending on the exact values of the ic.

@arashghgood  The dchange can be done more simply by 

ode2:=PDEtools:-dchange({K=x+a},ode,[x],params=[a]):

and still using Q. Result is the same. Hard to understand any discrepancy.

@arashghgood Perhaps you can reformulate, e.g., K=x+a with x real (including changing the derivatives appropriately). PDEtools:-dchange can do a change of variables - see attached. But ignoring singularities seems risky.

Download ODE.mw

@Thomas Dean Here's my interpretation. The wikipedia page you cited makes clear  is the notation for a ring, modulo n. So for the additive group modulo n, the order is n, but for the multiplicative group, 0 is excluded and the order is n-1. So your ord=12, mod 13, is Z/13Z.

This is how you used it in your original post.

@Thomas Dean Your original table didn't have 0 in the multiplicative case, so I emulated that without thinking too much about it. The Wikipedia page talks about integers 0..n-1 mod n. So that may be part of it. But notice that you are doing ord=12, which is mod 13, which is prime. If you change ord to 11, so mod 12, you get an error message, since the default is to check that it is a group. Try other values, some work and some don't.

@Thomas Dean 

restart

with(GroupTheory)

Matrix has to have the entries coded as 1..4

v := [1, -1, I, -I]; M := Matrix(4, 4, proc (i, j) options operator, arrow; eval(v[i]*v[j], `~`[`=`](v, [`$`(1 .. 4)])) end proc)

v := [1, -1, I, -I]

Matrix(%id = 36893490351220485524)

G := CayleyTableGroup(M)

_m2203734088608

CayleyTable(G)

Array(%id = 36893490351220474092)

lbl := proc (i) options operator, arrow; v[i] end proc

proc (i) options operator, arrow; v[i] end proc

DrawCayleyTable(G, labels = lbl)

NULL

Download Group.mw

I tried to find this out a while ago, but concluded it wasn't possible. You can use FileTools:-ListDirectory to find a list of all *.mw files in the interface(worksheetdir) directory, but there seems not to be a simple way to find which one is running. I suppose there must be some system-dependent system calls to figure out which programs are running.

@mmcdara Much, much simpler than mine!

@gharouce So, to be clear, you never want the actual numbers out, but just to evaluate some special algebra in which e^2=1, e^3=e etc for one specific variable e in an expression? That is easy to do if your expression is a polynomial in e, but requires more work if you want it to work for, say, e/sin(e^2). Here's the polynomial case:

restart

evalpm:=proc(expr,var)
  local p,sum,power,term,terms;
  p:=collect(expr,var);
  if not type(p,polynom(anything,var)) then error "%1 not polynomial in %2",expr,var end if;
  if nops(p)=1 then terms:=[p] else terms:=[op(p)] end if;
  sum:=0;
  for term in terms do
    power:=diff(term,var)/term*var;
    sum:=sum+ifelse(power::even,coeff(term,var,power),var*coeff(term,var,power));
  end do;
  sum;
end proc:

q := X^3*Y+X^2*Z+X; q2 := (e+1)^3

X^3*Y+X^2*Z+X

(e+1)^3

evalpm(q2, e)

4+4*e

evalpm(q, X)

X*Y+X+Z

NULL

Download Xn.mw

For the more general case

evalpm:=proc(expr,var)
        local p,pwr;
        p:=collect(expr,var);
        evalindets(p,`^`,
            proc(pwr) local res; 
              if op(1,pwr)=var then
                if op(2,pwr)::even then
                    res:=1
                elif op(2,pwr)::odd then
                    res:=var
                else
                    res:=pwr
                end if
              else
                res:=pwr;
              end if;
               res;
             end proc
        );
   end proc:

 

@gharouce You can only set X to one value at a time. But you can do something like this:

s:=X^3*Y + X^2*Z + X;
eval(s,X=1);
eval(s,X=-1);

or you can do something like this:

solve({s=X^3*Y + X^2*Z + X,X^2=1},{s,X});

which gives the two possibilities

@Ronan I originally had ModuleUnload remove the types, thinking that when I did unwith() the module would unload and the types would be removed. But the types still existed - unwith only gets rid of the global names (exports) the package created. The ModuleUnload procedure "is called when the module is destroyed. A module is destroyed either when it is no longer accessible and is garbage collected, or when Maple exits".

So my conclusion is that it isn't really useful.

@Ronan Here's a working example:

restart

packagedir:=interface(worksheetdir);

"C:\Users\dharr\Desktop"

MyThings:=module()
  option package;
  export mysqr,mysqrt;
  local ModuleLoad;
  uses TT=TypeTools;

  ModuleLoad:=proc()
   TT:-AddType(mytype,{identical(x),posint});
  end proc;

  mysqr:=proc(x::mytype);
    x^2
  end proc;

  mysqrt:=proc(x::mytype);
    sqrt(2)
  end proc;
 
end module:
 

libfile:=cat(packagedir, "/MyThings.mla");
march( 'create', libfile, 20 );
savelib('MyThings',libfile);

"C:\Users\dharr\Desktop/MyThings.mla"

 

NULL

Download MyThings.mw

 

restart;

packagedir:=interface(worksheetdir);

"C:\Users\dharr\Desktop"

libname:=libname,packagedir:

with(MyThings);

[mysqr, mysqrt]

mysqr(y);

Error, invalid input: MyThings:-mysqr expects its 1st argument, x, to be of type mytype, but received y

mysqrt(2.5);

Error, invalid input: MyThings:-mysqrt expects its 1st argument, x, to be of type mytype, but received 2.5

mysqr(x);

x^2

NULL

 

Download test.mw

First 50 51 52 53 54 55 56 Last Page 52 of 87