Vrbatim

118 Reputation

9 Badges

10 years, 265 days

MaplePrimes Activity


These are answers submitted by Vrbatim

> A;                         
[1, I, 2, 2 + I, 3 I]

> Criterium := x -> type(x,complex) and not type(x,rational);
Criterium := x -> type(x, complex) and not type(x, rational)

> Criterium( A[1] );
false

> Criterium( A[2] );
true

> select( Criterium, A );
[I, 2 + I, 3 I]
 
You may also find this helpful:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=type%2fcomplex

Does this suffice?

> A := LinearAlgebra[RandomMatrix](3,7);
[ 33 57 -76 -32 27 99 92]
[ ]
A := [-98 27 -72 -74 8 29 -31]
[ ]
[-77 -93 -2 -4 69 44 67]

> LinearAlgebra[Dimension](A);
3, 7

 
[1] http://www.maplesoft.com/support/help/Maple/view.aspx?path=LinearAlgebra/Dimension

First, a comment about your code:

+ "diz" and "diz2" will ultimately be given the values  diz := eta(17,17) and diz2 := eta( 18, 18 ) since each new iteration will overwrite the value from before. The same is true for "nod" for the same reason.

Second, I'm not quite sure I what it is you are trying to do. But, generally speaking two serially (one after the other) placed FOR loops do something quite different then nested (one contained in the other) FOR loops. See( http://en.wikipedia.org/wiki/Nested_loop_join ).

For this particular example, consider the following:

#The first loop will take i = 1, 2, 3
> for i from 1 to 3 do
> print( i );
> end do;
1

2

3
#The second will take j = 1, 2, 3

> for j from 1 to 3 do
> print( j );
> end do;
1

2

3

#Here, for the nested loop version, for i=1 j will take ALL vaules 1,2,3. 
This is repeated for i = 2 and 3 as well (for a total of 6 prints): 
> for i from 1 to 3 do
> for j from 1 to 3 do
> print( i, j );
> end do;
> end do;
1, 1

1, 2

1, 3

2, 1

2, 2

2, 3

3, 1

3, 2

3, 3
> Q:= x + y + z - 1 = 0;
Q := x + y + z - 1 = 0

> F := (a,b,c) -> eval( lhs(Q), [x=a,y=b,z=c] );
F := (a, b, c) -> eval(lhs(Q), [x = a, y = b, z = c])

> F( 1,2,3 );
5
> F( a+1, b+1, c+1 );
a + 2 + b + c

(FYI: you can more easily define "column matrices" through Vector( [...] )).

Is this what you need?

M := Matrix(18, 1, [2, 3, 3, 5, 7, 8, 12, 5, 9, -3, 4.1, 7, 7, 7, -3, 9, 3, 8]):

MatLabSort := proc( MM :: Matrix ) :: list( Matrix, list );
local i, Pos,
SortedMM := table(),
R := convert(Statistics[Rank](MM),list),
M := convert( MM, list );

for i from 1 to nops(R) do
SortedMM[ R[i] ] := M[i];
Pos[ R[i] ] := i;
end do;

return [ convert(convert(SortedMM,list),Vector), convert(Pos,list) ];

end proc;

MatLabSort( M );
 

[-3 ]
[ ]
[-3 ]
[ ]
[ 2 ]
[ ]
[ 3 ]
[ ]
[ 3 ]
[ ]
[ 3 ]
[ ]
[4.1]
[ ]
[ 5 ]
[ ]
[ 5 ]
[[ ], [10, 15, 1, 2, 3, 17, 11, 4, 8, 5, 12, 13, 14, 6, 18, 9, 16, 7]]
[ 7 ]
[ ]
[ 7 ]
[ ]
[ 7 ]
[ ]
[ 7 ]
[ ]
[ 8 ]
[ ]
[ 8 ]
[ ]
[ 9 ]
[ ]
[ 9 ]
[ ]
[12 ]

Okay. The problem was the addition of

"if m = 1 then v := 0 end if;"

The code from 13 is

proc(U::list, M::list(posint))
local v, m, u, p, delta, i, k, n;
option `Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2005`;
n := nops(U);
if n <> nops(M) then
error "list of images and list of moduli must be the same length"
end if;
v, m := U[1] mod M[1], M[1];
for k from 2 to n do
u, p := U[k], M[k];
try i := modp(1/m, p)
catch: error "the moduli must be pairwise relatively prime"
end try;
delta := i*modp(u - v, p) mod p;
v, m := v + delta*m, p*m
end do;
v
end proc

(w/ out that line).

 

@Alec Mihailovs 

Linux.

Thanks for your suggestion. But it didn't work. I am indeed using the command line.
Thanks Alec.
Page 1 of 1