Adri vanderMeer

## 18 Badges

15 years, 5 days
University of Twente (retired)
Enschede, Netherlands

My "website" consists of a Maple Manual in Dutch

## Manipulating inert Sums...

To be fair,

Sum(i, i=0..N) - Sum(i, i=0..N, i!=k);

should, obviously return: if k≤N then k, else zero.

There are some possibilities to manipulate inert Sums.
In your example:

`S1 := Sum(i, i=0..N):S2 := Sum(i, i=0..k-1) + Sum(i, i=k+1..N):combine( S1-S2, 'range' ) assuming k < N;`

gives you (almost) the desired answer, but, of course as an unevaluated Sum!

## Interesting difference...

Markiyan Hirnyk's procedure can be used if you only want to see the three values.
If you need the results for further calculation, the procedure must build a sequence (or list, or vector) of the values:

`Outp:=proc(x,y,z)local result:result := x^4+3;result := result, x+3*y;result := result, y+zend proc:a,b,c := Outp(3,4,2);                        a, b, c := 84, 15, 6`

Compare with:

`Outp := proc (x::integer, y::integer, z::integer)print(x^4+3);print(x+3*y);print(y+z)end proc:Outp(3,4,2);                               84                               15                               6a,b,c := Outp(3,4,2);                               84                               15                               6Error, ambiguous multiple assignmenta := Outp(3,4,2);                               84                               15                               6                             a:=`

The result is NULL, i.e. an empty sequence.

## The use of proc...

Case 1 and Question 3:
It is always clever to declare local variables as local; the returnType is only meaningful for debugging purposes:

`ReturnInteger:=proc(x,y,z)local g:g:=3+y;x^2-g;end proc;`

Case 2: a sequence of outputs:
The output of a procedure is the last executed statement, or an explicit return value. In yor example you wish "several values" that is: a sequence of values. In your example you can do for instance:

```Outp:=proc(x,y,z)
local result:
result := x+3*y;
result := result, y+z;
end proc;
```

## Sum or sum?...

Mind that Sum (capital S) is the inert form. The function value() can be used to calculate the value:

`Sum( i, i=0..N ): %=value(%);`

In your example (typing errors(?) removed):

`sum(1, i=0..N) - sum(1, i=k..N);`

## Documentation...

I suppose that ?proc will be a good starting point. More detailed information in the (online) programming guide

Procedures can be nested. You must declare the name of an inner procedure as a local variable in the outer procedure.

## Vector equation...

If v is a vector, so

`v := Vector( [54*a+3*b-c+d, 32*a-c+d, 96*b-69*c+85*d, 6*a+9*b+3*c+9*d] ):`

then you must convert v to a list or set, and solve:

`solve ( convert( v, set ), {a,b,c,d} );`

(only trivial solution)
If there is no right hand side in an expression, then it is automatically set to zero.

## Table of lists...

Of course you can build r as a table of lists:

```for i to 80 do
r[i] := [];  # initialization
# fill the list r[i]
for j to n(i) do r[i] := [ op(r[i], f(j) ] end do
end do:```

or, a little trickier: as a list of lists:

`r := []:for i to 80 do  Q := NULL:  # empty sequence  for j to n(i) do Q := Q, f(j) end do:  r := [ op(r), [Q] ]end do:`

Here is n(i) the number of elements in list r[i].
If all the lists r[i] have the same length, you can consider to create r as a Matrix.

## There are even more than two different a...

u and v are polynomials in α and β. so there are several (real) zeros.
Try for example

```s1 := fsolve({u,v});
s2 := fsolve({u,v}, {alpha,beta}, avoid={s1} );
s3 := fsolve({u,v}, {alpha,beta}, avoid={s1,s2} );
```

## Do not use 2-D Math notation for input d...

Tools → Options → Display → Input Display: Maple Notation.

## Initialization...

Apparently you want r to be a ?list , but by the initialization

`r[] := [];`

you make r a ?table (with one empty index and one empty entry). Try

`r := [];`

to start with.

## Use siderels in simplify...

```F:=randpoly(epsilon,degree=1000,dense):
simplify(F, {epsilon^2=1});```

?simplify/siderels

## Make a list of Matrices...

```with(LinearAlgebra):
Ck := [ seq( RandomMatrix(4,4), i=1..6 ) ];```

makes a list of six 4×4-matrices, Ck[1], ... Ck[6].

If you have a similar list P of matrices, a matrix product is

`Ck[i] . P[j];`

(not Ck[i] * P[j] )

## What is NewLambda supposed tot be?...

Your program is calculating several values for the variable NewLambda, and in each step is is overwritten by the new value.
Perhaps you mean a Matrix?

`NewLambda := Matrix(18,18):for i from 1 to 17 dofor j from 2 to 18 do NewLambda[i,j] := (Lambda[i,i]-Lambda[j,j])/2;end doend do;NewLambda;`

## more aliases...

`alias( f = f(x+y, z+y),    f[xx] = D[1, 1](f)(x+y, z+y),    f[xy] = D[1, 2](f)(x+y, z+y),    f[yy] = D[2,2](f)(x+y, z+y) ,    f[x] = D[1](f)(x+y, z+y),    f[y] = D[2](f)(x+y, z+y) );`
 First 22 23 24 25 26 27 Page 24 of 27
﻿