## Error in evaluating the function...

I am getting the following error while calculating function containing diffrential. Thankz in advance

 >
 (1)
 >
 >

## Why am I getting exprseq instead of array?...

Dear all,

I have a procedure in Maple. Input is a list. The procedure should add to a list the list [6,5,4,3,2,1] and find if there are repetitions in this new list. After, if there are repetitions, it should return [NO, initial list] and if there are no repetitions, it should find how many elements of the first 5 are larger than the 6th element and return this number together with the sorted list - [6,5,4,3,2,1] in reverse order. (It sounds a bit strange but it's actually computing some sheaf cohomologies).

The problem is, when there are repetitions, the procedure returns an array, and if there are no repetitions, it returns exprseq. I would like both to be an array. Where's the mistake?

For example, coh([4, 0, 0, 0, 0, 4]) is an array and coh([0, 0, 0, 0, 0, 12]) is exprseq.

Here's the text of the program:

restart;
with(combinat);
with(ListTools);
n:=6;

coh := proc (L::list)

Hm := Array([0, 0]);

b := 0;

M := L+[6, 5, 4, 3, 2, 1];

a := evalb(ListTools:-FindRepetitions(M) = []);

if a = false then Hm := Array(['NO', L]) else

for i to 5 do if M[i] < M[6] then b := b+1

end if;

end do;

K := sort(M);

KK := K+[-1, -2, -3, -4, -5, -6];

for j to n do

M[j] := KK[n-j+1]

end do;

Hm[1] := b;

Hm[2] := M;

print(Hm)

end if

end proc

## How to integrate a procedure properly?...

I recently encontered a very strange result.

Lets define the procedure:

```Fg := proc(x0,y0)
if (x0>=0)and(x0<=3) and (y0<=x0+2) and (y0>=x0-1) and (y0>=0) and (y0 <=3) then
return y0*(3-y0)*x0*(3-x0)*(x0+2-y0)*(y0-x0+1);
else
return 0;
end if:
end proc:```

The plot looks like needed:

`plot3d('Fg'(x,y), x=0..3, y=0..3);`

But integration returns weird result:

`evalf(Int('Fg'(x,y), [x=0..1, y=0..2.1]));`

7.888753239

`evalf(Int('Fg'(x,y), [x=0..1, y=0..2.2]));`

Error, (in evalf/int) when calling 'Fg'. Received: 'cannot determine if this expression is true or false: 0 <= x and x <= 3 and y <= x+2 and x-1 <= y and 0 <= y and y <= 3'

Hello,

I have two simple module's:

1) ------------------------------------------------------------------------

```Point := proc(xx::float,yy::float)     return module()         local x := xx,y := yy;         export ShowPoint,GetX,GetY;                  ShowPoint := proc()             printf("Point X,Y -> [%f,%f]",x,y);         end proc;```

```        GetX := proc()             return x;         end proc;                 GetY := proc()             return y;         end proc;         end module: end proc:```

2) ------------------------------------------------------------------------

```PointMath := module()     option package;       export `+`;          `+` := proc(a::Point(float,float),b::Point(float,float))         option overload;         Point(a:-GetX()+b:-GetX(),a:-GetY()+b:-GetY());     end proc; end module: ```

------------------------------------------------------------------------

Next I use first module:

`p1:=Point(1.2,1.4);`

`p2:=Point(1.0,2.0);`

Finally I want to add above two points:

`with(PointMath)`

`p2:=p1+p2`

`The results is:`

`p2:=p1+p2`

Why is not called operator '+' and two points are not added?

Best,

Rariusz

## Quick way to find duplicates in a matrix and set t...

I wrote some procedures in an older version of Maple to sort through a matrix and find repeated elements, and then set the matrix elements equal to one another. As an example, consider the matrix:

Due to its symmetric nature the upper triangular matrix is just the same as the lower triangular. i.e. the elements are equal: (2,1)=(1,2), (3,1)=(1,3) etc...

I have attached a minimal working example Maple script, which processes an input matrix, finds repeats and sets the elements equal to one another (e.g. [1,2]=[2,1], literally printing this) and saves the output to a file using a specific format for processing by another program. The matrix in the file is numeric but the actual matrices contain a lot of algebraic terms and can get quite large. This is where my procedures struggle as they take a very, very long time to process larger algebraic matrices to group the repeats. Is there a more Maple friendly way of going about this problem rather than these "archaic" procedures?

Here is the script:

duplicates_matrix_.mw

-Yeti

## Changing value of procedure parameter not allowed?...

I have a program:

Running abb(1,3) gives error: Error, (in abb) illegal use of a formal parameter

Might be a silly question: Is it not allowed? Do I have to define a local variable for b in order to change it?

## Float Infinity instead of integer...

Hi I have this code

``` psi:=proc(n,x);
(1/sqrt(sqrt(pi)*2^n*factorial(n))*exp(-x^2/2)*HermiteH(n,x))
end proc;
psi := proc(n, x) exp(-1/2*x^2)*HermiteH(n, x)/sqrt(sqrt(pi)*2^n*n!) end proc

psi2=proc(a,x);
psi(a,x):=(1/sqrt(sqrt(pi)*2^a*factorial(a))*exp(-x^2/2)*HermiteH(a,x))
end proc;
psi2 = (proc(a, x)
psi(a, x) := exp(-1/2*x^2)*HermiteH(a, x)/sqrt(sqrt(pi)*2^a*a!)

end proc)
for n from 0 to 2 do;
for a from 0 to 2 do;
result=proc(n,a);
result(n,a)=psi*psi2
end proc;
print(evalf(int(result(n,a),x=0..infinity)));
od;
od;```

it returns

Float(infinity) signum(result(0, 0))

Float(infinity) signum(result(0, 1))

Float(infinity) signum(result(0, 2))

Float(infinity) signum(result(1, 0))

Float(infinity) signum(result(1, 1))

Float(infinity) signum(result(1, 2))

Float(infinity) signum(result(2, 0))

Float(infinity) signum(result(2, 1))

Float(infinity) signum(result(2, 2))

I know the results for (0,0), (1,1) and (2,2) should be 1 and the rest should be 0.

Can anybody help fix this please

## Is it possible to call a procedure having inputs b...

I have a procedure, and I want to use it so many times whthin my equations, because all notation in my equations are in indicial format, it will be so nice if I can call the procedure in indicial form rather than paranthesis form.

Is there anyone knows how is it possible in Maple?

Rr is my procedure that accepts 2 inputs, So there is no problem to call it using Rr(x,y), I am trying to call it with Rr[x,y] (indicial form

)

Is it possible to do so in Maple? It will be so great to do so.

## How to define user defined function like Mattlab?...

I want to produce a user defined function in Maple and use it in my program like Matlab. My function in Matlab is as below:

function R=ff(i,m)
K=1;
Q= zeros( i );
for j=1:2:i
Q(j)=2*i-K;
K=4+K;
end
R=Q(m);

How to produce this function in Maple and use it in my program?

## How do I place a variable within a proceduere...

How can I produce the same output with something like alphadeg := alpharad * 180/Pi?

T := proc (p, q, R) alpharad = evalf[5](arccos((1/2)*(p^2+R^2-q^2)/(p*R))), alphadeg = 180*evalf[5](arccos((1/2)*(p^2+R^2-q^2)/(p*R)))/Pi end proc;
T(3, 4, 3.75);

Error, illegal use of an object as a name

Thanks! Les    AB59_20170205_Post.mw

## Writing a procedure for a matrix...

Hello I was trying to manipulate maple to write a procedure checking a matrix , say A with n rows and n columns. That matrix A given any row/column the sum of the entries for every row and column are equal. For example matrix [(-1,2)(2,-1)], every row and column in this matrix sums to 1. The entries in the matrix can be any real number.

## Vectorization of Symbolic Functions...

Maple provides efficient vectorization and automatic parallelization for many common operators. For example

`x -> 2*~x*~cos~(x*~x)`

But in my application it is common to want to create rather long vectorized operators starting from some complicated symbolic computations. Doing conversions by hand from symbolic expressions to element-wise operations is laborious and error prone.

As a very simple example consider that it is possible to obtain (almost) the same result as above by writing the following as a vectorized operation

`D(x->sin(x^2))~`

But there are at least two problems with this. First of all it is not nearly as efficient as the first operator and second, perhaps not unrelated, is that the datatype returned when applying this operator to a Vector/rtable of hardware floats (e.g. datatype=float[8]) becomes something  more general.

My question is how can I convert a complicated symbolic expression into an efficient numeric element-wise vector operation?

I have tried several different approaches but so far without success. In the case above for example it seemed natural to expect that the following derivative

`D(x->sin~(x^~2))`

would produce a vectorized result, but this is not the case. In another attempt I was unable to see how to perform substitions into an expression, e.g. like this

`unapply(subs(`*`=`*`~, cos=cos~, diff(sin(x),x)), x)`

I would be glad to receive suggestions and/or references to relevant documentation.

## Recovering un-returned local variables from a spec...

I would like to return local variable y (line 4 in showstat) in the attached dummy procedure (s1) without manually adding any comment inside the procedure s1. This procedure is a simple one and easy to copy paste/or change. When we have a long procedure, it is difficult to do so. I will always know the name of the local variable I want (say, y) and/or line number in showstat

Thanks

PS, I want to get y:=array(1..,2[(1)=x,2=zz])

 > restart;
 > s1:=proc(n,x) local y,xx,i,j,zz::array(1..n,1..n); for i from 1 to n do for j from 1 to n do zz[i,j]:=x[i]*(1+x[j]^2);od: od: y:=array(1..2,[(1)=x, (2)=zz]): for j from 1 to n do xx[i]:=zz[i,i]/(add(zz[i,j],j=1..n));od: 0; end proc;
 (1)
 > showstat(s1);
 s1 := proc(n, x) local y, xx, i, j, zz::array(1 .. n,1 .. n);    1   for i to n do    2     for j to n do    3       zz[i,j] := x[i]*(1+x[j]^2)          end do        end do;    4   y := array(1 .. 2,[1 = x, 2 = zz]);    5   for j to n do    6     xx[i] := zz[i,i]/add(zz[i,j],j = 1 .. n)        end do;    7   0 end proc
 > x0:=Vector(2,[1,1]);
 (2)
 > s1(2,x0);
 (3)
 >

## Runge Kutta method...

Hi guys, i'm working on a problem using the runge kutta method (4). The problem is, when I run this program, with the given starting values, it perfectly calculates every value of x[w-i] except x[0] and i have no idea why. Can anyone help? Thanks!