Robert Israel

6577 Reputation

21 Badges

18 years, 210 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are replies submitted by Robert Israel

This code is iterative, not recursive.

A recursive function would call itself (with different inputs)

An iterative function contains a loop: in this case

while Err > s do ... end do

It's not limited, you can use it instead of readline if you wish.  As far as I know, the only difference between the two is in what happens when the end of a file is reached.

You can indeed assign any procedure to a different name.  Unfortunately you had a multiplication sign * after FileTools (I suspect you had a space there, and 2D Math interpreted that as multiplication).  Another reason to avoid 2D Math.  But

> f:= FileTools[Text][ReadLine]

should work fine.

It's not limited, you can use it instead of readline if you wish.  As far as I know, the only difference between the two is in what happens when the end of a file is reached.

You can indeed assign any procedure to a different name.  Unfortunately you had a multiplication sign * after FileTools (I suspect you had a space there, and 2D Math interpreted that as multiplication).  Another reason to avoid 2D Math.  But

> f:= FileTools[Text][ReadLine]

should work fine.

question 2) The simplest way is probably to import the data into Maple, producing a Matrix, and then use LinearAlgebra[Transpose].

question 3) I don't know, but it would be easy to select the odd-numbered rows in Maple

question 4)

b:= FileTools[ListDirectory]("E:/New Folder", returnonly="*.jpg");

You can further filter the results.  For example, if you want only the files in the list b with today's date:

> with(StringTools):
  today:= FormatTime("%Y%m%d"):
  select(f -> (FormatTime("%Y%m%d",timestamp=FileTools[ModificationTime]
     (cat("E:/New Folder/",f)))=today), b);

 

 

 

question 2) The simplest way is probably to import the data into Maple, producing a Matrix, and then use LinearAlgebra[Transpose].

question 3) I don't know, but it would be easy to select the odd-numbered rows in Maple

question 4)

b:= FileTools[ListDirectory]("E:/New Folder", returnonly="*.jpg");

You can further filter the results.  For example, if you want only the files in the list b with today's date:

> with(StringTools):
  today:= FormatTime("%Y%m%d"):
  select(f -> (FormatTime("%Y%m%d",timestamp=FileTools[ModificationTime]
     (cat("E:/New Folder/",f)))=today), b);

 

 

 

It usually works when the worksheet contains only text and 1D input (no 2D math or output).  In this case the Maple commands come out fine, but the embedded formulas come out as raw Typesetting structures.

 

 

It usually works when the worksheet contains only text and 1D input (no 2D math or output).  In this case the Maple commands come out fine, but the embedded formulas come out as raw Typesetting structures.

 

 

Yes, we can (for numerical values of the parameters).  You might e.g. look at www.math.ubc.ca/~israel/m210/lesson5b.mw for an example of using Newton's method.

Yes, we can (for numerical values of the parameters).  You might e.g. look at www.math.ubc.ca/~israel/m210/lesson5b.mw for an example of using Newton's method.

As I said, it's unlikely that there is a closed-form solution.  So if by "solution" you mean a formula yo can write down, you're out of luck.  If you give numerical values to the parameters St[L}, St[S] and nu, you can get a numerical solution using fsolve.  For example:

> eq:=St[L]/exp(lambda^2)/erf(lambda)-St[S]/nu/exp(nu^2*lambda^2)/erfc(nu*lambda) 
     = lambda*Pi^(1/2);
  fsolve(eval(eq, {St[L]=1, St[S]=1,nu=1}), lambda = 0 .. 1);

             .3777597882

You can also plot the solutions.  Since there are four parameters, I'll make an animation where nu corresponds to time.

> with(plots):
  animate(implicitplot3d, [eq, St[S]=0..4, St[L]=0..4, lambda=-2..2,
     style=patchnogrid, grid=[30,30,30]],
   nu=0.001 .. 2, axes=box, orientation=[50,-80]);

Or you could try a series expansion.  For example:

> series(RootOf(eq,lambda),St[L]);

series(1/2*nu*Pi^(1/2)/St[S]*St[L]+1/8*nu^2*Pi^(1/2)*(-4*nu*St[S]-2*Pi*nu)/St[S]^3*St[L]^2+(-1/96*nu^3*Pi^(1/2)*(-48*nu^2*St[S]^2+8*St[S]^2*Pi-12*nu^2*Pi*St[S]^2-24*Pi^2*nu^2-96*nu^2*Pi*St[S])/St[S]^5)*St[L]^3+1/768*nu^4*Pi^(1/2)*(256*nu*St[S]^3*Pi-352*nu^3*Pi*St[S]^3-240*nu^3*Pi^2*St[S]^2+128*St[S]^2*Pi^2*nu-384*nu^3*St[S]^3-1440*nu^3*Pi^2*St[S]-1920*nu^3*St[S]^2*Pi-240*Pi^3*nu^3)/St[S]^7*St[L]^4+(-1/15360*nu^5*Pi^(1/2)*(1600*nu^2*Pi^2*St[S]^4-6720*Pi^4*nu^4-1200*nu^4*Pi^2*St[S]^4-76800*nu^4*St[S]^3*Pi-7680*nu^4*St[S]^4-512*St[S]^4*Pi^2-53760*nu^4*Pi^3*St[S]+12800*nu^2*St[S]^4*Pi+19200*nu^2*St[S]^3*Pi^2-32640*nu^4*Pi^2*St[S]^3-120960*nu^4*Pi^2*St[S]^2-16640*nu^4*Pi*St[S]^4-10080*nu^4*Pi^3*St[S]^2+4800*St[S]^2*Pi^3*nu^2)/St[S]^9)*St[L]^5+O(St[L]^6),St[L],6)

As I said, it's unlikely that there is a closed-form solution.  So if by "solution" you mean a formula yo can write down, you're out of luck.  If you give numerical values to the parameters St[L}, St[S] and nu, you can get a numerical solution using fsolve.  For example:

> eq:=St[L]/exp(lambda^2)/erf(lambda)-St[S]/nu/exp(nu^2*lambda^2)/erfc(nu*lambda) 
     = lambda*Pi^(1/2);
  fsolve(eval(eq, {St[L]=1, St[S]=1,nu=1}), lambda = 0 .. 1);

             .3777597882

You can also plot the solutions.  Since there are four parameters, I'll make an animation where nu corresponds to time.

> with(plots):
  animate(implicitplot3d, [eq, St[S]=0..4, St[L]=0..4, lambda=-2..2,
     style=patchnogrid, grid=[30,30,30]],
   nu=0.001 .. 2, axes=box, orientation=[50,-80]);

Or you could try a series expansion.  For example:

> series(RootOf(eq,lambda),St[L]);

series(1/2*nu*Pi^(1/2)/St[S]*St[L]+1/8*nu^2*Pi^(1/2)*(-4*nu*St[S]-2*Pi*nu)/St[S]^3*St[L]^2+(-1/96*nu^3*Pi^(1/2)*(-48*nu^2*St[S]^2+8*St[S]^2*Pi-12*nu^2*Pi*St[S]^2-24*Pi^2*nu^2-96*nu^2*Pi*St[S])/St[S]^5)*St[L]^3+1/768*nu^4*Pi^(1/2)*(256*nu*St[S]^3*Pi-352*nu^3*Pi*St[S]^3-240*nu^3*Pi^2*St[S]^2+128*St[S]^2*Pi^2*nu-384*nu^3*St[S]^3-1440*nu^3*Pi^2*St[S]-1920*nu^3*St[S]^2*Pi-240*Pi^3*nu^3)/St[S]^7*St[L]^4+(-1/15360*nu^5*Pi^(1/2)*(1600*nu^2*Pi^2*St[S]^4-6720*Pi^4*nu^4-1200*nu^4*Pi^2*St[S]^4-76800*nu^4*St[S]^3*Pi-7680*nu^4*St[S]^4-512*St[S]^4*Pi^2-53760*nu^4*Pi^3*St[S]+12800*nu^2*St[S]^4*Pi+19200*nu^2*St[S]^3*Pi^2-32640*nu^4*Pi^2*St[S]^3-120960*nu^4*Pi^2*St[S]^2-16640*nu^4*Pi*St[S]^4-10080*nu^4*Pi^3*St[S]^2+4800*St[S]^2*Pi^3*nu^2)/St[S]^9)*St[L]^5+O(St[L]^6),St[L],6)

e represents the position in the rtable Out where you want to place the first entry that you get by
merging In[a..b] and In[c..d].  That is, the minimum of In[a] and In[c] will go into Out[e]. 

 

 

e represents the position in the rtable Out where you want to place the first entry that you get by
merging In[a..b] and In[c..d].  That is, the minimum of In[a] and In[c] will go into Out[e]. 

 

 

You might try

> [seq](readline("word.txt"),i=1..11);

The difference is that this produces one output, a list, while your for loop produces 11 separate outputs.

Or you could use

> ImportVector("word.txt", datatype=string);

which, as the name implies, produces a Vector.  The advantage here is that you don't need to know how many lines are in the file.

You might try

> [seq](readline("word.txt"),i=1..11);

The difference is that this produces one output, a list, while your for loop produces 11 separate outputs.

Or you could use

> ImportVector("word.txt", datatype=string);

which, as the name implies, produces a Vector.  The advantage here is that you don't need to know how many lines are in the file.

First 64 65 66 67 68 69 70 Last Page 66 of 187