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

JADO, It is POSSIBLE to do this. The difficulty depends on exactly what types of objects will appear in the indices. Here is a rough implementation:
index4 := proc(var,ind)
  ``[ind[3]]^ind[1]*var[ind[4]]^ind[2]
end proc;
This implementation has trouble when a superscript is 1. There are ways to overcome this, but others are better at knowing all possible problems and the most efficient way to implement this. If you have some objects that should always be displayed in this format, you will want to define a print procedure for that object. For example, here is how you might use index4 to display a hypergeometric function:
HH := myfunc([a, b], [c, d]):
HH;
`print/myfunc` := proc ()
  index4(H, [op(args[1]), op(args[2])])
end proc
HH;
I also just noticed that Maple 10 has a Typesetting package. See ?Typesetting, or select Typesetting Rules under the View menu (in the standard interface). Is this a start to what you want? Doug ------------------------------------------------------------------ Prof. Douglas B. Meade Phone: (803) 777-6183 Department of Mathematics URL: http://www.math.sc.edu/~meade/ USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Jean Jacques, I believe you can do most of what you request with implicitplot3d from the plots package and transform and project from the plottools package. See the online help on these topics for more detail about what I about to suggest. >> Given, for example >> >> f(x,y,z) = x*y*z >> >> defined on x=0..1, y=0..1, z=0..1; >> >> I want >> >> 1. to implicitplot3d the function f for >> >> f(x,y,z)= 1, 1/2, 1/4, 1/8, 1/16, 1/32, ..., 1/2^10 An obvious first attempt here is: > restart; > with(plots); > with(plottools); > > F := x*y*z; > eqs := [ F = 2^(-k) $ k = 0 .. 10]; > > ImplPlot := implicitplot3d(eqs, x = 0 .. 1, y = 0 .. 1, z = 0 .. 1, > axes = boxed, style = patchnogrid, color = [red, blue, green, yellow, > magenta, cyan, wheat, pink, orange, sienna, gold]); > display(ImplPlot); You should experiment with the options. In particular, numpoints and style. Note the context menu (right mouse button) provides control the style (and other options) for individual surfaces. >> 2. to see the previous graphics only when (x>y ∧ y>z) The first idea I thought of was to insert the constraints on x,y, and z in the definition of the plot window. While this does not work, it is worthwhile to pursue this option a little further. In this case it is possible to solve each equation explicitly for z: > eqs2 := map(solve, eqs, z); These equations can then be plotted, with plot3d, on the triangle 1 > x > y > 0: > plot3d(eqs2, x = y .. 1, y = 0 .. 1, view = [DEFAULT, DEFAULT, 0 .. 1], > axes = boxed, style = patchnogrid, color = [red, blue, green, yellow, > magenta, cyan, wheat, pink, orange, sienna, gold]); This option exists only when the functions are simple enough to provide explicit formulae for the level surfaces. A second option is to use the transform procedure from the plottools package. Note that the procedure created by transform operates directly on a plot data structure. > RegionCutOff := transform((x, y, z) -> > `if`(y < x and z < y, [x, y, z], [undefined, undefined, undefined]) ); > > CutOffPlot := RegionCutOff(ImplPlot); > display( CutOffPlot ); To address the general case I find it instructive to think of the domain as a part of the function definition: > G := proc(x, y, z) > if not( x::numeric and y::numeric and z::numeric ) then > return 'procname'( args ) > end if; > if x>y and y>z then > return x*y*z > else > FAIL > end if; > end: > > eqs3 := [ G(x, y, z) = 2^(-k) $ k = 0 .. 10 ]; > ImplPlot2 := implicitplot3d(eqs3, x = 0 .. 1, y = 0 .. 1, z = 0 .. 1, > numpoints = 10000, axes = boxed, style = patchnogrid, color = [red, blue, > green, yellow, magenta, cyan, wheat, pink, orange, sienna, gold]); > display(ImplPlot2); >> 3. to CONTOURPLOT each "level" of f(x,y,z) obtained in 2 on the >> plane (x,y),(x,z) and (y,z). The transform procedure can be used to create the projections on the three coordinate planes: > ProjXY := transform((x, y, z) -> [x, y, 0]): > ProjXZ := transform((x, y, z) -> [x, 0, z]): > ProjYZ := transform((x, y, z) -> [0, y, z]): > > display([ProjXY(ImplPlot2), > ProjYZ(ImplPlot2), > ProjXZ(ImplPlot2), > ImplPlot2]); The project procedure (also in plottools) provides a different approach to implementing these projections: > display([project(ImplPlot2, [[0, 0, 0], [0, 1, 0], [1, 0, 0]]), > project(ImplPlot2, [[0, 0, 0], [1, 0, 0], [0, 0, 1]]), > project(ImplPlot2, [[0, 0, 0], [0, 1, 0], [0, 0, 1]]), > ImplPlot2]); I'm not completely certain these are exactly what you are looking for, but they should give you a start. I hope this has been helpful. Doug
Tom is correct - we need to see the logic behind the question to be able to explain this behavior. My recommendation is to locate the appropriate question bank (a .qu file). Open this file with your favorite text editor. Extract the lines in the file that define this question. Save this excerpt to a new file and post this file to MaplePrimes. Note that the attached screenshot gives the correct response as "null". I will be interested to see why this is the case. I will also be interested in seeing if any assumptions have been made about the format of the user response. Doug
This is, essentially, the same question that came up earlier this week in the forum "Digits in proc". I'll summarize that discussion here and let you read yesterday's posting for the full explanation. The problem is that Maple is trying to evaluate the function value in the plot command before it has specific values for Iatest and U_test. Your question really should be "How do I prevent Maple from evaluating the function before it has values for the arguments?" Glad you asked! Here are two solutions: 1. plot the function, i.e. omit all references to the variables
> Output_Curve_test:=plot3d([0,0,iL_RMS_func_Ue_const],0..2,0..1):
> Output_Curve_test;
(Note also that you most likely want to suppress the output from this command. Change the end of command terminator to a colon (:). To see the plot, enter the command Output_Curve_test.) 2. change the definition of the procedure to return "unevaluated" when the arguments are not numeric
> iL_RMS_func_Ue_const:=proc(Ia_IaLGmax_f,Ua_Ue)
>   if not (Ia_IaLGmax_f::numeric and Ua_Ue::numeric) then
>      return 'procname'(args)
>   end if;
>   eval(iL_RMS_AVG(Ue_input,Ua_Ue*Ue_input,
>                   Ia_IaLGmax_f*Ue_input/(8*L_input)*T_input,
>                   L_input,T_input,0));
> end proc;
I have not tested these, but they should work. Again, see my posting in the "Digits in proc" forum for more details. I hope this helps, Doug ---------------------------------------------------------------- Prof. Douglas B. Meade Phone: (803) 777-6183 Department of Mathematics URL: http://www.math.sc.edu/~meade/ USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
David, Here is your code - with a few modifications - and then the necessary additions to create the plots that I believe you have requested. Comments are included in the code.
> restart:
> with( plots ):   # needed for the pointplot and display commands
> Digits := 30:
> f :=x-> x^2-a:
> #df :=x-> 2*x:
> df := D(f);      # more general def of derivative (as a function)
                         df := x -> 2 x

> DATA := NULL:            # init data structure to hold all results
> for a from 1 to 6 do
>   x0 := trunc(sqrt(a)):
>   for j from 1 to 5 do
> #    x1 := x0 - f(x0)/df(x0);
> #    x0 := x1;
>      x0 := x0 - f(x0)/df(x0);   # no need for intermediate x1
>   end:
>    rsd := f(x0);                # moved outside the inner loop
>   DATA := DATA, [ a, x0, rsd ]; # put results in data structure
> #  printf(`%3.10f\t %3.10e\n`, x0,rsd):
> end:
At this point DATA is an expression sequence consisting of lists of triples (a, x0, and rsd) for each value of a. This data looks best - and almost like what you had in your original code - when it is displayed as a Maple Matrix. Here are two possible views that use this approach:
> mDATA := convert([DATA],Matrix);
         [           [   886731088897             1            ]  
mDATA := [[1, 1, 0], [2, ------------, ------------------------], 
         [           [   627013566048  393146012008229658338304]  

  [   708158977          1         ]             
  [3, ---------, ------------------], [4, 2, 0], 
  [   408855776  167163045568562176]             

  [   57780789062419261441                     1                   ]  
  [5, --------------------, ---------------------------------------], 
  [   25840354427429161536  667723916935157870722535619367981879296]  

  [   4250272665676801                 1               ]]
  [6, ----------------, -------------------------------]]
  [   1735166549767840  3010802955433229967557898265600]]
> convert(evalf[10]([['a','x0','rsd'],DATA]),Matrix);
              [a       x0              rsd       ]
              [                                  ]
              [1.      1.              0.        ]
              [                                  ]
              [                               -24]
              [2.  1.414213562  2.543584240 10   ]
              [                                  ]
              [                               -18]
              [3.  1.732050808  5.982183422 10   ]
              [                                  ]
              [4.      2.              0.        ]
              [                                  ]
              [                               -39]
              [5.  2.236067977  1.497624953 10   ]
              [                                  ]
              [                               -31]
              [6.  2.449489743  3.321373118 10   ]
Now, to create the plots. The first step is to create a list of ordered pairs of data:
> DATAax0 := [seq( [d[1],d[2]], d=DATA )];
           [        [   886731088897]  [   708158977]          
DATAax0 := [[1, 1], [2, ------------], [3, ---------], [4, 2], 
           [        [   627013566048]  [   408855776]          

  [   57780789062419261441]  [   4250272665676801]]
  [5, --------------------], [6, ----------------]]
  [   25840354427429161536]  [   1735166549767840]]
> DATAarsd := [seq( [d[1],d[3]], d=DATA )];
            [        [              1            ]  [           1         ]  
DATAarsd := [[1, 0], [2, ------------------------], [3, ------------------], 
            [        [   393146012008229658338304]  [   167163045568562176]  

          [                      1                   ]  
  [4, 0], [5, ---------------------------------------], 
          [   667723916935157870722535619367981879296]  

  [                  1               ]]
  [6, -------------------------------]]
  [   3010802955433229967557898265600]]
Maple's pointplot command can be used, but I find it easier to use the basic plot with s_tyle=point. (As noted in previous posts, "s_tyle" needs to be replaced with "style" in the actual code.) Both of these are illustrated below.
> display( [ pointplot( DATAax0, color=blue, legend="x0" ),
>            pointplot( DATAarsd, color=red, legend="residual" ) ],
>          title="Two point plots with pointplot" );
> plot( [DATAax0,DATAarsd], s_tyle=point,
>       color=[blue,red], legend=["x0","residual"],
>       title="Two point plots with plot" );
From here I think you should be able to customize the appearance to your specific needs. I hope this has been helpful. Doug ----------------------------------------------------------------- Prof. Douglas B. Meade Phone: (803) 777-6183 Department of Mathematics URL: http://www.math.sc.edu/~meade/ USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
MBP, There are at least two issues involved in your question. First, values assigned to Digits must be integers. Second, you have to understand Maple's evaluation rules. To make the value of Digits an integer, use trunc, round, floor, or ceil as appropriate. (See ?trunc for help on all 4 functions.) The evaluation problem requires a little more background. When you write myproc(x) in the plot command, Maple fully evaluates the arguments. In this case, myproc(x) - with x as a name. Try it. This gives the error message from Digits. The assignment to Digits must be avoided when x is not a numeric value.) This problem does not arise in the seq command because seq does not evaluate its arguments until a specific value of x is provided. So, what can you do? First, you can plot the FUNCTION myproc (and not the VALUE myproc(x)). The appropriate command would be:
plot( myproc, x=2..20 );
Second, you can modify the definition of myproc to return unevaluated when the argument is not numeric. Here is a common way to implement this:
> myproc := proc(x)
>  if not x::numeric then return 'procname'(args) end if;
>  Digits := trunc(x);
>  evalf(sqrt(x))
> end proc;
And, here are some examples showing how myproc works (plots omitted):
> myproc(2);
                              1.4
> myproc(2.3);
                              1.5
> myproc(x);
                           myproc(x)
> seq( myproc(x), x=2..20 );
1.4, 1.73, 2., 2.2361, 2.44949, 2.645751, 2.8284272, 3., 3.162277660, 

  3.3166247904, 3.46410161514, 3.605551275464, 3.7416573867739, 

  3.87298334620742, 4., 4.1231056256176605, 4.24264068711928515, 

  4.358898943540673552, 4.4721359549995793928
> plot( myproc, 2..20 );

> plot( myproc(x), x=2..20 );
I'm not sure what you expect to see in this plot. There is not enough resolution to see any influence from the Digits. Of course, there are other situations where this would be visible. I hope this is of some use to you, Doug P.S. Maple veterans might be disappointed that I made it through this entire posting without any references to premature evaluation. Oops. -------------------------------------------------------------------- Prof. Douglas B. Meade Phone: (803) 777-6183 Department of Mathematics URL: http://www.math.sc.edu/~meade/ USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
David, Can you provide more details about your problem? A simple example with explicit definitions for f and g (and xa) would be most helpful. The basic approach to a problem like this is to define a Maple procedure to evaluate the constraint (initial condition), g(y(0),ya)=0, as a function of ya and then use fsolve to find a numerical solution to the equation G(ya)=0. This is similar to the ideas used to implement the shooting method. There are a variety of Maple implementations of the shooting method in the Applications Center. I wrote a PowerTool for ODEs (http://www.maplesoft.com/applications/app_center_browse.aspx?CID=14&SCID=120, see Lesson 17) as well as a separate Shooting Method implementation (http://www.mapleapps.com/Info.asp?ArticleID=132). I have to go teach right now. I'll return to this later today, unless someone else beats me to it. Doug ------------------------------------------------------------------ Prof. Douglas B. Meade Phone: (803) 777-6183 Department of Mathematics URL: http://www.math.sc.edu/~meade/ USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
First 42 43 44 Page 44 of 44