schzan

125 Reputation

5 Badges

7 years, 331 days

MaplePrimes Activity


These are questions asked by schzan

Could you please give an example of a code where I can add outputs from a loop to a list. I am using the break command to end the loop so I don't have the number of elements in advance.

Edit: I have also changed the title accordingly. There was more to this question, somehow which was omitted. I am writing it again. My code looks like below: 
if ...
do H[i]:=int(K);
...
... end do;
end if;

I want an array of H[i]'s. The loop breaks when a condition is met, so I can't create an array with a given dimension beforehand. Thank you.

Hi, I need to count elements in an indexed set. The below commands gives 3, as it doesn't take the powers into consideration (u[1,2,2]^3). Desired output is 5, meaning to count 1 three times.
       

with(ListTools):
>C:=x*u[]*u[1,2,2]^3*u[1,1,2];
>indx_set:=(`[]`@ op)~(indets(C, indexed));
indx_set := {[], [1, 1, 2], [1, 2, 2]}
>indx_set:=Flatten(convert(indx_set,list));
 indx_set := [1, 1, 2, 1, 2, 2]
>indx1:=[SearchAll(1,indx_set)];
[1, 2, 4]
>num:=nops(indx1);
3

Thanks

I have a list of 1's and 2's. Something like [1,1,1,2,2,2]. I want to remove 1 or 2 from the list (only once), without needing to mention at which place. The remove command removes all of the occurrences, I need something similar which remove the given element only once.
>L:[1,1,1,2]
>remove(has, L, 1)
[2]

I want the output to be [1,1,2]

Hi,

I have created a simple command which extracts the term containing the input. It works fine when I have more than one term in the expression but fails when there is the only one term in the expression. See below.

LT:= (expr, term)-> select(has, expr, term) #extract the operand containing the "term" in the given expression "expr"


>A:=t*u[1,1,1]*u[1,1,1,2]+2;
             

(input)>LT(A, u[1,1,1]);# works as expected, extracting the operand containing u[1,1,1]
 (output) t u[1, 1, 1] u[1, 1, 1, 2]

>op(A);#works, there are two operands
 t u[1, 1, 1] u[1, 1, 1, 2], 2

>A:=t*u[1,1,1]*u[1,1,1,2];
 

>LT(A, u[1,1,1]);#doesn't work, expected output is tu[1,1,1]u[1,1,1,2]
 u[1, 1, 1]

>op(A); doesn't work, expected output is tu[1,1,1]u[1,1,1,2]
t, u[1, 1, 1], u[1, 1, 1, 2]

Hi, I have created a procedure and it keeps giving the error "Error, reserved word `then` unexpected". What am I doing wrong?


Clasterms:=proc(P)
local L,a,b;
L:=(`[]`@ op)~(indets(P, indexed));
a:=Search(1,L[1]); b:=Search(2,L[1]);
 if a<>0 and b<>0 then print("mixed");
 elif a<>0 and b=0 then print("t-only");
 elif a=0 and b<> then print("x-only") ; end if;
 end proc:

Product: Maple 2021

1 2 3 4 Page 1 of 4