Adri van der Meer

Adri vanderMeer

1350 Reputation

18 Badges

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

My "website" consists of a Maple Manual in Dutch

MaplePrimes Activity

These are answers submitted by Adri van der Meer

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!

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:

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

Compare with:

Outp := proc (x::integer, y::integer, z::integer)
end proc:
a,b,c := Outp(3,4,2);
Error, ambiguous multiple assignment
a := Outp(3,4,2);

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

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

local 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:

local result:
result := x+3*y;
result := result, y+z;
end proc;

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);

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.

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.

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.

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} ); 

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

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.

simplify(F, {epsilon^2=1});


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] )

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 do
for j from 2 to 18 do
 NewLambda[i,j] := (Lambda[i,i]-Lambda[j,j])/2;
end do
end do;


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