tomleslie

13876 Reputation

20 Badges

15 years, 181 days

MaplePrimes Activity


These are replies submitted by tomleslie

is introducing all sorts of random stuff whihc makes your worksheet difficult to deal with

Upload the complete worksheet using the big green up-arrow in the toolbar for the MaplePrimes editor

I had some extra time this evening, so I tidied up ths worksheet (a lot!)

The answers are exactly the same as before: I just stripped out absolutely everything which was completely irrelevant, and slightly tidied the way that the equations to be solved were stored/accessed. I'm a great believer in keeping things as simple as possible. So the attached gives the same answer as my earlier post - just without a lot of irrelevant ........

restart; `ε` := 1.2; k := 1; M := 3

MyEqs := NULL; for i while i <= 2^(k-1)*M do x[i] := (i-.5)/(2^(k-1)*M); MyEqs := MyEqs, 3.464101616*a[1][1]+a[1][2]*(26.83281573*x[i]-13.41640786)+(.3*(a[1][0]+a[1][1]*(3.464101616*x[i]-1.732050808)+a[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)))*(b[1][0]+b[1][1]*(3.464101616*x[i]-1.732050808)+b[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988))-.2*e[1][0]-.2*e[1][1]*(3.464101616*x[i]-1.732050808)-.2*e[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)+.7*a[1][0]+.7*a[1][1]*(3.464101616*x[i]-1.732050808)+.7*a[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988) = .5, 3.464101616*b[1][1]+b[1][2]*(26.83281573*x[i]-13.41640786)-(.3*(a[1][0]+a[1][1]*(3.464101616*x[i]-1.732050808)+a[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)))*(b[1][0]+b[1][1]*(3.464101616*x[i]-1.732050808)+b[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988))+(.3*(b[1][0]+b[1][1]*(3.464101616*x[i]-1.732050808)+b[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)))*(C[1][0]+C[1][1]*(3.464101616*x[i]-1.732050808)+C[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988))+1.0*b[1][0]+1.0*b[1][1]*(3.464101616*x[i]-1.732050808)+1.0*b[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988) = 0, 3.464101616*C[1][1]+C[1][2]*(26.83281573*x[i]-13.41640786)-(.3*(b[1][0]+b[1][1]*(3.464101616*x[i]-1.732050808)+b[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)))*(C[1][0]+C[1][1]*(3.464101616*x[i]-1.732050808)+C[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988))+2.6*C[1][0]+2.6*C[1][1]*(3.464101616*x[i]-1.732050808)+2.6*C[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988) = 0, 3.464101616*e[1][1]+e[1][2]*(26.83281573*x[i]-13.41640786)-.4*C[1][0]-.4*C[1][1]*(3.464101616*x[i]-1.732050808)-.4*C[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)+(`&epsilon;`+.9)*(e[1][0]+e[1][1]*(3.464101616*x[i]-1.732050808)+e[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988)) = 0, 3.464101616*g[1][1]+g[1][2]*(26.83281573*x[i]-13.41640786)-`&epsilon;`*(e[1][0]+e[1][1]*(3.464101616*x[i]-1.732050808)+e[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988))+.7*g[1][0]+.7*g[1][1]*(3.464101616*x[i]-1.732050808)+.7*g[1][2]*(3.354101966*(2*x[i]-1)^2-1.118033988) = 0 end do; fsolve([MyEqs])

{C[1][0] = 2.105295203, C[1][1] = .2909548367, C[1][2] = -.3502342475, a[1][0] = 0.9889801377e-1, a[1][1] = 0.4274378516e-1, a[1][2] = 0.4516101720e-2, b[1][0] = 11.01185501, b[1][1] = -4.973895862, b[1][2] = .8941055143, e[1][0] = -0.9631802686e-1, e[1][1] = .3014882510, e[1][2] = -0.6671128517e-1, g[1][0] = -8.985367719, g[1][1] = 1.782331021, g[1][2] = -.1143622028}

(1)

``

Download solEqs2.mw

When combinng a matrix and a scalar, (without using elementwise operators) there is a discrepancy which is dependent on the matrix 'shape' option.

Summarising the attached

  1. if 'shape=diagonal' or 'shape=identity', forcing elementwise operation is never necessary
  2. if 'shape=triangular[lower]', then forcing elementwise operation is sometimes necessary
  3. if 'shape=triangular[lower, unit]' then forcing elementwise operation is always necessary

The above summary may be incomplete/wrong, becuase right now I'm confused as hell and i'm going for a lie down

  restart;

#
# With shape='identity' or 'diagonal' forcing
# elementwise operation when combining a Matrix
# and a scale is unnecessary
#
  M1:= Matrix(2, shape=identity):
  M1+1; # correct
  2*M1; # correct
  M2:=Matrix(2, shape=diagonal, fill=3):
  M2+1; # correct
  2*M2; # correct

Matrix(2, 2, {(1, 1) = 2, (1, 2) = 0, (2, 1) = 0, (2, 2) = 2})

 

Matrix(2, 2, {(1, 1) = 2, (1, 2) = 0, (2, 1) = 0, (2, 2) = 2})

 

Matrix(2, 2, {(1, 1) = 4, (1, 2) = 0, (2, 1) = 0, (2, 2) = 4})

 

Matrix(%id = 18446744074373121918)

(1)

#
# With shape=triangular (with/without the additional 'unit'
# suboption forcing elementwise operation always works - but
# on one operation (2*M4) it isn't necessary!!
#
  M3:= Matrix(2, shape=triangular[lower,unit], fill=5):
  M3+1;  # wrong - diagonal changes, lower entry doesn't
  2*M3;  # wrong - lower entry changes, diagonal doesn't
  M3+~1; # correct
  2*~M3; # correct

  M4:= Matrix(2, shape=triangular[lower], fill=5):
  M4+1;  # wrong - diagonal changes, lower entry doesn't
  2*M4;  # correct WTF!!!
  M4+~1; # correct
  2*~M4; # correct

Matrix(2, 2, {(1, 1) = 2, (1, 2) = 0, (2, 1) = 5, (2, 2) = 2})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 2, (1, 2) = 1, (2, 1) = 6, (2, 2) = 2})

 

Matrix(2, 2, {(1, 1) = 2, (1, 2) = 0, (2, 1) = 10, (2, 2) = 2})

 

Matrix(2, 2, {(1, 1) = 6, (1, 2) = 0, (2, 1) = 5, (2, 2) = 6})

 

Matrix(2, 2, {(1, 1) = 10, (1, 2) = 0, (2, 1) = 10, (2, 2) = 10})

 

Matrix(2, 2, {(1, 1) = 6, (1, 2) = 1, (2, 1) = 6, (2, 2) = 6})

 

Matrix(%id = 18446744074373109390)

(2)

#
# This group shows a discrpancy between
#
# shape=triangular[lower, unit] and
# shape=triangular[lower]
#
# when using the "long form" commands in the
# LinearAlgebra package
#
# This discrepancy also show up when using
# the 'dot' operator
#
  M3:=Matrix(2, shape=triangular[lower,unit], fill=5):
  LinearAlgebra:-Multiply(M3, 2); # wrong
  LinearAlgebra:-ScalarMultiply(M3, 2); # wrong
  LinearAlgebra:-MatrixScalarMultiply(M3, 2); # wrong
  2 . M3; # wrong
  M3 . 2; # wrong

  M4:= Matrix(2, shape=triangular[lower], fill=5):
  LinearAlgebra:-Multiply(M4, 2); # correct
  LinearAlgebra:-ScalarMultiply(M4, 2); # correct
  LinearAlgebra:-MatrixScalarMultiply(M4, 2); # correct
  2 . M4; # correct
  M4 . 2; # correct

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 10, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 10, (1, 2) = 0, (2, 1) = 10, (2, 2) = 10})

 

Matrix(2, 2, {(1, 1) = 10, (1, 2) = 0, (2, 1) = 10, (2, 2) = 10})

 

Matrix(2, 2, {(1, 1) = 10, (1, 2) = 0, (2, 1) = 10, (2, 2) = 10})

 

Matrix(2, 2, {(1, 1) = 10, (1, 2) = 0, (2, 1) = 10, (2, 2) = 10})

 

Matrix(%id = 18446744074373092526)

(3)

 


 

Download JMSanomaly.mw

@vv 

Consider the difference between

with(LinearAlgebra):
U:= Matrix(4,4, shape=triangular[upper, unit], symbol =u);
P:=-U;
P:=-~U;

Althhough the results are different, I don't find this behaviour surprising, and I'm not convinced that it is a "bug"

@Kitonum 

I'm not convinced this is a *bug*, although the associated help page could be clearer!

When OP specifies shape=triangular[upper, unit]  this forces at least (three) things

  1. upper triangle entries are "anything" and can be reassigned
  2. lower triangle entries are 0 and cannot be reassigned
  3. diagonal entries are 1 and cannot be reassigned

So in the code

with(LinearAlgebra):
U:= Matrix(4,4, shape=triangular[upper, unit], symbol =u);
U[3,1]:=1;
U[1,1]:=2;

both of these reassignments will cause errors

Error, attempt to assign to lower triangle of upper triangular rtable
Error, attempt to assign non-one to unit diagonal

Since the OP apparently *wants* to change reassign diagonal entries, shape=triangular[upper, unit] cannot be used

 

The simplest(?) way to get an upper traingular matrix, with reassignable entries on the diagonal is to use

with(LinearAlgebra):
U:= Matrix(4,4, shape=triangular[upper], symbol =u);
U[3,1]:=1;
U[1,1]:=2;

Now only the reassignment of an entry in the lower triangle will cause an error

 

If one wants to initialise the matrix as triangular, with initial (but reassignable) entries on the diagonal =1, the simplest way is probably

M:=Matrix(4,4, (i,j)-> `if`(i=j, 1, u[i,j]), shape=triangular[upper]);

 


 

fourteen equations in fifteen unknowns. Is this what you expect?

@Josolumoh 

I have just tried exporting a 20*512 matrix to both Excel (.xlsx' format) and text ('csv' format) using the followingnf and both work

   restart;
#
# Generate a 20 X 512 random Matrix
#
   M:= LinearAlgebra:-RandomMatrix(20,512);
#
# Export to Excel file - this works
#
   ExcelTools:-Export(M, "C:/Users/TomLeslie/Desktop/test.xlsx", "sheet1", "B2");
#
# Export to text file in csv format - this works
#

   ExportMatrix( "C:/Users/TomLeslie/Desktop/test.csv", M, target=csv);

Obviously you have to change the file_path to something appropriate for your machine

but if you have something which is in (more-or-less) Excel format then ExcelTools:-Import() will import it.

I can only suggest that you upload the file you want to import to Maple  to this site, using the big green up-arrow in the Mapleprimes toolbar, so that responders might get some idea of what works and what doesn;t

a System Error, or a Maple Error

Suggest that you

  1. Copy/paste the exact error message here
  2. Post worksheet using the big green up-arrow in the MaplePrimes toolbar

you could try typing into Maple and attempting a solution. If this fails, then you could try posting the relevant worksheet here

@Gabriel samaila 

to revise the code I supplied earlier to solve for the cases in your Table, ie

Pr =10, eta=0.5, Ec=0.01,R=1, Nb=0.1, Nt =0.1
Ha=[0, 2, 4, 6]
Sc=[0.5, 1, 2]

This will supply the necessary values of phi(y), theta(y), v(y).

However the Table is captioned "effect of Schmitt number on Concentration" which doesn't tell me how the Table entries are computed from the information available (ie phi(y), theta(y), v(y).)

You will need to supply the relevant function of phi(y), theta(y), v(y), and the value of 'y' which produces the Table entries

but is it what you want???

I have no idea what you are trying to achieve.with this data and hence I have no idea of the form in which you need the data for further processing -only you know this!

A list of things which *could* be done, in no particular order

  1. Declare the matrix as 6*6: you can now populate with values for x[1, 5], x[1, 6], x[5, 1], x[5, 6], x[6, 1], x[6, 5] . Other values in the matrix would be unknown eq x[1,1], x[1,2] etc or you could easily set them to zero, one or anything convenient. Does that make any sense?
  2. Use a 3*3 matrix and subtract 3 from any index value greater than 3, so x[1,5]->x[1,2], x[1,6]->x[1,3], x[5,1]->x[2,1] etc. Possible, but does it make any sense?
  3. The matrix generated on the first pass through the loop was 4*4, and has been already been populated. Add two rows and two columns to this matrx, populate the new positions with values from the second pass through the loop. You end up with a 6*6 matrix with pretty much all off-diagonal elements assigned. Does that make any sense??
  4. Something lse which makes sense????

 

@sand15 

  restart;
  fapp:= x^(2)+423*x^(3)/3+6789*x^(4)/4;
  fexact:=sin(x)/x;
  eval( abs(fapp-fexact), x=2);
  evalf(%);

This returns 28288-sin(2)/2 as an exact answer, which is 28287.54535 as a floating point approx

In turn this agrees with the answer returned by maximize() and NLPSolve()

 

 

@JAMET 

your original code contains F(3) but does not contain B(3), although it does contain B3. Easily fixed, see the attached - I also recommend checking out vv's solution


 

restart;
A002487:= proc(m)
               local a, b, n;
               option remember;
               a:= 1; b:= 0; n:= m;
               while 0 < n do
                     if   type(n, odd)
                     then b:= a+b
                     else a:= a+b
                     end if;
                     n:= floor((1/2)*n)
               end do;
               b
          end proc:

listeinverse:= proc(L::list)
                    local i;
                    [seq(op(nops(L)-i, L), i = 0 .. nops(L)-1)]
               end proc:

Brocot:= proc(n)
              local c, i, L, M, r;
              L:= NULL;
              r:= 2^n;
              L:= [seq(A002487(i), i = 0 .. r)];
              M:= listeinverse(L);
              c[0]:= 0, 1/cat(0);
              for i to r do
                  c[i]:= L[i]/M[i]
              end do;
              c[r+1]:= 1/cat(0);
              return [seq(c[i], i = 1 .. r+1)], r+1
        end proc:

F:= proc(N)
         local a, b, L; L:= NULL;
         L:= sort([op({seq(seq(a/b, a = 0 .. b), b = 1 .. N)})]);
         return L, nops(L)
    end proc:

for i from 0 to 4 do
    B || i:= Brocot(i)
end do;
 
F(1); F(2); F(3); F(4);

rang:=proc(M,a)
           local i:
           for i from 1 to nops(M)-1 do
               if   M[i]=a
               then return(i)
               fi
           od
      end:

rang(F(3)[1], 2/3);
rang(B3[1], 2/3);

[0, 1/`0`], 2

 

[0, 1, 1/`0`], 3

 

[0, 1/2, 1, 2, 1/`0`], 5

 

[0, 1/3, 1/2, 2/3, 1, 3/2, 2, 3, 1/`0`], 9

 

[0, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 1, 4/3, 3/2, 5/3, 2, 5/2, 3, 4, 1/`0`], 17

 

[0, 1], 2

 

[0, 1/2, 1], 3

 

[0, 1/3, 1/2, 2/3, 1], 5

 

[0, 1/4, 1/3, 1/2, 2/3, 3/4, 1], 7

 

4

 

4

(1)

 

 


 

Download newProc.mw

@izhammulya 

the way Maple's random number generators work, one gets the same "random" numbers every time the same code executes, becuase the seed for the random number generator remains the same. (Useful for debug purposes). Now I can get around this by using a randomize() command at the top of your worksheet, because this randomizes the seed as well  (probably based on the system clock?). This has the drawback that you will get a different answer from me - whic can make debug tricky.

Anyhow I used tha randomize() command and the first value of 'a' which contained no symbols was a := [0, 1, 1, 1, 2, 2], which from your response *seems* to be a valid(?) input for subsequent code.

The first time the loop executes with the above definition of 'a' it generates values for

x[1, 2], x[1, 3], x[1, 4], x[2, 1], x[2, 3], x[2, 4], x[3, 1], x[3, 2], x[3, 4], x[4, 1], x[4, 2], x[4, 3]

and uses these values to populate a 4 X 4 matrix

The second time the loop executes, it generates values for

x[1, 5], x[1, 6], x[5, 1], x[5, 6], x[6, 1], x[6, 5]

and then attempts to insert these in a 3 X 3 matrix.  Rather obviously, this is going to fail: after all where would you use (say) x[5,6] in a 3 X 3 matrix????

 I really  can't work out what you are trying to achieve.

First 73 74 75 76 77 78 79 Last Page 75 of 207