Preben Alsholm

13728 Reputation

22 Badges

20 years, 241 days

MaplePrimes Activity


These are answers submitted by Preben Alsholm

The subprocedure handling Heaviside in ztrans is `ztrans/zrule`['Heaviside'].

And that one checks if No has type 'integer'. Since No (with or without assumptions) is not an integer, ztrans returns unevaluated.

(You mistyped the type check :: , but since it doesn't have an effect, it doesn't matter).


If the procedure is changed to something like the following, it seems to work:

`ztrans/zrule`['Heaviside']:=proc(f,stepexp,n,z) option `Copyright (c) 1995 by Waterloo Maple Inc. All rights reserved.`;
local i,s,r;
if type(stepexp,'linear'(n)) then
  s:=coeff(stepexp,n,1);
  r:=-coeff(stepexp,n,0)/s;
  if type(r,integer) or hasassumptions(r) then if is(0<=r) then `ztrans/ZT`(f,n,z) - (sum(subs(n=i,f)/z^i,i=0..r - 1)) else `ztrans/ZT`(f,n,z) end if
else '`ztrans/ZT`'(Heaviside(stepexp)*f,n,z) end if
else
  '`ztrans/ZT`'(Heaviside(stepexp)*f,n,z)
end if
end proc;

The changes are in this part:

if type(r,integer) or hasassumptions(r) then if is(0<=r) ......

c:=table():
a:=[5,6,7]:
b:=[4,3,9]:
counter1:=1:
counter2:=1:
for i in a do
  for j in b do
    c[counter1,counter2]:=i+j:
    counter2:=counter2+1
  end do:
counter2:=1; 
counter1:=counter1+1
end do:

eval(c);


It is rather curious, indeed. And disturbing!

Apparently by saving the module in the second example mp:-mult evaluates to the global variable mult, which has not been defined to be anything.

If inside the procedure f2, mult is replaced by mp:-mult, then both versions work, also after saving.

 

However, if you create a Maple archive and save your packages there, both seem to work fine:

restart;
#mkdir("F:/temp");
march(create,"F:/temp/mp.mla",10);
restart;
mp1:= module()
export mult, f2; option package;
mult:=proc(v) 3*v end proc;
f2 :=proc(v) mult(v); end proc;
end module;
savelibname:="F:/temp/mp.mla";
savelib(mp1);
restart;
libname := libname, "F:/temp";

with(mp1);
f2(5);
mult(4);

restart;
mp2:= module() export f2, mult; option package;
mult:=proc(v) 3*v end proc;
f2 :=proc(v) mult(v) end proc;
end module;

savelibname:="F:/temp/mp.mla";
savelib(mp2);

restart;
libname := "F:/temp",libname;

with(mp2);
f2(5);
mult(4);

The time spent in converting a given nice and simple answer into something else is (I find) usually rather frustrating, and maybe not worth the effort.

I did the following, but notice in particular the simplify(..., symbolic) and the convert(...., arccosh):

res:=simplify(int(9/sqrt(81*x^2-4),x));
convert(res,arccosh);
simplify(%,symbolic);
res2:=radnormal(%,rationalized) ;
plot([res,res2],x=2/9..10);

The answer is in terms of arccosh, but not in the form you wished.

If you change the Export to pdf format setting to "Export using shapes for greater fidelity" then the export to pdf seems to work fine (I used the letters you provided above).

(Tools/Options/Export)polishTEST3.pdf

Here is another idea.

The procedure _RemoveMyAssignments unassigns all user assigned names, but because of the leading underscore, it doesn't unassign the name _RemoveMyAssignments.

If the procedure is placed in a library, it won't be unassigned either. See the help for 'anames'.

_RemoveMyAssignments:=proc() local L;
L:=map(convert,[anames('user')],string);
unassign(op(map(parse,L)))
end proc:


p:=plot(sin);
tr1:=87;
t[6]:=14;
M:=Matrix(3,3,(i,j)->i+j);
_RemoveMyAssignments();
p,tr1,t[6],M;
eval(t);
eval(_RemoveMyAssignments);

The responses from select and remove ought not be unexpected.

In the help page it says:

"The select function selects the operands of the expression e which satisfy the Boolean-valued procedure f, and creates a new object of the same type as e. Those operands for which f does not return true are discarded in the newly created object."

(emphasis added).

The type of ccc (i.e. sin(x)) is function (which in Maple means unevaluated calll to a function). The function in question is obtained by doing
op(0, ccc);

i.e. it is the 0'th operand. For a list this would be 'list'. For a sum it would be `+`, etc. 

The operands of f(x,y,z) are x, y, z (numbered 1, 2, 3).

So

op(sin(x));

just returns x.

select(has, sin(x), x);

will select among the operands those for which has(...., x) is true, in this case the argument x. After that an object of the same type as the original is returned, thus the result is sin(x).

remove(has, sin(x), x);

will act accordingly. There will be no argument left, so the result will be sin(), however if you evaluate that further (by merely doing %;) you get an error message because sin does not accept no arguments.

If your list is a list of lists you can do as follows using scan:

restart;
A:=[[1,2,3],[4,5,6]];

Matrix(A);

#Same as:

Matrix(A,scan=[rectangular,rows]);

#But now different:
Matrix(A,scan=[rectangular,columns]);

You can change Fortran order to C order as follows, but it doesn't affect the dimensions:

restart;
A:=[1,2,3,4,5,6];
M:=Matrix(3,2,A);
MC:=Matrix(M,order=C_order);
lprint(MC);

The same happens in Maple 14, but as suggested in the help page you can change Normalizer from the default normal to e.g. radnormal:

Normalizer:=radnormal;
IsSimilar(A,A,output=['C']):
simplify(%);

After attempting PDEtools[dcoeffs], it seems that actually this works also on a pde, not just an ode (the equation eq2 is defined below):

dd:=convert(indets(eq2,specfunc(anything,diff)) union {f(x,y)},list):

coeffs(eq2,dd,'terms');
               1 + r + y, 5 + 4 y + z, 1, 3 + 4 x
terms;
          d            d  / d  / d         \\   d  / d         \
f(x, y), --- f(x, y), --- |--- |--- f(x, y)||, --- |--- f(x, y)|
          dx           dx \ dx \ dx        //   dy \ dx        /

Notice that as described in the help page for coeffs there is a 1-1 correspondence between the output from coeffs and the contents of 'terms'.

If your input is a polynomial in the indeterminate and its derivatives then you can use dcoeffs from the PDEtools package:

eq1:=simplify(( (3+4*x)*diff(f(x), `$`(x, 2)))+(5+4*y+z)*(diff(f(x), x))+(1+r+y)*f(x)):
PDEtools[dcoeffs](eq1,f(x));
                3 + 4 x, 5 + 4 y + z, 1 + r + y

#The help page describes ODE's and although at first it seems to work on a pde:

eq2:=simplify(diff(f(x,y),x,x,x)+(3+4*x)*diff(f(x,y), x,y)+(5+4*y+z)*diff(f(x,y), x)+(1+r+y)*f(x,y)):
PDEtools[dcoeffs](eq2,f(x,y));
               3 + 4 x, 1, 5 + 4 y + z, 1 + r + y

#You notice that the order of the coefficients is surprising.

Using collect w.r.t. diff could be useful:

collect(eq1,diff,factor);

collect(eq2,diff,factor);

The simplest:

diff(f(a*y),y);

#Defining a new function g as g(y) = f(a*y):

g:=unapply(f(a*y),y);
D(g);
D(g)(r);

# Using dchange from the PDEtools package is relevant in a more complicated context, e.g. if you like to nondimensionalize a differential equation:

restart;
eq:=diff(f(x),x)=b*f(x)^2+c*f(x);
PDEtools:-dchange({f(x)=q*g(y),x=a*y},eq,[y,g]);

Go to the Program Files/Maple 14/ETC. Copy the files in that folder and put them where you got your tex-file.

 

Instead of using `` as suggested by pagan you could use the inert operator &* in the following way.

restart;

#Defining FactorOut:
FactorOut:=proc(u::algebraic,d::algebraic,f::{procedure,name}:=expand,{force::boolean:=false}) local u1;
     u1:=u/d;
     if force then d&*f(u1) else d*f(u1) end if
end proc:

#Extending value:
`value/&*`:=proc() `*`(args) end proc:

F:=1 + Q*x^2 + P*x^3;
FactorOut(F,x^2/L^2);
FactorOut(F,x^2/L^2,force);
FactorOut(F,6,force);
value(%);

By default f is the procedure expand, but the optional third argument could be another procedure.

Similarly I have used an extended version of value for inert matrix multiplication &. in linear algebra.

You want Maple to say that x = 2 when there is no solution? Why not x = 3?

eq:=(x-1)/(2*(x-2)) = 2/(x^2-4)+1/2:
normal((lhs-rhs)(eq))=0;
normal(eq*(x-2));
solve(%,x);

normal(eq*(x-3));
solve(%,x);

Here are a few ways.

eq:=diff(z(t),t,t)=-sin(z(t))-cos(t):

#Output default = procedurelist:

sol:=dsolve({eq,z(0)=0,D(z)(0)=0},numeric):
sol(7);
subs(sol(7),z(t));
#Make a function:
X:=s->rhs(sol(s)[2]);
X(7);
#Alternative method
X:=s->subs(sol(s),z(t));
X(7);
#My preferred output is listprocedure:
sol2:=dsolve({eq,z(0)=0,D(z)(0)=0},numeric,output=listprocedure);
X:=subs(sol2,z(t));
X(7);
plot(X,0...50);

First 150 151 152 153 154 155 156 Last Page 152 of 160