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 answers submitted by Doug Meade

Like this?

restart;
R := (x::posint) -> [A,B,C,D,E,F,G,H,I,J][trunc(x/10)+1]:
R(29);
                                      C

Note that Maple defines D as the differentiation operator, but the others should be unassigned Maple names. You should probably modify this to check that the input is between 0 and 99, and  handle inputs outside these bounds appropriately. But, those are details that you need to address for your assignment.

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

You need to be using plotsetup. Here's an example; see the online help for plotsetup and for plot/device for full explanations of the arguments and what else might be possible. Note that the files created by this loop are placed in the folder whose name is in currentdir(); If you want them to go someplace special, this can be done with currentdir (just be sure you get all the slashes going the proper way). The plotsetup outside the loop is needed to prevent Maple for continually replacing the last file created with any plots created outside the loop.

for k from 1 to 2 do
  plotsetup( jpeg, plotoutput=`plot`||k||`.jpg`, plotoptions="height=200,width=320" );
  plot( x^k, x=-1..1 );
end do;
plotsetup( default );

Of couse, you will want to replace the plot with the plots you are creating.

I hope you find this useful,

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

This may not be exactly what you are requesting, but maybe it will be of some use.

Maple's contour plot commands can fill in the regions between level curves on a surface. I like to use contourplot3d more than contourplot (both in the plots package), but they both accept the same arguments. Here's an example of what I can get:

with( plots ):
eq := x*z-y^2;
                                         2
                                  x z - y 
contourplot3d( solve( eq, z ), x=-2..2, y=-2..2,
               view=-2..2, contours=[$(-2..2)], filledregions=true,
               axes=boxed, orientation=[-90,0], grid=[70,70] );

You can change the domains to fit your needs. Note that the vertical dimension is specified with view (you can't use z) and this is coordinated with the explicit list of contours. You can play with these to, hopefully, come closer to meeting your needs.

This is a 3D plot (in Maple) so you can use the mouse to view it from different angles.

If you don't  like these colors, you should use the coloring option, e.g., coloring=[white,blue]

I note that filledregions can be shortened to filled.

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

In principle, your problem is a system of 16 quartic equations. While it might be possible to find an explicit solution to this problem, it's my guess that it will be so long and complicated that it will be of almost no use.

First question: What do you hope to do with the solution, assuming it can be found?

Would you accept an approximate solution? Numerical? Expansion? (A numeric approximation is possible only if you can provide numeric values for the other parameters in the problem.)

Myabe it's possible to get what you want without actually finding a solution. Knowing more about your problem could help us to provide more helpful responses.

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

Knowing the result that you are looking for, here's one way to get there.

ex1 := C10*C20*a^2+2*C10*C20*a*b+C10*C20*b^2-m*u^2*a*C10+m*u^2*b*C20
       +1/2*e1*e2*a^2+e1*e2*a*b+1/2*e1*e2*b^2;

ex2 := convert( factor( [selectremove( has, ex1, u )] ), `+` );
            1        2                          2                
            - (a + b)  (e1 e2 + 2 C10 C20) - m u  (a C10 - C20 b)
            2                                                    

And, to check that this is correct,

simplify( ex2-ex1 );
                                      0

What this does is to recognize that the terms can be split into two separate parts, those that involve u and those that don't.

q1 := [selectremove( has, ex1, u )];
[    2            2        
[-m u  a C10 + m u  b C20, 
[                          

           2                            2   1        2               1        2
  C10 C20 a  + 2 C10 C20 a b + C10 C20 b  + - e1 e2 a  + e1 e2 a b + - e1 e2 b 
                                            2                        2         

  ]
  ]
  ]

Maple can factor each of these subexpressions.

q2 := factor( q1 );
           [    2                  1        2                    ]
           [-m u  (a C10 - C20 b), - (a + b)  (e1 e2 + 2 C10 C20)]
           [                       2                             ]
                                       
Then we put them back together as a sum.
q3 := convert( q2, `+` );

            1        2                          2                
            - (a + b)  (e1 e2 + 2 C10 C20) - m u  (a C10 - C20 b)
            2         

It would not surprise me if others come up with other approaches to this.

Asking Maple to see this splitting might be a little too much to expect. Maple is powerful, but it can't always work magic.

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

 

Or, more simply, with convert:

map( convert, [G], list );
   [[" ", 4], [".", 1], ["I", 1], ["a", 1], ["b", 1], ["d", 1], ["e", 3], 
     ["g", 1], ["h", 2], ["o", 1], ["s", 1], ["t", 2], ["v", 1]]

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

Everything looks good to me, after adding with( LinearAlgebra ): and changing matrix to Matrix. Now, to actually see the matrix, you do have to also add interface( rtablesize=20 ): . You can hit the matrix with evalf if you want to see the numerical values of the coefficients.

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

It's unfortunate that zip works only with two lists. It would be nice if you could use, say,

zip( (a,b,c)->[a,b,c], A, B, C );

but you can't. In light of this, my next suggestion would be to construct the table one column at a time:

c1 := [$0..n];
c2 := [coeff(q,R,k)$k=0..n];
c3 := [...];;
Transpose(Matrix( [c1,c2,c3] ));

This can be streamlined as follows.  For the original two-column table:

<  <`'n'`,`---`,($0..n)>
 | <`a[n]`,`---`,(coeff(q,R,k)$k=0..n) >;

A third column can now be added to this with:

< % | <` c3 `,`---`,(column 3)>;

Or, all three columns can be constructed at once with

<  <`'n'`,`---`,($0..n)>
 | <`a[n]`,`---`,(coeff(q,R,k)$k=0..n) >
 | <`...`,`---`,(column 3)> >;

Note that my original suggestion using coeffs is not quite correct because you cannot assume the coefficients are returned in order (look closely at the results of my original post).

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

 

Is this what you want?

interface( rtablesize=20 );                  # to be able to see the final matrix
n := 15:
q := add( a||k*R^k, k=0..n );                # construct the original expression
c := coeffs(q,R);                            # extract the coefficients
t := zip( (a,b)->[a,b], [$0..n], [c] );      # form the rows of the table
< <`'n'`|`a[n]`>,<`---`|`---`>, Matrix(t) >; # and the final table (with headers)

Of coruse, as you understand what this does, it can be condensed into a single command, or a proc.

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

 

I think I understand your confusion. You need to be careful about what you call a function. In general, a function is a rule, like

y := x->-(x-6)-0.01*(x-6)^3:

When you refer to y(x), this is the value of the function y when it's evaluated at x. This could be a number or another expression.

If you want to use

G:=(x,y)->D(y)(x)*x/y(x)

Then you have to remember that y needs to be a function. (I am still uncertain how you expect to use the second argument of the function g or G.)

Based on what you have written I now believe you have hit upon the correct way to implement your function. What you want is a function that accepts the market demand (y) and returns the elasticity function (with two independent variables).

You should not be looking for type function. You want to be looking for type procedure.

Here's how I put all of this together. Note how E is a mapping that returns another mapping.

E := (y::procedure) -> (x,z)->D(y)(x)*x/z:

E(y);
          D(y)(x) x
(x, z) -> ---------
              z    
E(y)(x,z);
                           /                 2\  
                           \-1 - 0.03 (x - 6) / x
                           ----------------------
                                     z           
E(z);
Error, invalid input: E expects its 1st argument, y, to be of type procedure, but received z


If you want to have the elasticity function as a standalone name, you could use:

e1 := E(y);
          D(y)(x) x
(x, z) -> ---------
              z    
e1(x,z);
                           /                 2\  
                           \-1 - 0.03 (x - 6) / x
                           ----------------------
                                     z           

Is this helpful, and moving closer to what you want to do?

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

Think about what your definition is asking Maple to do.

When you ask for g(6,7), Maple sees: diff(7(6),6)*6/7

Now, 7(6) is OK. It's the constant function 7 evaluated at 6, that is, 7.

The problem is that Maple cannot differentiate with respect to a constant. This explains the error message that you report.

Now, how should you define your function?

I'm not sure. I don't really understand what you are trying to do. What really confuses me is when y refers to the function y(x) and when y is an independent variable.

Is this what you are trying to do?

y := x->-(x-6)-0.01*(x-6)^3;
                                                   3
                         x -> -x + 6 - 0.01 (x - 6) 
G := (x,z)->D(y)(x)*x/z;
                                       D(y)(x) x
                             (x, z) -> ---------
                                           z    
G(6,7);
                                -0.8571428571

In this, the references to y refer to the previously defined function y and I use z for the second variable in the function definition.

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

 

When Maple simply spits back a plotting command like this, it suggests to me that Maple does not know the command you are using. In this case, spacecurve is a command in the plots package. If you execute with( plots ): before your command, you will see the picture. (You can also replace spacecurve with plots:-spacecurve.) Implement either of these changes and the plot appears.

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

One of the new features in Maple 12 is the ability to create plots with two different scales. Here are three examples from ?plots[dualaxisplot]. Note that the second one is an animation. Very nice, even though I'm not sure these plots have a whole lot of meaing in and of themselves.

dualaxisplot(plot(x^2, x = 0 .. 10, labels = [x, x^2], legend = x^2), plot(x^3, x = 0 .. 10, color = blue, labels = [x, x^3], legend = x^3));

dualaxisplot(animate(plot, [A*x^3, color = blue, labels = [x, x^3]], A = 0 .. 1), plot(x^2, labels = [x, x^2]));

dualaxisplot(inequal({x-y <= 1, 0 < x+y}, x = -3 .. 3, y = -3 .. 3, optionsexcluded = (color = white)), conformal(z^2, z = 0 .. 2+2*I));
 

I hope this is helpful.

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

I can't see your matrix because I do not have the xls file.

The matrix is 5000 x 2. Your description says each row is a close price and the stock number. How do you get the year from this? Is the first occurrence 2005, the second 2006, etc?

If you can show us a little more of your problem, I'm sure we can find a good solution.

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

This could be a situation where Maple's flexible table indexing can be used effectively.

I'm not going to make too many comments about the importing of data from the Excel spreadsheet. Let's start with the data being represented as follows:

STOCK[A,2005] := 200:
STOCK[A,2006] := 300:
STOCK[B,2005] := 100:
STOCK[B,2006] := 150:

From here we can create a Maple Matrix with each stock in a column and each year in a row:

S := <
  < ``, seq( yy, yy=map2(op,2,{indices(STOCK)}) ) > |
  seq( < ss, seq( STOCK[ss,yy], yy=map2(op,2,{indices(STOCK)}) ) >,
         ss=map2(op,1,{indices(STOCK)}) )
>;

[       A   B  ]
[ 2005 200 100 ]
[ 2006 300 150 ]

You also talk about computing the return. Here's one way that this can be done:

S := < S, < `return` | S[3,2..]-S[2,2..] > >;
[         A   B  ]
[  2005  200 100 ]
[  2006  300 150 ]
[ return 100  50 ]

If you now add some more data to the system, the same commands can be used to update the matrix.

STOCK[C,2005] := 125:
STOCK[A,2007] := 310:

S := <
  < ``, seq( yy, yy=map2(op,2,{indices(STOCK)} ) ) > |
  seq( < ss, seq( STOCK[ss,yy], yy=map2(op,2,{indices(STOCK)}) ) >,
         ss=map2(op,1,{indices(STOCK)}) )
>;

S := < S, < `return` | S[3,2..]-S[2,2..] > >;


More rows can be appended in a similar manner. With a little work you can control how empty entries are displayed and processed.

I wish it was possible to easily include matrix output in MaplePrimes.

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 25 26 27 28 29 30 31 Last Page 27 of 44