Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are replies submitted by Doug Meade

This is not quite an accepted proof, but it does fulfill your request "how do I get Maple to show 2^(1/2)/3?". Except, I think the correct value is 2/3^(1/2). My approach is to let Maple make a numerical approximation and then use identify to find the corresponding closed-form expression that has this approximation.

a := 2/sqrt(n+2)-2/sqrt(n+3);
                              2              2      
                         ------------ - ------------
                                (1/2)          (1/2)
                         (n + 2)        (n + 3)     
S := sum( a, n=1..infinity );
                    infinity                             
                     -----                               
                      \                                  
                       )    /     2              2      \
                      /     |------------ - ------------|
                     -----  |       (1/2)          (1/2)|
                     n = 1  \(n + 2)        (n + 3)     /

evalf( S );
                                 1.154700538
identify( % );
                                  2  (1/2)
                                  - 3     
                                  3       

I think identify is a pretty neat command. I've used it several times in other situations like this. I've not shown it to my colleagues, but students think it's pretty handy.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

Only 10 years? It's taken me 20 years to get to this level. Of course, Maple could not have done this 20 years ago either.  It's all a matter of evolution - of software and user knowledge. If you hang around the Maple community for a reasonable period of time you'll be surprised how much you will learn.

I'm glad  you found my work useful. I'm just waiting for someone else to show me even better ways to get the same results. I am, in fact, hoping someone can suggest some improvements - that's how I'll maximize my knowledge gain from this exercise.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Only 10 years? It's taken me 20 years to get to this level. Of course, Maple could not have done this 20 years ago either.  It's all a matter of evolution - of software and user knowledge. If you hang around the Maple community for a reasonable period of time you'll be surprised how much you will learn.

I'm glad  you found my work useful. I'm just waiting for someone else to show me even better ways to get the same results. I am, in fact, hoping someone can suggest some improvements - that's how I'll maximize my knowledge gain from this exercise.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Hmm. A response that I wrote late last night did not appear. I'll be I just didn't hit Post comment. That's just as well, as this morning I came up with a much better response. The ideas are all the same as what I posted yesterday. There are some details that required some work. I think you will like what I have been able to do. Download the ZIP archive attached to this message.

Download 178_My-Data.zip
View file details

Extract the contents (2 files) and open the Maple worksheet. It might take about 30 seconds to execute the entire worksheet. If you do so, double-click on the final matrix (S5) to see what I have created.

When you go back and read the worksheet's details you will see that I have included some timings of different implementations of some of the steps.

I will post more snippets of code, but none of the matrix output is easily viewable through these posts. Bummer!

Here's the general approach:

Read in the data from an excel file

A:=ExcelTools:-Import("My-Data.xls", "FTSE-250");

Create a price table and construct the matrix with each stock in a separate column. If there is no price for a specific month, that stock's entry will be a 0.

for r in $1..Nr do
  STOCK[trunc(A[r,5]),trunc(A[r,1])] := A[r,4]
end do:
myS := (ss,yy,default) -> `if`(assigned(STOCK[ss,yy]),STOCK[ss,yy],default):
S := <
  < ``, seq( yy, yy=map2(op,2,{indices(STOCK)}) ) > |
  seq( < ss, seq( myS(ss,yy,0), yy=map2(op,2,{indices(STOCK)}) ) >,
         ss=map2(op,1,{indices(STOCK)}) )
>;

Add a row with the total return for each stock.

TotRet := proc( s )
  local i0;
  uses ArrayTools;
  i0 := SearchArray( s );
  return s[i0[-1]]-s[i0[1]]
end proc:
TotRet( S[2..,2] );
S3 := < S,
       < `tot return` , <seq( TotRet( S[2..,c] ), c=2..253 )> >^%T
      >;

The details are all in the worksheet. You should download the ZIP archive as it also contains the Excel spreadsheet from which all of the data is obtained. If you keep the worksheet and spreadsheet in the same folder, you should not have to change anything in the worksheet.

I'm sure you could now export the matrix I have constructed back into an Excel spreadsheet. I have not tried this, yet.

One suggestion I hope the developers will hear is that it would be very empowering if it was possible to do work in the worksheet while the matrix browser was running. As it is, you have to close the matrix browser window to pass control back to the spreadsheet. This appears to be very similar to the limitation that control cannot be passed between Maplet windows, but I digress.

Comments, questions, and suggestions are greatly appreciated.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

Hmm. A response that I wrote late last night did not appear. I'll be I just didn't hit Post comment. That's just as well, as this morning I came up with a much better response. The ideas are all the same as what I posted yesterday. There are some details that required some work. I think you will like what I have been able to do. Download the ZIP archive attached to this message.

Download 178_My-Data.zip
View file details

Extract the contents (2 files) and open the Maple worksheet. It might take about 30 seconds to execute the entire worksheet. If you do so, double-click on the final matrix (S5) to see what I have created.

When you go back and read the worksheet's details you will see that I have included some timings of different implementations of some of the steps.

I will post more snippets of code, but none of the matrix output is easily viewable through these posts. Bummer!

Here's the general approach:

Read in the data from an excel file

A:=ExcelTools:-Import("My-Data.xls", "FTSE-250");

Create a price table and construct the matrix with each stock in a separate column. If there is no price for a specific month, that stock's entry will be a 0.

for r in $1..Nr do
  STOCK[trunc(A[r,5]),trunc(A[r,1])] := A[r,4]
end do:
myS := (ss,yy,default) -> `if`(assigned(STOCK[ss,yy]),STOCK[ss,yy],default):
S := <
  < ``, seq( yy, yy=map2(op,2,{indices(STOCK)}) ) > |
  seq( < ss, seq( myS(ss,yy,0), yy=map2(op,2,{indices(STOCK)}) ) >,
         ss=map2(op,1,{indices(STOCK)}) )
>;

Add a row with the total return for each stock.

TotRet := proc( s )
  local i0;
  uses ArrayTools;
  i0 := SearchArray( s );
  return s[i0[-1]]-s[i0[1]]
end proc:
TotRet( S[2..,2] );
S3 := < S,
       < `tot return` , <seq( TotRet( S[2..,c] ), c=2..253 )> >^%T
      >;

The details are all in the worksheet. You should download the ZIP archive as it also contains the Excel spreadsheet from which all of the data is obtained. If you keep the worksheet and spreadsheet in the same folder, you should not have to change anything in the worksheet.

I'm sure you could now export the matrix I have constructed back into an Excel spreadsheet. I have not tried this, yet.

One suggestion I hope the developers will hear is that it would be very empowering if it was possible to do work in the worksheet while the matrix browser was running. As it is, you have to close the matrix browser window to pass control back to the spreadsheet. This appears to be very similar to the limitation that control cannot be passed between Maplet windows, but I digress.

Comments, questions, and suggestions are greatly appreciated.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

If you are using 2D Maple Input (the default, out of the box) you can use Maple's implied multiplication in your problem. To do this there has to be a space between the two terms in the numerator.

As you have written the expression, with no space, Maple interprets the parentheses as function evaluation not multiplication. Thi sis what Maple's output shows: the function exp(-x) evaluated at (exp(x)-1) minus the constant function 1 evaluated at the same argument. Maple does simplify the constant function to the constant. Here are both approaches for your comparison.

> (exp(-x)-1)(exp(x)-1)/(exp(-x)-exp(x));              # function evaluation
                          (exp(-x))(exp(x) - 1) - 1
                          -------------------------
                              exp(-x) - exp(x)     

> (exp(-x)-1)*(exp(x)-1)/(exp(-x)-exp(x));             # multiplication
                         (exp(-x) - 1) (exp(x) - 1)
                         --------------------------
                              exp(-x) - exp(x)     
  
> normal((6));
                                 exp(x) - 1
                                 ----------
                                 exp(x) + 1

This might be I have replied to a post that encourages someone to use Maple Notation with an explanation of how to do something using 2D Math Notation. To avoid any possible confusion I, personally, would recommend using the * as Alex suggests.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

If you are using 2D Maple Input (the default, out of the box) you can use Maple's implied multiplication in your problem. To do this there has to be a space between the two terms in the numerator.

As you have written the expression, with no space, Maple interprets the parentheses as function evaluation not multiplication. Thi sis what Maple's output shows: the function exp(-x) evaluated at (exp(x)-1) minus the constant function 1 evaluated at the same argument. Maple does simplify the constant function to the constant. Here are both approaches for your comparison.

> (exp(-x)-1)(exp(x)-1)/(exp(-x)-exp(x));              # function evaluation
                          (exp(-x))(exp(x) - 1) - 1
                          -------------------------
                              exp(-x) - exp(x)     

> (exp(-x)-1)*(exp(x)-1)/(exp(-x)-exp(x));             # multiplication
                         (exp(-x) - 1) (exp(x) - 1)
                         --------------------------
                              exp(-x) - exp(x)     
  
> normal((6));
                                 exp(x) - 1
                                 ----------
                                 exp(x) + 1

This might be I have replied to a post that encourages someone to use Maple Notation with an explanation of how to do something using 2D Math Notation. To avoid any possible confusion I, personally, would recommend using the * as Alex suggests.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

The number of roots for an equation is a challenge, in general. If the equation is a polynomial, then the fundamental theorem of algebra tells us the degree is the number of roots - including complex roots and repeated roots. There are some other cases where you can do some analysis to find the number of roots. This does not get very far in most cases. Oftentimes plots are helpful to suggest what you can hope to be able to prove: monotonicity (in the function or a derivative), concavity, ....

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

The number of roots for an equation is a challenge, in general. If the equation is a polynomial, then the fundamental theorem of algebra tells us the degree is the number of roots - including complex roots and repeated roots. There are some other cases where you can do some analysis to find the number of roots. This does not get very far in most cases. Oftentimes plots are helpful to suggest what you can hope to be able to prove: monotonicity (in the function or a derivative), concavity, ....

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Sure. This answer should help clarify any questions about why Robert's solution works.

Instead of defining dT as in my earlier post, let's define T as a function of t:

T := eval(T(t),solL):

Now, to find the time when T(t)=400, use:

fsolve( T=400, 0..50 );
                                 6.089149028

And, the crtical point can be found with:

fsolve( D(T)=0, 0..50 );
                                 27.36040182

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Sure. This answer should help clarify any questions about why Robert's solution works.

Instead of defining dT as in my earlier post, let's define T as a function of t:

T := eval(T(t),solL):

Now, to find the time when T(t)=400, use:

fsolve( T=400, 0..50 );
                                 6.089149028

And, the crtical point can be found with:

fsolve( D(T)=0, 0..50 );
                                 27.36040182

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Robert,

I got caught up trying to put arguments on the function and the range. While I knew how to work with a function in plot, I didn't apply the same logic to fsolve.

Thanks for showing us the simplicity of this approach.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Robert,

I got caught up trying to put arguments on the function and the range. While I knew how to work with a function in plot, I didn't apply the same logic to fsolve.

Thanks for showing us the simplicity of this approach.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

More can be done with the numeric solution returned by dsolve,numeric.

Alex's graph is helpful to see that T does have a maximum. But, exactly where does it occur? For this we do want to plot the derivative of T.

restart;
with( plots ):
ode1:=diff(T(t),t)=-125*diff(c(t),t)-0.434:
ode2:=diff(c(t),t)=-0.01725*(c(t)^2)*exp(-2660*(1/T(t)-1/300)):
ic1:=T(0)=300.15:
ic2:=c(0)=2:
sys:={ode1,ode2,ic1,ic2};
        /                          d              / d      \          
       { T(0) = 300.15, c(0) = 2, --- T(t) = -125 |--- c(t)| - 0.434, 
        \                          dt             \ dt     /          

          d                      2    /  2660   133\\ 
         --- c(t) = -0.01725 c(t)  exp|- ---- + ---| }
          dt                          \  T(t)   15 // 
solL:=dsolve(sys,numeric,output=listprocedure):
dT := D(eval(T(t),solL)):
plot( dT, 0..50 );

 

And now zoom in to see that the critical point occurs near t=27.36.

plot( dT, 27..30 );

sol(27.36);
    [t = 27.37, T(t) = 530.089296499127840, c(t) = 0.0654569880069777038]

It's possible, but somewhat cumbersome, to get the derivative in a form where fsolve can be used to approximate the location of this maximum.
 

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

More can be done with the numeric solution returned by dsolve,numeric.

Alex's graph is helpful to see that T does have a maximum. But, exactly where does it occur? For this we do want to plot the derivative of T.

restart;
with( plots ):
ode1:=diff(T(t),t)=-125*diff(c(t),t)-0.434:
ode2:=diff(c(t),t)=-0.01725*(c(t)^2)*exp(-2660*(1/T(t)-1/300)):
ic1:=T(0)=300.15:
ic2:=c(0)=2:
sys:={ode1,ode2,ic1,ic2};
        /                          d              / d      \          
       { T(0) = 300.15, c(0) = 2, --- T(t) = -125 |--- c(t)| - 0.434, 
        \                          dt             \ dt     /          

          d                      2    /  2660   133\\ 
         --- c(t) = -0.01725 c(t)  exp|- ---- + ---| }
          dt                          \  T(t)   15 // 
solL:=dsolve(sys,numeric,output=listprocedure):
dT := D(eval(T(t),solL)):
plot( dT, 0..50 );

 

And now zoom in to see that the critical point occurs near t=27.36.

plot( dT, 27..30 );

sol(27.36);
    [t = 27.37, T(t) = 530.089296499127840, c(t) = 0.0654569880069777038]

It's possible, but somewhat cumbersome, to get the derivative in a form where fsolve can be used to approximate the location of this maximum.
 

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed
First 36 37 38 39 40 41 42 Last Page 38 of 76