Items tagged with array array Tagged Items Feed

Hi All,

I used the command map to apply a procedure to elements of a array like this:

 

Why did I get the null array "[]"?

A vector was also used and got the similar result: 

 

I'd appreciate any help on this topic. Thank a lot.

Hello,

As a means of encoding information, I'm working with nested array objects (I had originally used lists, but they became too large and Maple suggested that I use arrays). The nesting should be at most four deep, but the nested arrays can have varying lengths. In order to work with the arrays, I have a series of procedures that manipulate a given array and update the existing array object to contain the result. The issue that I have is that one of my procedures needs to simultaneously use both the original array and a modified version of the array, but once the modification is performed, the original version no longer exists.

Ultimately, my issue boils down to this: is there a clean (or messy, I'm not picky) way to duplicate an array so that there are two copies of the array in memory? Just writting Array2 := Array1 just creates another pointer to the same array in memory from what I can tell, so that doesn't work. There is a function copy, but it doesn't seem to work on nested arrays. 

For example, running the following does not modify Array2.

Array1 := Array([Array([1, 2]), Array([3, 4])]);
Array2 := Array([Array([1, 2]), Array([5, 6])]);
copy(Array1, Array2);

Indeed, neither does

Array1 := Array([Array([1, 2]), Array([3, 4])]);
Array2 := Array([Array([1, 2]), Array([5, 6])]);
copy(Array1(2), Array2(2));

Unfortunately, the latter case would seem to mean that I can't just write a procedure to recurse through my layers of arrays and copy piecewise either.

Thanks in advance for any help.

Please see the attached worksheet for the error at the end, any idea what happens?

Besides, anyone know how to make plot array with each element has a plot and scatterplot in it?  I made my plot by making table first and then type the cmd individually.

Raw Data

restart

avicel102_aero200 := Matrix(12, 3, {(1, 1) = 50, (1, 2) = 1.6621, (1, 3) = .22, (2, 1) = 100, (2, 2) = 3.33221, (2, 3) = .103, (3, 1) = 150, (3, 2) = 4.95533, (3, 3) = 0.43e-1, (4, 1) = 200, (4, 2) = 5.62147, (4, 3) = 0.37e-1, (5, 1) = 50, (5, 2) = 1.88627, (5, 3) = .207, (6, 1) = 50, (6, 2) = 1.90375, (6, 3) = .199, (7, 1) = 100, (7, 2) = 4.04708, (7, 3) = 0.89e-1, (8, 1) = 100, (8, 2) = 4.20413, (8, 3) = 0.87e-1, (9, 1) = 150, (9, 2) = 5.50509, (9, 3) = 0.41e-1, (10, 1) = 150, (10, 2) = 4.90453, (10, 3) = 0.49e-1, (11, 1) = 200, (11, 2) = 6.22001, (11, 3) = 0.16e-1, (12, 1) = 200, (12, 2) = 6.24435, (12, 3) = 0.23e-1}); avicel102_syloid := Matrix(13, 3, {(1, 1) = 50, (1, 2) = 1.76578, (1, 3) = .235, (2, 1) = 100, (2, 2) = 4.08314, (2, 3) = .128, (3, 1) = 150, (3, 2) = 4.85921, (3, 3) = 0.73e-1, (4, 1) = 200, (4, 2) = 5.66786, (4, 3) = 0.51e-1, (5, 1) = 50, (5, 2) = 2.06221, (5, 3) = .224, (6, 1) = 50, (6, 2) = 2.17294, (6, 3) = .216, (7, 1) = 100, (7, 2) = 4.03728, (7, 3) = .109, (8, 1) = 100, (8, 2) = 3.67978, (8, 3) = .116, (9, 1) = 150, (9, 2) = 5.78427, (9, 3) = 0.6e-1, (10, 1) = 150, (10, 2) = 5.43599, (10, 3) = 0.59e-1, (11, 1) = 200, (11, 2) = 6.26332, (11, 3) = 0.38e-1, (12, 1) = 200, (12, 2) = 6.10814, (12, 3) = 0.39e-1, (13, 1) = 200, (13, 2) = 6.83857, (13, 3) = 0.25e-1}); avicel301_101_aero200 := Matrix(12, 3, {(1, 1) = 50, (1, 2) = 1.106, (1, 3) = .2597543205, (2, 1) = 50, (2, 2) = 1.06, (2, 3) = .2564849561, (3, 1) = 50, (3, 2) = 1.129, (3, 3) = .2552025392, (4, 1) = 100, (4, 2) = 2.865, (4, 3) = .1280363098, (5, 1) = 100, (5, 2) = 2.793, (5, 3) = .127659333, (6, 1) = 100, (6, 2) = 3.088, (6, 3) = .1347147061, (7, 1) = 150, (7, 2) = 4.216, (7, 3) = 0.802489497e-1, (8, 1) = 150, (8, 2) = 4.044, (8, 3) = 0.838493001e-1, (9, 1) = 150, (9, 2) = 4.071, (9, 3) = 0.855901289e-1, (10, 1) = 200, (10, 2) = 4.826, (10, 3) = 0.627298821e-1, (11, 1) = 200, (11, 2) = 4.924, (11, 3) = 0.614759445e-1, (12, 1) = 200, (12, 2) = 4.76, (12, 3) = 0.61001365e-1})

NULL

 

with(LinearAlgebra):

X[1] := Column(avicel102_aero200, 3):

X[2] := Column(avicel102_syloid, 3):

X[3] := Column(avicel301_101_aero200, 3):

S := Array(1 .. 3):

S[1] := ScatterPlot(X[1], Y[1], labels = [Porocity, Tensile*Strength], title = Compactability*of*Avicel102*with*Aerosil200):

with(plots):NULL

 

vSST := Array(1 .. 3):

tpfit := proc (x, y) options operator, arrow; Fit(a*exp(-k*p)+c, x, y, p, output = [leastsquaresfunction, residualsumofsquares, degreesoffreedom]) end proc:SST := proc (y) options operator, arrow; Variance(y)*(NumElems(y)-1) end proc:NULL

for i to 3 do fnTP[i] := tpfit(X[i], Y[i])[1] end do:

for i to 3 do fnPC[i] := Fit(c*p^2+b*p+a, P[i], X[i], p, output = [leastsquaresfunction, residualsumofsquares, degreesoffreedom])[1] end do:

NULL

for i to 3 do vSST[i] := SST(Y[i]) end do:

for i to 3 do pSST[i] := SST(X[i]) end do:

NULL

for i to 3 do vSSR[i] := tpfit(X[i], Y[i])[2] end do:

for i to 3 do Rsquare[i] := 1-vSSR[i]/vSST[i] end do:

NULL

``

s := Array(1 .. 3):

for i to 3 do s[i] := plot(fnTP[i], p = 0 .. .26, legend = typeset(fnTP[i], R^2, "= ", Rsquare[i])) end do

for i to 3 do ps[i] := plot(fnPC[i], p = 0 .. 200, legend = typeset(fnPC[i], R^2, "= ", pRsquare[i])) end do

G := Array(1 .. 3):

G[1] := [S[1], s[1]]:

pG := [[PS[1], ps[1]], [PS[2], ps[2]], [PS[3], ps[3]]]:NULL

NULL

Table 1: Compactability Curve

display(G[1])

 

NULL

display(G[2])

 

NULL

display(G[3])

 

NULL

NULL

NULL

Table 2: Compressibility Curve

display(pG[1])

 

NULL

display(pG[2])

 

NULL

display(pG[3])

 

NULL

``

ff := proc (x) options operator, arrow; unapply(x, p) end proc:

gtp := map(ff, fnTP):

gpc := map(ff, fnPC):

TS1 := proc (pressure) options operator, arrow; (`@`(gtp[1], gpc[1]))(pressure/Unit('MPa'))*Unit('MPa') end proc:

TS2 := proc (pressure) options operator, arrow; (`@`(gtp[2], gpc[2]))(pressure/Unit('MPa'))*Unit('MPa') end proc:

TS3 := proc (pressure) options operator, arrow; (`@`(gtp[3], gpc[2]))(pressure/Unit('MPa'))*Unit('MPa') end proc:

por1 := proc (p) options operator, arrow; gpc[1](p/Unit('MPa')) end proc:

(1)

por1(x*Unit('MPa'))

HFloat(0.36333333333333295)-HFloat(0.0036139999999999957)*x+HFloat(9.666666666666651e-6)*x^2

(2)

por1(x);

HFloat(0.36333333333333295)-HFloat(0.0036139999999999957)*x/Units:-Unit('MPa')+HFloat(9.666666666666651e-6)*x^2/Units:-Unit('MPa')^2

(3)

``

NULL

 

(4)

ts := 2/3*(10*P/(Pi*D^2*(2.84*t/D-.126*t/W+3.15*W/D+0.1e-1))):

Target Weight of Tablet, m__t:

m__t := 700*Unit('mg')

700*Units:-Unit('mg')

(5)

Tablet True Density:NULL

`ρ__true1` := 1.8*Unit('g'/'cm'^3)

1800.0*Units:-Unit(('kg')/('m')^3)

(6)

Width of tablet w;

d := 7.747*Unit('mm')

7.747*Units:-Unit('mm')

(7)

Length of tablet, l:

l := 17.018*Unit('mm')

17.018*Units:-Unit('mm')

(8)

Cup Depth, h:

hh := 1.6764*Unit('mm')

1.6764*Units:-Unit('mm')

(9)

Cup Volume", `v__cup`"

v__cup := 119.789438*Unit('mm'^3)

119.789438*Units:-Unit(('mm')^3)

(10)

Die cross sectional area, v__die:

a__die := 118.9610524*Unit('mm'^2)

118.9610524*Units:-Unit(('mm')^2)

(11)

Equation to solve tablet thickness using tablet dimension and porocity:

Tablet bulk density:

`ρ__bulk` := `ρ__true`*sf

`ρ__true`*sf

(12)

Tablet volume:``

V__tablet := 2*V__cup+A__die*(t-2*H)

2*V__cup+A__die*(t-2*H)

(13)

NULL

Tablet bulk Density:``

`ρ__bulk` := m__tablet/V__tablet

m__tablet/(2*V__cup+A__die*(t-2*H))

(14)

NULL

eq1 := m__tablet/(2*V__cup+A__die*(t-2*H)) = `ρ__true`*sf

m__tablet/(2*V__cup+A__die*(t-2*H)) = `ρ__true`*sf

(15)

Function for thickness:

thickness := unapply(simplify(solve(eq1, t), size), sf, A__die, H, V__cup, `ρ__true`, m__tablet)

proc (sf, A__die, H, V__cup, `ρ__true`, m__tablet) options operator, arrow; (2*sf*(A__die*H-V__cup)*`ρ__true`+m__tablet)/(A__die*sf*`ρ__true`) end proc

(16)

simplify(thickness(1-por[1](100*Unit(MPa)), a__die, hh, v__cup, `ρ__true1`, m__t))

HFloat(0.005719286791216391)*Units:-Unit('m')

(17)

t2 := proc (cc, A__die, H, V__cup, `ρ__true`, m__tablet) options operator, arrow; simplify(thickness(1-cc, A__die, H, V__cup, `ρ__true`, m__tablet)) end proc:

``

``

``

Tablet tensile strength:NULL

eq2 := `σ__t` = ts

`σ__t` = (20/3)*P/(Pi*D^2*(2.84*t/D-.126*t/W+3.15*W/D+0.1e-1))

(18)

Break force of tablet (N)

breakforce := unapply(subs(W = t-2*h, solve(eq2, P)), `σ__t`, D, h, t)

proc (`σ__t`, D, h, t) options operator, arrow; 0.9424777961e-3*`σ__t`*D*(5.*D*(t-2*h)-63.*t*D+1575.*(t-2*h)^2+1420.*t*(t-2*h))/(t-2*h) end proc

(19)

 

kp := simplify(breakforce(TS[1](100*Unit('MPa')), d, hh, 0.5719e-2*Unit('m')))

HFloat(286.99924404612904)*Units:-Unit('N')

(20)

convert(kp, units, kilopond)

HFloat(29.265778226624693)*Units:-Unit('kilopond')

(21)

t2(por[1](100*Unit('MPa')), a__die, hh, v__cup, `ρ__true1`, m__t)

HFloat(0.005719286791216391)*Units:-Unit('m')

(22)

``

hh

1.6764*Units:-Unit('mm')

(23)

simplify(breakforce(TS[1](100*Unit('MPa')), d, hh, t2(por[1](100*Unit('MPa')), a__die, hh, v__cup, `ρ__true1`, m__t)))

HFloat(287.02451456724083)*Units:-Unit('N')

(24)

Encounter problem while chaning variable

 BF:= 
proc (`σ__t`, D, p, A__die, hhh, V__cup, `ρ__true`, m__tablet) options operator, arrow; breakforce(`σ__f`, D, hhh, t2(p, A__die, hhh, V__cup, `ρ__true`, m__tablet)) end proc:

BF(TS1(100*Unit('MPa')), d, por1(100*Unit('MPa')), a__die, hh, v__cup, `ρ__true1`, m__t)

BF(HFloat(3.6712504621161846)*Units:-Unit('MPa'), 7.747*Units:-Unit('mm'), HFloat(0.09859999999999991), 118.9610524*Units:-Unit(('mm')^2), 1.6764*Units:-Unit('mm'), 119.789438*Units:-Unit(('mm')^3), 1420.00*Units:-Unit(('kg')/('m')^3), 667*Units:-Unit('mg'))

(25)

evalf(TS[1](100*Unit(MPa)))

HFloat(3.6712504621161846)*Units:-Unit('MPa')

(26)

plot(breakforce(TS1(x), d, hh, t2(por1(x), a__die, hh, v__cup, `ρ__true1`, m__t)), x = Unit('MPa') .. 200*Unit('MPa'), useunits = true)

Error, (in Units:-Standard:-+) the units `1` and `1/MPa` have incompatible dimensions

 

plot(t2(por1(x), a__die, hh, v__cup, `ρ__true1`, m__t), x = Unit('MPa') .. 200*Unit('MPa'), useunits = true)

Error, (in Units:-Standard:-+) the units `1` and `1/MPa` have incompatible dimensions

 

plot(evalf(por1(xx)), xx = 10 .. 200)

 

but por1 works fine on its own with units

por1(Units:-Standard:-`*`(200, Unit('MPa')))

HFloat(0.02719999999999989)

(27)

plot(evalf(por1(xx)), xx = 10 .. 200);

 

Unloading Units:-Standard

``

``

``

``

``

``

``

``

``

``

``

``

``

``

 

Fitting_worksheet.mw

I also used a lot for for loop in this worksheet, can anyone suggest another way of doing it? And I think I initiated many Array(1..3) that is of no use.  But if I do not initiate and do the following

A[1]:=a : 

A[2]:=b:

A[3]:=c:

A;

output: A

Only if I initiate A:=Array(1..3) and then define the element I can see the complete A array at the end.

 

Hi, i'm wondering if theres anything i can do printf and print and have the outputs on the same line. I want the string wihtout any quotations so i think i can only do printf to get this, but then i'm putting an entry out of an array after this. This is a small example out of my code, i would like the output to be all on one line:

The synchronising vector is (S[j-1]) The synchronising word is (X[j-1]) The length of the synchronising word is ...

 

if (sync=true) then 
printf("The Synchronising vector is"); print(S[j-1]);
printf("The sychronising word is");
print(X[j-1]);
printf("The length of the synchronising word is");
print(length(X[j-1]));
else printf("There is no synchronising word"); 
end if;

 At the moment its outputing each print on a new line.

Any help would be much appreciated, thanks.

 

I have no idea where to start with this problem.

I know how to create arrays, but I want to assign characteristics to each position in the array; the array being a population with each member having a set of characteistics like height, weight etc. I want to be able to have some of the characteristics able to change with time, and some remain constant (those that change with time will be defined by generic equations)

I have tried looking on maplesoft for answers, and the help within maple 16, but have been unable to make any progress.

 

Sorry if the question is not specific enough.

 

Thanks in advance x

Hi,

I have a 4-D function that I have found an analytic expression for in Maple, but I want to generate a numerical 4-D array, which I can export for use in Matlab. However, I don't think I'm using a very good solution, because it is extremely slow (several minutes for even 10x10x10x10 elements). My code is

NumRange:=10:
NumElements:=10:
dx:=2*NumRange/(NumElements-1):
A:=Array(1..NumElements,1..NumElements,1..NumElements,1..NumElements,[seq([seq([seq([seq(evalf(rho(ws1,ws2,ws1p,ws2p)),ws2p=-NumRange..NumRange,dx)],ws1p=-NumRange..NumRange,dx)],ws2=-NumRange..NumRange,dx)] , ws1=-NumRange..NumRange,dx)],datatype=float);

Rho is an exponential with 10 terms in the exponents.

I also tried using four for-loops but that was even slower!

Thanks for any input

Hello,

 

I don't seem to be able to create an array of plot with two rows, where the first one is a sigle animation and the second rwo is two animations in the same plot. For example I would the first row of the array to display

H := animate(plot3d, [x-k*y+1, x=-10..10, y=-10..10], k=-10..0, frames=4):

display([H]);

end the second row to display

P := animate(plot, [sin(x+t), x=-Pi..Pi], t=-Pi..Pi, frames=8):
Q := animate(plot, [cos(x+t), x=-Pi..Pi], t=-Pi..Pi, frames=8):


display([P, Q]);


Any ideas?

If i use expression with function add() it runs normaly, but if I use expression with Threads:-Add (parallel implementation) it causes error "Error, continuation task already created for the current task" or "Kernel connection has been lost"

Expression:

Array(1 .. N,1 .. 1/2*N-NR-1,(i, m) -> evalf(Add(cosArr2[modp(k*i,N)]/kl[k],k = 1 .. NR+m-1)+Add(cosArr2[modp(k*i,N)]*alpha[k],k = NR+m .. 1/2*N)))

 

What am I doing wrong? Can I use two Add in one evalf?

I'm trying to create and populate the Array `A` with a sequence of lower triangular matrices based on the following relation:

A[k+1][i,j] = a (1+k) A[k][i,j] + b ((1+j) A[k][i-1,j] - j A[k][i-1,j-1])

The rows and columns of each matrix are given by i and j; a and b are scalars. The structure of A is not important provided a matrix can be accessed for a given k. The highest k value will not be more than about 100.

The starting matrix for k=1 is

[-1  0]
[ 1 -1]

Any guidance on where to start with setting up the appropriate procedure would be greatly appreciated.

Thanks.

In ode solve command i generated a large array data. The output shows a large order matrix of this form

 

[110001x6 Matrix

Datatype:Anything

Storage:rectangular

order:Fortran_order].

 

I want to export this matrix into a notepad. Which can then be used for plotting in TecPlot. 

 

Looking for good response

 

 

Hi,

I'm currently writing a programme for synchronising automatas, its creates an array and adds words or matrices to the array that aren't already in. I am currently getting an error when i try and run my procedure though and i'm unsure of the problem, any help would be appreciated, here is my code so far.

Thanks!

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector[row],N)
local x, S, i, j, T, R, y, found;
x:=2^N;
S:=Array(0..(x-1));
S[0]:=C;
i:=0;
j:=1;
found:=false;

while (i<(x-1) and i<>j) do
T:=S[i].A;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=T;
j:=j+1;
end if:
end if:
od:

R:=S[i].B;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=R;
j:=j+1;
i:=i+1;

end if:
end if:
od:
od:
print(S);
end proc:

 

The error i'm getting is when i input this:

proc_cerny1(Matrix([[1,0,0],[1,0,0],[1,0,0]]),Matrix([[0,1,0],[0,0,1],[0,0,1]]),Vector(1..3,1,orientation=row),3);

and the error is:

Error, (in LinearAlgebra:-Equal) invalid input: LinearAlgebra:-Equal expects its 1st argument, X, to be of type {Matrix, Vector} but received 0

 

Please

 

can someone tell me how to plot values directly from an array? I'd have thought that this was a simple task but unfortunately I havent seen any useful examples in the Maple Help.

 

Let's say any array such as A:=Array(1..4,1..4); with random numbers.

 

I want to plot column 1 vs 3, how do I do it?

 

thanks

Hi, I am trying to write a procedure that inputs two matrices (A,B) and vector (C), it then multiplies C by A, and thenC by B and adds these to the array, it then multiplies each other them by A and B and adds them to the array etc up to (N-1)^2 (N will be given), this is what I hve so far, I am trying to write an if loop inside to say if it's already in the array then do not add it again but i'm unsure. Any help would be appreciated thanks!

 

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector,N)
local x, S, i, j, T, R, y;
x:=(N-1)^2;
S:=Array([]);
S[0]:=C;
i:=0;
j:=0;
while (i<(2^N)) do
T=S[i].A;
S[j]=T;
j=j+1;
R=S[i].B;
S[j]=R;
i=i+1;
for y from 0 to j do
if (S[y]=T) then
S[i]=S[i]-T;
fi:
od:
print(S);
end proc:

I am getting an error dialog when I try to Browse an array I created programmatically.  The title of the dialog is RTable Browse Error with and error that says Empty RTable Structure. 

 

Now the data is 0..20 x 0..1 Array Datatype :anything Storage: rectangular

Order: Fortran_Order. 

 

If I do a showall, I can see the data, I just cannot browse it.  Any help would be appreciated.

Code is:


for i from 1 to N do
 t:=h*i:
 X[i,0]:=x1+h*(-x1)*x2+x1:
 X[i,1]:=x2+h*x1*x2-x2:
 x1:=X[i,0]:
 x2:=X[i,1]:
 print('Iteration',i,'AtTime',t,x1,x2)
end do;
print(X);

Thanks

Melvin

 

 

Hi there!

Maple has lot's of datatypes which are very related to each other, such as Matrices and Arrays, or sets, lists and vectors.

Most of the time I am not quite sure which type is the "right" one to use for me, and I guess for most of the stuff I have done so far it didn't really matter. However now I am going a bit into numerics, and there things can get big and computationally expensive. Also, recently I got an error message stating that I would assign a large list to a variable, and should rather use an Array instead. So I guess I should start to bother what to use. : )

Obviously the Matrix has some advantages to the Array in the sense that I can perform matrix calculations with it easier using the LinearAlgebra package. So it can be transposed and what not. But is it disadvantegeous to the Array in any way, especially when it comes to large matrices in numerical calculations?

The same would interest me for sets, lists and Vectors.

Cheers!

Gernot

1 2 3 4 5 6 7 Last Page 1 of 23