Reputation:
In Maple, How to divide the number of data1 by the number of data2?
data1:=[1, 2, 3];
data2:=[3, 4, 5];
in order to get something like this:
data3:=[0.333, 0.5, 0.6];
Upvotes: 3
Views: 634
Reputation: 7271
In versions of Maple prior to "Maple 13" (2009) you can use the zip
command:
data1 := [1, 2, 3]:
data2 := [3, 4, 5]:
zip(`/`, data1, data2);
[1 1 3]
[-, -, -]
[3 2 5]
From Maple 13 onwards you can use the elementwise syntax,
data1 /~ data2;
[1 1 3]
[-, -, -]
[3 2 5]
Notice that neither of those give you the floating-point approximations that you gave in your Question. Depending on how many digits you might want in a floating-point representation, you could use the evalf
command:
T := evalf[10](data1 /~ data2):
T;
[0.3333333333, 0.5000000000, 0.6000000000]
That can be further rounded to three digits,
evalf[3](T);
[0.333, 0.500, 0.600]
You could also have only a smaller number of the (internally stored) floating-point digits be displayed.
interface(displayprecision=3):
T;
[0.333, 0.500, 0.600]
# T is still stored to greater precision
lprint(T);
[.3333333333, .5000000000, .6000000000]
Upvotes: 1
Reputation: 15525
According to the documentation:
You can use operator /~
.
data3 := data1 /~ data2
Disclaimer: I don't have maple on this computer to check, and I haven't used maple in many many years.
Bonus: For element-wise operators in other languages, you can find a comparison list on rosettacode:
Upvotes: 2