tomleslie

13876 Reputation

20 Badges

15 years, 181 days

MaplePrimes Activity


These are replies submitted by tomleslie

@ecterrab 

As a result of this thread, I've updated my 'Physics' package more often in the last two days, than I have in the last three months. The latest update produces no answer to the OP's time-dependent Schrodinger Equation example.

I suppose that not 'hanging' is an improvement, but was it really intended to produce nothing, albeit quickly. See the attached


 

restart;
kernelopts(version);
Physics:-Version();
pde:=  I* diff(f(x,y,t),t) = -hBar^2/(2*m) * (diff(f(x,y,t),x$2) +  diff(f(x,y,t),y$2)):
ic := f(x, y, 0) = sqrt(2)*(sin(2*Pi*x)*sin(Pi*y) + sin(Pi*x)*sin(3*Pi*y)):
bc := f(0, y, t) = 0,f(1, y, t) = 0, f(x, 1, t) = 0, f(x, 0, t) = 0:
sol:=pdsolve({pde,ic,bc},f(x,y,t));

`Maple 2018.1, X86 64 WINDOWS, Jun 8 2018, Build ID 1321769`

 

"C:\Users\TomLeslie\maple\toolbox\2018\Physics Updates\lib\Physics Updates.maple", `2018, July 4, 22:47 hours, version in the MapleCloud: 75, version installed in this computer: 75`

 

(1)

 


 

Download physProb.mw

@inteli 

  1. Can i organise the export of a a complete matrix to a blank excel spreadsheet - yes
  2. Can I organise the export of some contiguous columns of a matrix to a blank excel spreadsheet - yes
  3. Can I organise the export of some non-contiguous columns of a matrix to a blank excel spreadsheet - yes
  4. Can I organise the export of a matrix to an existing (non-blank) excel spreadsheet, overwriting when necessay- yes
  5. Can I organise the export of some contiguous columns of a matrix to an existing (non-blank) excel spreadsheet, overwriting when necessay- yes
  6. Can I organise the export of some non-contiguous columns of data to an existing excel spreadsheet, overwriting when necessay - yes

I can do all of the above because I can read the "help" for the ExcelTools:-Export() command, which obviously you can't

Before I do anything else, you have to specify exactly which of the above six options you want - and bear in mind, that you get precisely one shot. I will answer your next question absolutely precisely - but if it turns out to be the "wrong" question, like most of your previous attempts, then all subsequent requests for assistance will be ignored

@Bosco Emmanuel 

that you have to change the path to the file in these worksheets, but why are you editing the code I send before you execute it? This is pretty much guaranteed to produce errors! The code in the file Tom-Redo-2.mw has a typo, which wasn't in my original!! Did you retype it? Do you know how long it took me to find this typo?

 

Having got that off my chest, I admit to a typo in both of the original files which I provided I had T[1,n] where I should have had T[l, n] -mea culpa etc, and a good illustration why one should never use the letter 'l' as an index variable, because it is to easy to confuse it with the number '1'

 

Having fixed my mistakes, and yours, the four versions in the attached now all give the same answer.

 

The remaining problem is that the returned answer is not the same as the code in your earlier posts, ie the files

Download Code-2-for-Tom.mw

Download Code-1-for-Tom.mw. .

 
The discrepancy is small, and I think that it is related to the fact that generating 'samples' from the exponential distribution 'one-at-a-time' within the for loop results in a different set of samples than generating all 1001 samples in one command This behaviioour i also illustrated in the attached. Unless you think otherwise I'm not convinced that the discrepancy is "significant"

  restart;
  with(Statistics):
#
# Initialise a few things
#
  p:= [3, 1, 0.5, 0.3, 1, 1.5]:
  RT:= Array(1..3, p[4..6]):
  TC[0]:= 0.:
  N:= Array(1..3, [0, 0, 0]):
  T:= Matrix( 3, 1001, [ Sample(Exponential(1/p[1]), 1001),
                         Sample(Exponential(1/p[2]), 1001),
                         Sample(Exponential(1/p[3]), 1001)
                       ],
              scan=columns
            ):
#
# Do the calculation
#
  for n to 1001 do
      l:= min[index](T[..,n]):
      N[l]:= N[l]+1;
      B[N[l], l]:= T[l,n]+RT[l]; # changed T[1,n] to T[l,n]
      TC[n]:= TC[n-1]+B[N[l], l]
   end do:
   z:= ImportMatrix("C:/Users/TomLeslie/DeskTop/Tom.txt"):
#
# Get the result
#
   Error:= add((z[i,1]-(TC[i+1]-TC[i]))^2, i = 1 .. 1000);

Error := 253.811587911532

(1)

###############################################################
#
# Define procedure which does the same
# calculation as the above
#
  restart:
  lc:=proc( p::list )
          #
          # Declare/initialise local variables
          #
            local RT:= Array(1..3, p[4..6]),
                  TC:= Array(0...1001, fill=0),
                  N:= Array(1..3, [0, 0, 0]),
                  T:= Matrix( 3, 1001, [ Sample(Exponential(1/p[1]), 1001),
                                         Sample(Exponential(1/p[2]), 1001),
                                         Sample(Exponential(1/p[3]), 1001)
                                       ],
                              scan=columns
                            ),
                  z:= ImportMatrix("C:/Users/TomLeslie/DeskTop/Tom.txt"),
                  n, l, B;
          #
          # Ensure Statistics package is loaded
          #
            uses Statistics:
          #
          # Do calculations
          #
            for n to 1001 do
                l:= min[index](T[..,n]):
                N[l]:= N[l]+1;
                B[N[l], l]:= T[l, n]+RT[l]; # changed T[1,n] to T[l,n]
                TC[n]:= TC[n-1]+B[N[l], l]
            end do:
          #
          # Return result
          #
            return add((z[i,1]-(TC[i+1]-TC[i]))^2, i = 1 .. 1000);
       end proc:
#
# Run the calculation with the same data
# as used in the above
#
  Error:=lc([3, 1, 0.5, 0.3, 1, 1.5])

Error := 253.811587911532

(2)

############################################
# A 'Quirk' of sample generation
#
# Note that in the following two methods
# the 'first sample always agrees, but
# subsequent samples do not
#
  restart;
  with(Statistics):
  Sample(Exponential(1/0.3), 5);
#
  restart;
  with(Statistics):
  X:=Exponential(1/0.3):
  for i from 1 by 1 to 5 do
      Sample(X,1)[1];
  od;

Vector[row](5, {(1) = 13.726161926962995, (2) = 6.2840096650094015, (3) = 6.516070658333388, (4) = .26198922234730954, (5) = .6134828406538144})

13.7261619269630

4.78315819740088

1.51064580852117

11.1102902544401

1.52147762430717

(3)

restart; with(Statistics); p := [3, 1, .5, .3, 1, 1.5]; RT := Array(1 .. 3, p[4 .. 6]); TC[0] := 0.; N := Array(1 .. 3, [0, 0, 0]); T := Matrix(3, 1001, [Sample(Exponential(1/p[1]), 1001), Sample(Exponential(1/p[2]), 1001), Sample(Exponential(1/p[3]), 1001)], scan = columns); for n to 1001 do l := min[index](T[() .. (), n]); N[l] := N[l]+1; B[N[l], l] := T[l, n]+RT[l]; TC[n] := TC[n-1]+B[N[l], l] end do; z := ImportMatrix("C:/Users/TomLeslie/Desktop/Tom.txt"); Error := add((z[i, 1]-TC[i+1]+TC[i])^2, i = 1 .. 1000)

Error := 253.811587911532

(4)

restart; with(Statistics); lc := proc (p::list) local RT, TC, N, T, z, n, l, B; RT := Array(1 .. 3, p[4 .. 6]); TC := Array(0 .. 1001, fill = 0); N := Array(1 .. 3, [0, 0, 0]); T := Matrix(3, 1001, [Statistics:-Sample(Exponential(1/p[1]), 1001), Statistics:-Sample(Exponential(1/p[2]), 1001), Statistics:-Sample(Exponential(1/p[3]), 1001)], scan = columns); z := ImportMatrix("C:/Users/TomLeslie/Desktop/Tom.txt"); for n to 1001 do l := min[index](T[() .. (), n]); N[l] := N[l]+1; B[N[l], l] := T[l, n]+RT[l]; TC[n] := TC[n-1]+B[N[l], l] end do; return add((z[i, 1]-TC[i+1]+TC[i])^2, i = 1 .. 1000) end proc; Error := lc([3, 1, .5, .3, 1, 1.5])

Error := 253.811587911532

(5)

 

Download randStuff2.mws

 

@inteli 

in the Export() command. Without a full pathname, you will be exporting to a location which is specific to your OS/installation/etc. Are you sure you know where it is going?

The attached reads the data file from my desktop, and saves the output file JUNR.xls to my desktop

restart; kernelopts(version); with(ExcelTools); M1A := Import("C:/Users/TomLeslie/Desktop/Inquiry1.xls", "Sheet1", "A3:E9"); M2A := Import("C:/Users/TomLeslie/Desktop/Inquiry1.xls", "Sheet2", "A3:E8"); f := proc (x) options operator, arrow; sqrt(x)+1 end proc; M1B := `<|>`(M1A, `~`[f](M1A[() .. (), 5])); M2B := `<|>`(M2A, `~`[f](M2A[() .. (), 5])); g := proc (x, y) options operator, arrow; zip(proc (i, j) options operator, arrow; i^2+j end proc, x, y) end proc; M1C := `<|>`(M1A, g(M1A[() .. (), 2], M1A[() .. (), 4])); M2C := `<|>`(M2A, g(M2A[() .. (), 2], M2A[() .. (), 4]))

`Maple 2018.1, X86 64 WINDOWS, Jun 8 2018, Build ID 1321769`

 

Matrix(7, 5, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7})

 

Matrix(6, 5, {(1, 1) = "JAN", (1, 2) = 29.1, (1, 3) = 36.9, (1, 4) = 29.2, (1, 5) = 35.1, (2, 1) = "FEB", (2, 2) = 32.1, (2, 3) = 39.1, (2, 4) = 30.0, (2, 5) = 37.4, (3, 1) = "MAR", (3, 2) = 31.9, (3, 3) = 39.5, (3, 4) = 31.6, (3, 5) = 37.7, (4, 1) = "APRIL", (4, 2) = 32.0, (4, 3) = 39.5, (4, 4) = 31.5, (4, 5) = 37.7, (5, 1) = "MAY", (5, 2) = 30.6, (5, 3) = 372.0, (5, 4) = 30.1, (5, 5) = 35.3, (6, 1) = "JUNE", (6, 2) = 28.3, (6, 3) = 33.1, (6, 4) = 28.3, (6, 5) = 32.0})

 

Matrix(7, 6, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (1, 6) = 6.477225575, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (2, 6) = 6.522680509, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (3, 6) = 6.477225575, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (4, 6) = 6.630275304, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (5, 6) = 6.753259945, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (6, 6) = 6.865151319, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7, (7, 6) = 6.805170109})

 

Matrix(6, 6, {(1, 1) = "JAN", (1, 2) = 29.1, (1, 3) = 36.9, (1, 4) = 29.2, (1, 5) = 35.1, (1, 6) = 6.924525297, (2, 1) = "FEB", (2, 2) = 32.1, (2, 3) = 39.1, (2, 4) = 30.0, (2, 5) = 37.4, (2, 6) = 7.115553941, (3, 1) = "MAR", (3, 2) = 31.9, (3, 3) = 39.5, (3, 4) = 31.6, (3, 5) = 37.7, (3, 6) = 7.140032573, (4, 1) = "APRIL", (4, 2) = 32.0, (4, 3) = 39.5, (4, 4) = 31.5, (4, 5) = 37.7, (4, 6) = 7.140032573, (5, 1) = "MAY", (5, 2) = 30.6, (5, 3) = 372.0, (5, 4) = 30.1, (5, 5) = 35.3, (5, 6) = 6.941380311, (6, 1) = "JUNE", (6, 2) = 28.3, (6, 3) = 33.1, (6, 4) = 28.3, (6, 5) = 32.0, (6, 6) = 6.656854249})

 

Matrix(7, 6, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (1, 6) = 862.91, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (2, 6) = 771.99, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (3, 6) = 761.01, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (4, 6) = 800.04, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (5, 6) = 857.44, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (6, 6) = 917.14, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7, (7, 6) = 840.15})

 

Matrix(%id = 18446744074396182518)

(1)

Export(M1B, "C:/Users/TomLeslie/Desktop/JUNR.xls", 1, "D4:F7")

NULL

Download fileLocation.mw

Use the big green up-arrow in the MaplePrimes toolbar to post your worksheet

@BigBugBuzz 

Use the big green up-arrow in the MaplePrimes toolbar to upload your code - no-one can do anything very much with "pictures" of code

% -refers to the output of the previous command

[%] - puts the output of the previous command in a list

numelems([%]) - counts the number of elements in the generated  list

I'm running Maple 2018.1.on 64-bit Windows 7.

I cannot reproduce the error you see. As sheer luck would have it, I was running a slightly old Physics version. I do get a difference in output between this 'old' version, and that which is returned when I update to the latest Physics version - but neither of these produces an "ERROR"

Without updating the Physics package I obtained

restart;
version();
Physics:-Version();
interface(showassumed=0);
pde :=  diff(u(x,t),t)+k*diff(u(x,t),x$2)+sin(2*Pi*x/L);
ic  :=  u(x,0)=f(x);
bc  :=  D[1](u)(0,t)=0, D[1](u)(L,t)=0;
sol :=  pdsolve({pde,ic,bc},u(x,t)) assuming L>0,t>0,k>0;

 User Interface: 1321769

         Kernel: 1321769
        Library: 1321769

 

1321769

 

"C:\Users\TomLeslie\maple\toolbox\2018\Physics Updates\lib\Physics Updates.maple", `2018, March 29, 0:45 hours`

 

1

 

diff(u(x, t), t)+k*(diff(diff(u(x, t), x), x))+sin(2*Pi*x/L)

 

u(x, 0) = f(x)

 

(D[1](u))(0, t) = 0, (D[1](u))(L, t) = 0

 

u(x, t) = ((Sum(2*(Int(f(tau1)*cos(n*Pi*tau1/L), tau1 = 0 .. L))*cos(n*Pi*x/L)*exp(k*Pi^2*n^2*t/L^2)/L, n = 1 .. infinity))*L+(Int(((Sum(-2*(Int(sin(2*Pi*x/L)*cos(n1*Pi*x/L), x = 0 .. L))*cos(n1*Pi*x/L)*exp(k*Pi^2*n1^2*(t-tau1)/L^2)/L, n1 = 1 .. infinity))*L-(Int(sin(2*Pi*x/L), x = 0 .. L)))/L, tau1 = 0 .. t))*L+Int(f(tau1), tau1 = 0 .. L))/L

(1)

 

Download oldPhys.mw

 

If I update to the" latest/greatest" Physics package, I don't actually get an answer - but I don't get an error????

restart;
version();
Physics:-Version();
interface(showassumed=0);
pde :=  diff(u(x,t),t)+k*diff(u(x,t),x$2)+sin(2*Pi*x/L);
ic  :=  u(x,0)=f(x);
bc  :=  D[1](u)(0,t)=0, D[1](u)(L,t)=0;
sol :=  pdsolve({pde,ic,bc},u(x,t)) assuming L>0,t>0,k>0;

 User Interface: 1321769
         Kernel: 1321769
        Library: 1321769

 

1321769

 

"C:\Users\TomLeslie\maple\toolbox\2018\Physics Updates\lib\Physics Updates.maple", `2018, April 24, 18:29 hours, MapleCloud version: 72`

 

1

 

diff(u(x, t), t)+k*(diff(diff(u(x, t), x), x))+sin(2*Pi*x/L)

 

u(x, 0) = f(x)

 

(D[1](u))(0, t) = 0, (D[1](u))(L, t) = 0

 

(1)

 


Download newPhys.mw

@Bosco Emmanuel 

the logic is the same  although I found following yor orifginal code difficult.

If you do get a difference, I'm pretty sure that I could trace it if you posted your datafile here

Using your matrix definition, then my original code shows that the eigenvalues are real, the eigenvectors are real and both can be plotted. You *ought* to be able to load/read/examine the attached.

realEV2.mws

For some reason, this site will not allow me to display the contents of this file - maybe something to with the plot arrays, although to be honest, I'm not sure

From your response, I'm assuming that if you actually try to re-execute this file it. will fail. This is undoubtedly a Maple version issue. You are running Maple 12, which was superseded ten years ago. There have been ten major Maple releases since. I only keep Maple releases for about the last five years, so my ability to diagnose possible problems is very limited.

There are only about 6-8 significant commands in the attached: It *ought* to be fairly simple to determijne which one is failing, by executing them one at a time. Once you know which command is failing, and why, it may be possible to come up with a workaround

@Bosco Emmanuel 

  1. As before, I can't run/test anything in Maple12 - I just don't have anything that old:-(
  2. You didn't provide the datafile - so obviously I can't run your code
  3. I strongly recommend that switch to using Maple's 1-D input option. Apart from anything else, it would actually mak your code "person-readable" - because (as written) it is an absolute nightmare to debug. NB it is possible to write neat, readable code using 2-D input, but it is more difficult, particularly for inexperienced users

So what did I do

  1. Created a "random" matrix to use as a datafile: I had to use something!
  2. Converted your code to 1-D input
  3. Removed loads of repetitions, inefficiencies, redundant variables, etc. Since I don't have you original data file, with the "expected" result, this is a "high risk" activity, since I may have made a logical error somewhere
  4. Produced two execution groups: one where the calculation is performed as a top-level worksheet, and the other where a procedure is used to perform the same calculation.
  5. Note that in the attached, both of these calculations return the same answer - although since I am using a randomly generated data file, this answer bears no relation to that which would be obtained using your actual data file.
  6. In order to run this code on your machine, the filename in the ImportMatrix() commands will have to be modified to point at your datafile

Check the attached


 

  restart;
  with(Statistics):
#
# Initialise a few things
#
  p:= [3, 1, 0.5, 0.3, 1, 1.5]:
  RT:= Array(1..3, p[4..6]):
  TC[0]:= 0.:
  N:= Array(1..3, [0, 0, 0]):
  T:= Matrix( 3, 1001, [ Sample(Exponential(1/p[1]), 1001),
                         Sample(Exponential(1/p[2]), 1001),
                         Sample(Exponential(1/p[3]), 1001)
                       ],
              scan=columns
            ):
#
# Do the calculation
#
  for n to 1001 do
      l:= min[index](T[..,n]):
      N[l]:= N[l]+1;
      B[N[l], l]:= T[1,n]+RT[l];
      TC[n]:= TC[n-1]+B[N[l], l]
   end do:
   z:= ImportMatrix("C:/Users/TomLeslie/DeskTop/TestData.csv"):
#
# Get the result
#
   Error:= add((z[i,1]-(TC[i+1]-TC[i]))^2, i = 1 .. 1000);%?

Error := 3423523.69275516

(1)

###############################################################
#
# Define procedure which does the same
# calculation as the above
#
  restart:
  lc:=proc( p::list )
          #
          # Declare/initialise local variables
          #
            local RT:= Array(1..3, p[4..6]),
                  TC:= Array(0...1001, fill=0),
                  N:= Array(1..3, [0, 0, 0]),
                  T:= Matrix( 3, 1001, [ Sample(Exponential(1/p[1]), 1001),
                                         Sample(Exponential(1/p[2]), 1001),
                                         Sample(Exponential(1/p[3]), 1001)
                                       ],
                              scan=columns
                            ),
                  z:= ImportMatrix("C:/Users/TomLeslie/DeskTop/TestData.csv"),
                  n, l, B;
          #
          # Ensure Statistics package is loaded
          #
            uses Statistics:
          #
          # Do calculations
          #
            for n to 1001 do
                l:= min[index](T[..,n]):
                N[l]:= N[l]+1;
                B[N[l], l]:= T[1, n]+RT[l];
                TC[n]:= TC[n-1]+B[N[l], l]
            end do:
          #
          # Return result
          #
            return add((z[i,1]-(TC[i+1]-TC[i]))^2, i = 1 .. 1000);
       end proc:
#
# Run the calculation with the same data
# as used in the above
#
  Error:=lc([3, 1, 0.5, 0.3, 1, 1.5])

Error := 3423523.69275516

(2)

 

 

Download randStuff.mws

@Bosco Emmanuel 

Use the following code

   restart:
#
# Define a procedure which will return
# a list of random numbers. Length of
# the list depends on the passed argument
#
   getSomeRands:= proc(n::posint)
                                           local r:=rand(-1.0..1.0):
                                           return [seq( r(), j=1..n)]:
                                 end proc:
   getSomeRands(10);

 

@Carl Love 

I thought that had been in Maple since the year dot!

Just for completeness I now feel morally obliged to produce the same two worksheets as in my earlier post, but this time without elementwise operators - and I'm now probably going for a lie-down.

restart:
#interface(imaginaryunit, errorbreak=0, errorcursor=true, #labelling=false):
#with(SolveTools);

# Investigating sets and expression sequences
#S:={q, w,e}:
S:=7,2,5:
whattype(S);
#L4:=convert(S,list):  #Doesn't work for expression sequences
L4:=[S]; # this converts the expression sequence to a list, L4
L4[3];   # outputs 3rd element of L4 which is 5
# End of investigation

#print(`Next part - solving two equations:  Ranj and height H given`);
#print(`To find angle of inclination, alfa, and velocity, V`);  
g:=9.81:Ranj:=80:H:=15:
L:=solve({4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), Ranj*g-V*sin(2*alfa)},{V, alfa}):  #::real}):
#L:=solve([4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), #Ranj*g-V*sin(2*alfa)],{V, alfa}):  #::real}):
# ::real, alfa::real:
#printf("L is of type %a", whattype(L));
#whattype(L);
#L2:=convert(L,list);  #gives error message
#L2:=[L]:
# L2;
# print(`Next:  To distinguish between real and complex solutions`);
# print(`Output in if statement is not working as expected.`);
# nops([L]);
# for i from 1 to nops([L]) do
#   if type(L[i],complex(float)) then
#         #if type(L[i],nonreal) then
#   printf("Complex solution for i=%d\n",i);
#                         else
#   printf("else part of if: i=%d\n",i);
#    print( L[i]);
#  end if;
# end do;  #for
#
##################################
# get the real solutions
#
# select( i->type~(rhs~(i),realcons)[], [L]);
#
  select( x-> `if`( map( type,
                         map(rhs, x),
                         realcons
                       )={true},
                    true,
                    false
                  ),
          [L]
        );

exprseq

L4 := [7, 2, 5]

5

[{V = 1193.173195, alfa = .3589084910}, {V = 1193.173195, alfa = -2.782684163}]

(1)

 

Download getReal3.mws

  restart;

  A:=[{a=1.0, b=2.0}, {a=3.0*I, b=4.0}];
#
# map(rhs,  ) works on the elements of A
# so for example map(rhs, A[2] ) is working
# on the second set and so *ought* to
# return the set {3.0*I, 4.0*I}
#
  map( rhs, A[2]);
#
# However one can use the 'map' command
# to iterate the above across all elements
# of A - which I'm assigning to B, just
# for convenience
#
  B:=map( i-> map(rhs, i),
          A
        );
#
# So this *ought* to return [{1.0, 2.0}, {4.0, 3.0*I}]
#

A := [{a = 1.0, b = 2.0}, {a = 3.0*I, b = 4.0}]

{4.0, 3.0*I}

B := [{1.0, 2.0}, {4.0, 3.0*I}]

(1)

#
# One can now essentially repeat this logical
# process using the map(type, argument, realcons),
# to check for cases where the rhs() is real,
# ie non-imaginary.
#
# So for each element of 'B'
#
  map( type, B[1], realcons);
  map( type, B[2], realcons);
#
# Again the use of the map() command, allows
# one to iterate over all the element of 'B'
#
  map( i -> map( type,
                 i,
                 realcons
               ),
       B
     );
#
# Now one doesn't have to compute B explicitly
# because actually it is given by
#
# map( i-> map(rhs, i),
#      A
#    );
#
# so the following will also work
#
   map( i-> map( type,
                 i,
                 realcons
               ),
        map( i -> map( rhs,
                       i
                     ),
             A
           )
      );

{true}

{false, true}

[{true}, {false, true}]

[{true}, {false, true}]

(2)

#
# This is starting to get a little "untidy", so
# one can define a separate function, which works
# directly on the elements of A, but does the
# same thing
#
  f:=x-> map( type,
              map( rhs, x),
              realcons
            );
  map(f, A);
#
# Note that this operation returns 'sets' containing
# {true}, {false}, {false, true}. However in order
# to use this successfully, one needs to return 'true'
# whenever one gets the set {true} and false for
# everything else, which can be achieved with
#
  g:=x-> `if`( map( type,
                    map( rhs, x),
                    realcons
                  )={true},
               true,
               false
             );
  map(g, A);

f := proc (x) options operator, arrow; map(type, map(rhs, x), realcons) end proc

[{true}, {false, true}]

g := proc (x) options operator, arrow; `if`(map(type, map(rhs, x), realcons) = {true}, true, false) end proc

[true, false]

(3)

#
# This still doesn't 'select' anything, so rather
# than using map() in the above, one needs the
# select() command. This will 'select' those
# elements of A which exactly returns 'true'
#
  select( g, A);
#
# or
#
  select( x-> `if`( map( type,
                         map( rhs, x),
                         realcons
                       )={true},
               true,
               false
             ),
          A
        );

[{a = 1.0, b = 2.0}]

[{a = 1.0, b = 2.0}]

(4)

 

Download toyExample2.mws

 

@das1404

that use of Maple 7 might cause an issue - and as I said I can't check this.

There are two worksheets attached.

The first is a "toy" example, saved with output, so that you can understand/test the 'logic' of the selection process. This *may* help you work out where the problem with the Maple 7 may be (and whether it might be fixable).

Whilst creating this, I realised that there was an error in my original suggestion (sorry, mea culpa, etc). It worked provided both variables in a solution were real, or both imaginary, but failed with an error if there was one of each. So the second worksheet contains the logically 'correct' version - which still may or may not work in Maple 7

  restart;

  A:=[{a=1.0, b=2.0}, {a=3.0*I, b=4.0}];
#
# rhs~() works on the elements of A
# so for example rhs~(A[2]) is working
# on the second set and so *ought* to
# return the set {3.0*I, 4.0*I}
#
  rhs~(A[2]);
#
# However one can use the 'map' command
# to iterate the above across all elements
# of A - whihc I'm assigning to B, just
# for convenience
#
  B:=map(rhs~, A);
#
# So this *ought* to return [{1.0, 2.0}, {4.0, 3.0*I}]
#

A := [{a = 1.0, b = 2.0}, {a = 3.0*I, b = 4.0}]

{4.0, 3.0*I}

B := [{1.0, 2.0}, {4.0, 3.0*I}]

(1)

#
# One can now essentially repeat this logical
# process using the type~(argument, realcons),
# to check for cases where the rhs() is real,
# ie non-imaginary.
#
# So for each element of 'B'
#
  type~(B[1], realcons);
  type~(B[2], realcons);
#
# Again the use of the map() command, allows
# one to iterate over all the element of 'B'
#
  map( type~, B, realcons);
#
# Now one doesn't have to compute B explicitly
# because actually is is given by map(rhs~, A)
# so the following will also work
#
  map( type~, map( rhs~, A), realcons);

{true}

{false, true}

[{true}, {false, true}]

[{true}, {false, true}]

(2)

#
# This is starting to get a little "untidy", so
# one can define a separate function, which works
# directly on the elements of A, but does the
# same thing
#
  f:=x-> type~(rhs~(x), realcons);
  map(f, A);
#
# Note that this operation returns 'sets' containing
# {true}, {false}, {false, true}. However in order
# to use this successfully, one needs to return 'true'
# whenever one gets the set {true} and false for
# everything else, which can be achieved with
#
  g:=x-> `if`( type~(rhs~(x), realcons)={true},
               true,
               false
             );
  map(g, A);

f := proc (x) options operator, arrow; `~`[type](`~`[rhs](x), realcons) end proc

[{true}, {false, true}]

g := proc (x) options operator, arrow; `if`(`~`[type](`~`[rhs](x), realcons) = {true}, true, false) end proc

[true, false]

(3)

#
# This still doesn't 'select' anything, so rather
# than using map() in the above, one needs the
# select() command. This will 'select' those
# elements of A which exactly returns 'true'
#
  select( g, A);
#
# or
#
  select( x-> `if`( type~(rhs~(x), realcons)={true},
                    true,
                    false
                  ),
          A
        );

[{a = 1.0, b = 2.0}]

[{a = 1.0, b = 2.0}]

(4)

 

Download toyExample.mws

restart:
#interface(imaginaryunit, errorbreak=0, errorcursor=true, #labelling=false):
#with(SolveTools);

# Investigating sets and expression sequences
#S:={q, w,e}:
S:=7,2,5:
whattype(S);
#L4:=convert(S,list):  #Doesn't work for expression sequences
L4:=[S]; # this converts the expression sequence to a list, L4
L4[3];   # outputs 3rd element of L4 which is 5
# End of investigation

#print(`Next part - solving two equations:  Ranj and height H given`);
#print(`To find angle of inclination, alfa, and velocity, V`);  
g:=9.81:Ranj:=80:H:=15:
L:=solve({4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), Ranj*g-V*sin(2*alfa)},{V, alfa}):  #::real}):
#L:=solve([4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), #Ranj*g-V*sin(2*alfa)],{V, alfa}):  #::real}):
# ::real, alfa::real:
#printf("L is of type %a", whattype(L));
#whattype(L);
#L2:=convert(L,list);  #gives error message
#L2:=[L]:
# L2;
# print(`Next:  To distinguish between real and complex solutions`);
# print(`Output in if statement is not working as expected.`);
# nops([L]);
# for i from 1 to nops([L]) do
#   if type(L[i],complex(float)) then
#         #if type(L[i],nonreal) then
#   printf("Complex solution for i=%d\n",i);
#                         else
#   printf("else part of if: i=%d\n",i);
#    print( L[i]);
#  end if;
# end do;  #for
#
##################################
# get the real solutions
#
# select( i->type~(rhs~(i),realcons)[], [L]);
#
  select( x-> `if`( type~(rhs~(x), realcons)={true},
                    true,
                    false
                  ),
          [L]
        );

exprseq

L4 := [7, 2, 5]

5

[{V = 1193.173195, alfa = .3589084910}, {V = 1193.173195, alfa = -2.782684163}]

(1)

 

Download getReal2.mws

 

You can use

showstat(commandName)

for many Maple commands, provided these are not 'built-in'. Be prepared to do a *lot* of reading!

Try showstat(tan) as an illustrative example

First 90 91 92 93 94 95 96 Last Page 92 of 207