slevy2

10 Reputation

4 Badges

4 years, 89 days

MaplePrimes Activity


These are questions asked by slevy2

Hi everyone,

I'm trying to create a function that utilizes the index of a vector to preform the following:

 

Where x and y are both nx1 vectors.  I've tried using summation to no avail, as you can see below: 

Of course, it works when I do it this way, but it's incredibly inefficient if the vectors have a large number of rows:

 

Any help y'all can give me would be extremely appreciated!  Thank you kindly

This is my code.  It's not appending as I need it to.  Any help would be humbly and gratefully appreciated!

 


 

restart; Sort4 := proc (Q, T, U, Rx1, Ry1, Rx2, Ry2, Rx3, Ry3, Rx4, Ry4) local i, k; description "Organizes vectors Q,T into new vectors Rx1...Ry4 correspponding to values of U."; for i from 5 to nops(U) do if U(i) = 1 then Append(Rx1, Q(i)); Append(Ry1, T(i)) elif U(i) = 2 then Append(Rx2, Q(i)); Append(Ry2, T(i)) elif U(i) = 3 then Append(Rx3, Q(i)); Append(Ry3, T(i)) elif U(i) = 4 then Append(Rx4, Q(i)); Append(Ry4, T(i)) end if end do; return Rx1, Rx2, Rx3, Rx4, Ry1, Ry2, Ry3, Ry4 end proc

Q, T, U := `<,>`(0, 2, 4, 6, 7, 17, 27, 57, 67, 97), `<,>`(0, 2, 1, 8, 19, 20, 21, 22, 23, 24), `<,>`(o, o, o, o, 1, 2, 3, 2, 4)

Vector[column](%id = 18446744078670632710), Vector[column](%id = 18446744078670632830), Vector[column](%id = 18446744078670632950)

(1)

Rx1 := Vector([Q(1)]); Ry1 := Vector([T(1)]); Rx2 := Vector([Q(2)]); Ry2 := Vector([T(2)]); Rx3 := Vector([Q(3)]); Ry3 := Vector([T(3)]); Rx4 := Vector([Q(4)]); Ry4 := Vector([T(4)])

_rtable[18446744078670623558]

 

_rtable[18446744078670624518]

 

_rtable[18446744078670625238]

 

_rtable[18446744078670625958]

 

_rtable[18446744078670626678]

 

_rtable[18446744078670619222]

 

_rtable[18446744078670619942]

 

Vector[column](%id = 18446744078670620662)

(2)

Sort4(Q, T, U, Rx1, Ry1, Rx2, Ry2, Rx3, Ry3, Rx4, Ry4)

Vector[column](%id = 18446744078670623558), Vector[column](%id = 18446744078670625238), Vector[column](%id = 18446744078670626678), Vector[column](%id = 18446744078670619942), Vector[column](%id = 18446744078670624518), Vector[column](%id = 18446744078670625958), Vector[column](%id = 18446744078670619222), Vector[column](%id = 18446744078670620662)

(3)

``


 

Download Sort4_320.mw

Page 1 of 1