## 3023 Reputation

18 years, 207 days

Doug

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

## no if...

The previous answers assume there are only 2 columns. Here's the same thing, with increasing powers in additional columns.

`Matrix( 5, 3, (i,j)->i^(j+1) );`
`Array( 5..14, 1..2, (i,j)->i^(j+1) );`

Doug

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

## use display...

From some quick tests, it appears as though listplot3d prints only one matrix at a time. If it's first argument is a list of lists/matrices, these are concatentated before printing. So, to produce a plot of more than one matrix, I'd recommend creating a separate plot for each matrix and then use the display command (also in the plots package) to combine the separate plots into a single combined plot,

For example:

`LL := [[1, 2], [3, 4], [5, 6], [7, 8]]:M := convert( LL, Matrix ):display(   listplot3d( LL, color = "LightBlue"),   listplot3d( 2*M, color = "Green"));`

You might alos want to take a look at the matrixplot command (also in the plots package).

Doug

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

## try unapply and ~...

I'd suggest using unapply to create a function out of BResponseCoefficient. The fact that it's piecewise is irrelevant.

To be a little more specific I'll use the definition of BResponseCoefficient from your post (but I note that your last condition on the second term looks to me as there something might not be exactly as you intended):

`BRC := piecewise( t>=0 and t<0.15, 1.1+11*t, t<=0.7, 2.75, t>0.7, 1.92/t )      *piecewise( t>=0 and t<0.7, 1, t<4, 0.852+0.212*t, t>=4, 1.7 ):fBRC := unapply( simplify(BRC), t );   # ask Maple to simplify the product into a single piecewisetlist := <(\$0..100)/10.>:              # vector of values of t to be used in the table of function valuesflist := fBRC~(tlist):                 # vector of function valuesinterface( rtablesize=200 ):           # increase size of matrices that Maple siill display (default is 10)<tlist|flist>;                         # two-column table of function values`

I hope this is close to what you are wanting to do.

Doug

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

## convert,bytes...

If you are asking how to convert the list of "bytes" back to characters, you use the same command used to convert the text into bytes:

`"Hello";      "Hello"convert( %, bytes );      [72, 101, 108, 108, 111]convert( %, bytes );      "Hello"`

Doug

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

## select / remove...

Using assumptions can work, but sometimes does not give exactly what you might desire.

My preferred way to do this is to let Maple give me all of the solutions and then to select the ones I want or to remove the ones I don't want. The commands used to do this are select and remove, respectively.

 > restart;
 > S := solve( x^4=1, x ); (1)
 > select( is, [S], positive )[];  # select all positive roots (2)
 > remove( has, [S], I )[];  # remove all complex-valued roots (3)
 > selectremove( has, [S], I ); # separate complex-valued and real-valued roots (4)
 >

Sometimes there is no simple Maple command to do the selection. In these cases the first argument must be a Maple procedure that evaluates to true or false for each element of the second argument. Here's an example that selects all solutions with a non-positive imaginary part (note the use of evalf to get the root in a form where Maple knows if the imaginary part is positive or negative).

 > S := solve( x^3+x-1=0, x ); (5)
 > evalf([S]); (6)
 >
 > select( x->Im(x)<=0, [S] )[];  # Maple needs help to decide the sign of the imaginary part
 >
 > select( x->evalf(Im(x))<=0, [S] )[];  # select roots whose imaginary part is <=0 (7)
 >
 >

I hope this is useful.

Doug

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

## Two possibilities...

The best way to control what fits on one line is to control the width of that line. Two ways in which this can be done are

1. widen the worksheet window
2. decrease the size of the font

Both still have their limitations, but can be useful in some situations. Unfortunately, this affects the entire worksheet. It's not possible to use different settings for different parts of a worksheet.

Nothing fancy, but this has worked for me at times.

I do take issue with your comment that deleting output deletes associated variables. Changes in the worksheet have no effect on the status of the worksheet until they are executed.

Doug

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

If I understand your question, you want the user to enter the sum of two complex numbers, in polar form. If this is correct, the two commands you need to know are polar and evalc (and also convert).

I'll first demonstrate with jwatkins' example:

 > x := 1+5*I:
 > y := 2-3*I:
 > xP := polar( x ); (1)
 > yP := polar( y ); (2)
 > xP+yP; (3)
 > evalc( xP+yP ); (4)
 >

So, for the specific example in your original post:

Note that it is necessary to enter the angle as 10*degrees for convert to be able to convert this to radians.

In Maple TA, you could have separate input fields for the r and theta, or you could ask them to enter them as an ordered pair in one input field. Unless you want to require users to include *degrees when their angle is in degrees, you will need to be explicit about whether you expect input in degrees or radians.

I hope this has been helpful.

 > x := polar( 10, convert( 30*degrees, radians ) ); (5)
 > y := polar( 15, convert(-10*degrees, radians ) ); (6)
 > evalc( x+y ); (7)
 >

Because the results of these computations are so rarely "nice", you may have to work with floating-point numbers; evalf will provide a numeric approximation - then you have to decide how close you expect the user's input to be.

Doug

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

## A combined approach using subs...

My personal favorite is a combination is Kitonum's and Preben's approaches.

`eq := (-Omega^2*a*A-Omega^2*m*B+Omega*A*c+B*k)*cos(Omega*t)+(Omega^2*a*B-Omega^2*m*A-Omega*B*c+A*k)*sin(Omega*t) = 0:`
`subs({sin(Omega*t)=1, cos(Omega*t)=0}, lhs(eq));   # coefficient of sin(Omega*t)subs({sin(Omega*t)=0, cos(Omega*t)=1}, lhs(eq));   # coefficient of cos(Omega*t)`

The benefit I see to this approach is that it is easily extended to cases with other occurrences of sin and cos. Preben's approach lumps all sin terms together and all cos terms togehter. Kitonum's approach can be modified for this, but requires the introduction of a new name for each term. Here's a quick example showing what I would do:

`eq := A*sin(a*t) + B*cos(a*t) + C*sin(2*a*t) + D*exp(-t) = 0:`
`eval( lhs(eq), [sin=1, cos=0, exp=0] );  # example where Kitorum's approach fails          A + Csubs( [sin(a*t)=1, cos(a*t)=0, sin(2*a*t)=0, exp(-t)=0], lhs(eq) );   # my approach          A`
`subs( [sin(a*t),cos(a*t),sin(2*a*t),exp(-t)]=~[1,0,0,0], lhs(eq) );     # my approach, with ~ operator          A`
`MyCoeffs := proc( expr, Tlist ) local Clist,Ulist; Clist := NULL; Ulist := [1,0\$nops(Tlist)-1]; to nops(Tlist) do   Clist := Clist, subs( Tlist=~Ulist, expr );   Ulist := ListTools:-Rotate( Ulist, -1 ); end do; return Clistend proc;`
`s1,c1,s2,e1 := MyCoeffs( lhs(eq), [sin(a*t),cos(a*t),sin(2*a*t),exp(-t)] );          s1, c1, s2, e1 := A, B, C, D`

I do have to admit that there are cases where any of these approaches could fail.

I should also point out the coeff is designed for polynomial expressions (of one variable) but coeffs is the corresponding command for multinomial expressions. There are lots of times when coeffs is more useful (and powerful) than coeff.

Doug

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

## axis, labels, and tickmarks - oh my!...

I encourage you to post a specific example, then we can give you some explicit pointers. Until then, I think you'll find the axis, labels, and tickmarks options of use. You can find all of these (and many others) in the help page for plot3d,options, or look directly at plot,axis and plot,tickmarks.

Doug

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

The showstat command is useful for looking at the implementation of almost any Maple procedure. In this case, because you've already loaded the Student[NumericalAnalysis] package, all you have to type is

 > >
 > showstat( Secant );
 Student:-NumericalAnalysis:-Secant := proc({method::identical(secant) := 'secant'})    1   return Student:-NumericalAnalysis:-Roots(args,(':-method') = method) end proc

This shows that this command is actually a special case of the Roots command (also in the same package). You know what to do to see the definition of Roots. Be forewarned that Roots can do a lot; it's more than 400 lines of Maple code (and so has been omitted from this post).

 > showstat( Roots );
 >

To address your question about getting more information from Secant, I suggest looking at the online help. If you try ?Secant, you will find informaiton about a Tutor for the secant method (maybe this will be of some interest to you?). You can find the NumericalAnalysis Secant in the list of related commands in the left-hand side of the Help window - or you can ask for help for Student,NumericalAnalysis,Secant. Once you are looking at this information, open the Options section and look at the different options for output=. I think you might like what you get with output=information:

 > > > > Secant(f, x = [2.7, 3.2], tolerance = 10^(-2), output = information) (1)

You might find other combinations of options that provide slightly different and more useful information, depending upon your ultimate needs and uses for this information.

I hpe this has been helpful.

Doug

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

## only in 3D plots...

plot3d allows for colors to be specified via a procedure. If there is no other solution, you could create your point plot as a 3D plot and specify the orientation so that it appears as a 2D plot.

See the help for plot3d,colorfunc for details about how to specify a color function. Then plot3d,options for information about the orientation option.

If all goes well, you might be able to use plottools,transform to convert your 3D plot to a 2D plot. I do not know if this will retain the coloring from the 3D plot.

If you provide us with some additional details about what you are doing, includiing the points you want to plot and the parameter used to produce the coloring, maybe one of us can put these ideas into practice for you.

Doug

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

## Use the typeset command...

plot( x^2, caption = typeset("A plot of %1.", x^2) );

See the Maple help for plots,typesetting for more details and examples.

Doug

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

## colon and ...

Sure. Here's how I would do this:

`GenerateMatrix( eqns, [x(t),y(t)] ):      # the colon suppresses all output%                                      # % is the last result, and  selects the second object`

If you use this it would be best to have both commands in the same execution group. If you don't, there's a chance ou execute the second command sometime without executing the GenerateMatrix command immediately before it. Then the output would be different.

I would assign the results to names, for example:

`GM := GenerateMatrix( eqns, [x(t),y(t)] ):ans := GM;`

Doug

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

## VolumeOfRevolution (in Student[Calculus1...

Have you looked at the VolumeOfRevolution command in the Student[Calculus1] package?

This single command can handle most of the typical examples encountered by calculus students. Here's a quick demo from your problem:

 > with( Student[Calculus1] ):
 > VolumeOfRevolution( x, x^2+1, x=0..2, output=animation ); >
 > VolumeOfRevolution( x, x^2+1, x=0..2, output=integral ); (1)
 >
 > VolumeOfRevolution( x, x^2+1, x=0..2, output=sum ); (2)
 > VolumeOfRevolution( x, x^2+1, x=0..2, output=value ); (3)
 >
 > map~(p->VolumeOfRevolution( x, x^2+1, x=0..2, output=p), integral=value ); (4)
 >

Doug

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

## so close...

The OP was very close to getting the desired answer. The problem is best described as a classic mismatch between analytic and numerical methods.

`a := 1; w0 := 1; w1 := 3; K := 10; h0 := .25; A := 3; alpha := .7; b := .6; c := .2;f := A*x^(b*alpha)*(alpha*A*x^(b*alpha)/(a+w0*h0+(x-h0)*w1))^(alpha/(1-alpha))-(alpha*A*x^(b*alpha)/(a+w0*h0+(x-h0)*w1))^(1/(1-alpha)):`
`M := maximize(f, x = 0 .. 1):0.8295280335`

The result from maximize is an approximation. When this maximum value is passed to solve, Maple tries to find a symbolic solution to this numeric problem. Maybe it should know better, but I'm not surprised that it did not get an answer. It would make more sense, at least to me, to use fsolve:

`fsolve(f = M, x);`

But this just returns unevaluated. Why? Because this maximum value is approximate. If it's ever so slightly larger than the exact maximum, then there truly is not a solution to this equation. As has been suggested by other responders, this value is accurate only to a few digits. Let's through away a few digits from the maximum value:

`fsolve(f = .829528, x);0.5357195187`
`fsolve(f = .82952803, x); 0.5354902012`
`fsolve(f = .829528033, x); 0.5355263036`
`fsolve(f = .8295280333, x); 0.5355353790`
`fsolve(f = .8295280334, x) 0.5355415721`
`fsolve(f = .8295280335, x);`

I don't know if it's realistic to expect Maple to do any better than this. It's not a black box, and it can answer only the questions that are posed to it - not the ones that we hope it understands that we are asking.

```---------------------------------------------------------------------