acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Optimization:-Maximize(f, x = 0 .. 1, method = branchandbound);

                [0.829528033419476, [x = 0.535545765963319]]

That x value is a few ulps off I think, correct to 9 decimals, given your original expression f computed with floating-point coefficents. You can set Digits higher (say, 30 or higher) and pick up more accurate digits on that x value, for that given f, if you need it. I doubt that higher accuracy has much meaning here, since it doesn't look like you care that the coefficients in your f are being computed coarsely up front.

Consider the power of exact computing here,



a := 1:

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)):``

NULL

NULL

`assuming`([simplify(combine(f))], [x > 0]);

(2646/625)*x^(7/5)*525^(1/3)*(-1+15*x)/(1+6*x)^(10/3)

max(solve(diff(%, x)));

17/60+(1/60)*229^(1/2)

evalf[20](%);

.53554576584035926545

``

Download maximum_exact.mw

You could also have used the `location` option of the `maximize` command. maximum_fl.mw

And with those exact rational parameters you can also evaluate at the found maximum (or use `maximize`). maximum_exact2.mw

acer

Is this helpful?


restart

assume(varepsilon > 0)

H := Matrix(3, 3, {(1, 1) = 0, (1, 2) = -epsilon, (1, 3) = epsilon, (2, 1) = -epsilon, (2, 2) = 2-2*epsilon, (2, 3) = 0, (3, 1) = epsilon, (3, 2) = 0, (3, 3) = 2+2*epsilon})

H := Matrix(3, 3, {(1, 1) = 0, (1, 2) = -varepsilon, (1, 3) = varepsilon, (2, 1) = -varepsilon, (2, 2) = 2-2*varepsilon, (2, 3) = 0, (3, 1) = varepsilon, (3, 2) = 0, (3, 3) = 2+2*varepsilon})

with(LinearAlgebra):

evals, evecs := Eigenvectors(H):

e1 := convert(simplify(series(evals[1], varepsilon = 0, 4)), polynom)

2+2*varepsilon+(1/2)*varepsilon^2-(7/16)*varepsilon^3

e2 := convert(simplify(series(evals[2], varepsilon = 0, 4)), polynom)

-varepsilon^2

e3 := convert(simplify(series(evals[3], varepsilon = 0, 4)), polynom)

2-2*varepsilon+(1/2)*varepsilon^2+(7/16)*varepsilon^3

K:=map(z->radnormal(convert(MultiSeries:-series(z, varepsilon = 0, 10),polynom)), evecs);

K := Matrix(3, 3, {(1, 1) = -(1/4194304)*`ϵ`*(548197*`ϵ`^7+786432*`ϵ`^6-1389696*`ϵ`^5+1048576*`ϵ`^4-61440*`ϵ`^3-1048576*`ϵ`^2+1835008*`ϵ`-2097152), (1, 2) = (1/2)*(`ϵ`^6-`ϵ`^4-2*`ϵ`^2-4*`ϵ`-4)/`ϵ`, (1, 3) = -(15/1024)*`ϵ`^4+(1/4)*`ϵ`^3+(7/16)*`ϵ`^2+(1/2)*`ϵ`-4, (2, 1) = (1/2097152)*`ϵ`*(165669*`ϵ`^6-183168*`ϵ`^5+86912*`ϵ`^4+61440*`ϵ`^3-192512*`ϵ`^2+262144*`ϵ`-262144), (2, 2) = -(7/4)*`ϵ`^9-(1/2)*`ϵ`^8+(3/4)*`ϵ`^7+(3/2)*`ϵ`^6+`ϵ`^5-`ϵ`^3-2*`ϵ`^2-2*`ϵ`-1, (2, 3) = (1/512)*(559*`ϵ`^4+960*`ϵ`^3+1088*`ϵ`^2-4096*`ϵ`+4096)/`ϵ`, (3, 1) = 1, (3, 2) = 1, (3, 3) = 1})

eval(evecs,varepsilon=1/10):
simplify(combine(simplify(%)),size):
simplify(map(fnormal,evalf[100](%)));

Matrix([[0.4587427651e-1, -22.10049496, -3.945379313], [-0.1133853238e-1, -1.220988432, 72.23232696], [1., 1., 1.]])

eval(K,varepsilon=1/10):
evalf[100](%): evalf(%);

Matrix([[0.4587427612e-1, -22.10049500, -3.945376465], [-0.1133853220e-1, -1.220988432, 72.23234180], [1., 1., 1.]])

#Digits:=100:
#map(plot,map(Re,evecs),varepsilon=1/100..1/10);
#Digits:=10:

#Digits:=100:
#map(plot,K,varepsilon=1/100..1/10);
#Digits:=10:

 


Download someseries.mw

acer

In the attached example the first set of four radio buttons all share the same action code.

radiostuff.mw

The second set of four radio buttons each make a call to the same procedure that is defined in the Startup Code of the worksheet. (Use the main menubar item Edit->Startup Code to see or alter that code). This set won't do anything unless you alloow the Startup Code to run when you open the worksheet or do a restart.

I've deliberately made the examples very simple. There are lots of possible variations. You could use GetProperty and SetProperty (which I prefer) instead of Do. It's not strictly necessary to write if blah = true then when you could write it more tersely as if blah then , but I wanted to make things clear. What I'm trying to convery in the example is how you can utilize values of component properties alongside Maple's usual if..then..else.. conditional programming..

Of course you may not want to have all the actions use exactly the same code. But if you do then, as shown in the lower set of four, you may find it easier to centralize any commonly used code to the Startup Code region.

Another variation, which I have not shown, is one in which the action code calls a procedure and passes to it the name of the current component (and any other that's relevent).

I don't know exactly what you want to do with your components, but hopefully this will help you sort out some of it.

You should also be able to see, at this point, that it is sensible to rename your buttons so that you can make better sense of the code.

acer

The evaluation of the name dim inside the type can be accomplished for createModule2 (using a local dim to hold the value) using the depends parameter modifier.

Since this involves evaluation of the type specification it is then necessary to quote Matrix (so that it doesn't call the Matrix constructor command).

restart;

with(LinearAlgebra):

createModule1 := proc(dim::posint)

    module()

        export det;

        det := (x::Matrix(1..dim,1..dim)) -> Determinant(x);

    end module

end proc:

createModule2 := proc(A::Matrix(square))

    local dim;

    dim := RowDimension(A);

    module()

        export det;

        det := (x::depends('Matrix'(1..dim,1..dim))) -> Determinant(x);

    end module

end proc:

createModule1(       2 ):-det(IdentityMatrix(2));

1

createModule2(Matrix(2)):-det(IdentityMatrix(2));

1

 

Download paramdep.mw

I should have thought of this earlier.

See the help page for topic parameter_modifiers .

acer

Is this what you want to obtain?


restart;

f2 := (diff(y(a, b), a)-(-(1/2)*x-1/2+(1/2)*sqrt(-3*x^2-2*x-3))/x^2)
      *(diff(y(a, b), b)-(-(1/2)*x-1/2-(1/2)*sqrt(-3*x^2-2*x-3))/x^2):

ans := subs(dab=diff(y(a,b),a)*diff(y(a,b),b),
            collect(algsubs(diff(y(a,b),a)*diff(y(a,b),b)=dab, expand(f2)),
                    [diff(y(a,b),a), diff(y(a,b),b), dab]));

(1/2)*(x+1+(-3*x^2-2*x-3)^(1/2))*(diff(y(a, b), a))/x^2-(1/2)*(-x-1+(-3*x^2-2*x-3)^(1/2))*(diff(y(a, b), b))/x^2+(diff(y(a, b), a))*(diff(y(a, b), b))+(x^2+x+1)/x^4

simplify(ans - f2);

0

 


Download coll.mw

acer

One of the important things to remember is the the right-click menu is context sensitive, which means that the various options that appear will vary with the type of thing upon which you click.

For example, you'll see quite a few differences if you bring it up for the output of the command

  Matrix(3,3,(i,j)->1/(1.0+i+j));

versus the output of a scalar like, say,

  sin(2*x)

For example, issue the Matrix command above and right-click on the displayed output. Instead of selecting some action just take note of what you see, and investigate what items appear within the submenus (some of which are Matrix-specific).

In modern Maple the context-menus get augmented or otherwise altered by loading subpackages of the Student package. All the following information may or may not be relevant or useful to you.

You can load these either using the with command, or with the main menubar choice Tools->Load Package .

Execute one or more of the following commands, and notice how new submenus appear near the bottom of the context-menu after you right-click again on that same Matrix output. These new submenus are entitled according to the loaded packages.

  with(Student:-LinearAlgebra):
  with(Student:-Statistics):
  with(Student:-NumericalAnalysis):
  with(Student:-VectorCalculus):

Now notice that not all of those appear when you right-click again on the scalar sin(2*x) output, because not all the commands from those packages are appropriate for scalar arguments.

Now load one or more of these packages,

  with(Student:-Calculus1):
  with(Student:-Basics):
  with(Student:-Precalculus):
  with(Student:-MultivariateCalculus):

Again, right click on the displayed output sin(2*x) and notice the appearance of new submenus for that. Not all of those second set will appear when you right-click on that Matrix output example, because some of this set are mostly appropriate for scalar arguments.

Notice also that these Student package exports (commands) will replace some context-menu items. For example when you load Student:-LinearAlgebra you'll see that the location in the menus of the item for computing Eigenvalues has moved -- the upper submenu item that would previously invoked LinearAlgebra:-Eigenvalues has been removed and the new submenu (at bottom) which invokes Student:-LinearAlgebra:-Eigenvalues is now available.

You can also unload these packages using either the unwith command, or using the menubar Tools item. Issuing the restart command should clear all the loaded packages.

You should take note that some common command names are exported from more than one package,  and that loading a package will rebind the name of the command. If you load the VectorCalculus or Student:-VectorCalculus packages then you rebind the name Vector, and the exported package version of some commands behave slightly differently than do the default global command names. Even when a package is loaded you can still access the global command name, eg. by calling it like :-Vector( ) .

If two packages export the same name as a command then the last one loaded is the one that is currently bound. You can always get at them individually, however. For example :-LinearAlgebra:-DotProduct( ) will call the version from the LinearAlgebra package, even if Student:-LinearAlgebra was loaded last.

The items from those new context-submenus should be hard-coded to get the command that they each appear to be, so you shouldn't have to worry about such name clashes when you use those submenus after loading many packages. But when you type in the commands as code then the order in which the packages were loaded can sometimes make a difference (in the case of a command name that appears in more than one package).

acer

In Maple 2015 this is made simpler by the Units:-UseUnit command.


restart;

simplify( [ Unit(J)/Unit(s), Unit(volt)*Unit(ampere), Unit(W), 1/Unit(W) ] );

[Units:-Unit('W'), Units:-Unit('W'), Units:-Unit('W'), Units:-Unit(1/('W'))]

with(Units:-Standard):

Unit(J)/Unit(s), Unit(1/J)/Unit(1/s);

Units:-Unit('W'), Units:-Unit(1/('W'))

restart;

Units:-UseUnit(volt*ampere):

simplify( [ Unit(J)/Unit(s), Unit(volt)*Unit(ampere), Unit(W), 1/Unit(W) ] );

[Units:-Unit(('V')*('A')), Units:-Unit(('V')*('A')), Units:-Unit(('V')*('A')), Units:-Unit(1/(('V')*('A')))]

with(Units:-Standard):

Unit(J)/Unit(s), Unit(1/J)/Unit(1/s);

Units:-Unit(('V')*('A')), Units:-Unit(1/(('V')*('A')))

 


Download voltampere.mw

An alternative way involves creating a custom system of units by augmenting the SI system with some unit of choice, using a combination of all of the GetSystem, AddSystem and UsingSystem commands from the Units package.

acer

It seems that you want to get a visual display of the progress being made.

One simple way is to use a command such as print, or printf, or userinfo. One drawback to those is that it clutters the worksheet with all the printed values. You can mitigate that by printing only a select number of values (using irem or mod, say) but then you lose the granularity and still have some clutter. Another drawback is that it doesn't work in a Document Block -- the values are only display (all at once), after the whole computation in that Block completes.

If you're using the Standard GUI then read on, for ways that work even if you call the procedure or loop code from within a Document Block.

You can use Embedded Components for this. One way to do it consists of manually inserting say a TextArea or Slider component into the worksheet and then at each iteration of the loop calling DocumentTools:-SetProperty to update the component using the current value of the loop index variable. A drawback of this approach is that if you insert the component from the palette then its position in the worksheet is not dynamic. The location of the component may not always be convenient if you want to re-use it from several places in your worksheet.

One simple alternative available in Maple 2015 is to use DocumentTools:-Tabulate to inform you of the current loop status. Here is an example.

p := proc()
  uses DocumentTools;
  local i, N;

  N := 5;

  for i from 1 to N do

    Tabulate([sprintf("Doing iteration %a of %a",i,N)],
             ':-widthmode'=':-pixels', ':-width'=150);

    Threads:-Sleep(1); # replace with your own computations

  end do;

  InsertContent(Layout:-Worksheet()); # empty

  return i-1; # or whatever you want
end proc:

So now if you call procedure p you can see the effect.

  p();

tab.mw

The above example can be easily modified to show more intermediate results. The first argument passed to Tabulate doesn't have to be a list with only single formatted string -- you could make it a list with a formatted string as well as some math expression and a plot, etc.

If your loop index takes all values from 1 to 10000 then I suggest that you only display some values. For example, using irem to update the display every 500th iteration:

tab2.mw

There are other interesting alternatives, including programmatic insertion of a Slider component (or other sliding component) for use as a progress indicator, instead of the GUI Table that Tabulate inserts. (I have examples, if people are interested...)

acer

Look at the help page for ComboBox components.

Suppose that your ComboBox component has identity "ComboBox0". Then you can do it with the following commands,

L := [m, n, c, k]; # Get a list of parameter names

Ls := map(convert,L,string); # convert them to strings

DocumentTools:-SetProperty("ComboBox0", ':-itemList', Ls, ':-refresh');

acer

This scalar is not zero.

restart;

ee := (-3/186591314-(2/13327951)*I)*(-((28412308*I)*3^(1/2)+44068556*3^(1/2)
      +(-76328978-49211561*I))/(((4*I)*3^(1/2)+4*3^(1/2)+(-7-9*I))^2
      *((-3-4*I)+2*3^(1/2)+(2*I)*3^(1/2))^6))^(1/2);

       /      3          2      \ /  /            (1/2)
       |- --------- - -------- I| |- \28412308 I 3     
       \  186591314   13327951  / \                    

                      (1/2)                           \//
          + 44068556 3      + (-76328978 - 49211561 I)/ |
                                                        \

                                             2 
         /     (1/2)      (1/2)             \  
         \4 I 3      + 4 3      + (-7 - 9 I)/  

                                             6\\      
         /                (1/2)        (1/2)\ ||^(1/2)
         \(-3 - 4 I) + 2 3      + 2 I 3     / //      

simplify(ee);

                               0

evalf[10000](ee): evalf[10](%);

                            -9                 -8  
             -2.481288046 10   - 2.748412826 10   I

acer

How about inserting a DataTable (from the Embedded Components palette) and associating its data with a name to which you have assigned the imported Maple Matrix?

You can associate a DataTable component with an existing Matrix by right-click to change the components properties. You don't need to make all the rows and columns visible. If you want you can even toggle the visibility of the whole component.

When you close and repoen the worksheet that variable name should automatically have the Matrix as its assigned value.

DT2.mw

acer

Now that I have the problematic worksheet I can reproduce the error in Maple 2015.0, and I recall why it occurs.

In Maple 2015 the statement terminator (colon or semicolon) was made optional for 1D Maple Notation input (on a line with a prompt). See the last section, "More Updates" on this page, the body of which declares:

     Previously, if a command was entered in 1-D without a semi-colon, a warning
     would be returned. In Maple 2015, the missing semicolon warning has been
     removed for 1-D math.

The original implementation of this was buggy in Maple 2015.0, in the following repsect. The GUI was automatically (behind the scenes) including the terminator for 1D input lines that lacked a terminator if the following line in the Group had a prompt. The GUI was not restricting this to only the last line of a mult-line 1D input in an Execution Group.

In Maple 2015.1 the implementation was fixed, and it appears that the statement terminator is now only ever added (behind the scenes) by the GUI to the last line of 1D input in an Execution Group.

I had difficulty reproducing the problem at first because I was using Ctl-Enter to type in the example, or pasting it from your question. I reproduced it by conjoining multiple 1D input lines -- each with their own prompts -- using the F4 key. The input prompt at the start of the second line of the proc body was needed, in order to reproduce.

Where I write "all other statements in the body" below I mean statements other that `global` declaration, `uses` or`use` calls, `description` statement, `option` statement...

restart;

# This is an expected error, as the local declaration does not
# come before all other statements in the body (including empty ones).
test := proc()
  ;
  local a;
  a := 3
end proc;

Error, unexpected `local` declaration in procedure body

# This is an expected error, as the local declaration does not
# come before all other statements in the body (including empty ones).
test := proc();
  local a;
  a := 3
end proc;

Error, unexpected `local` declaration in procedure body

# In Maple 2015.0 the GUI attempts to execute the following

# while inserting (behind the scenes) a semicolon terminator

# at the end of the first line. That produces the error case

#  immediately above. This was fixed in the Maple 2015.1 update.

test := proc()

  local a;

  a := 3

end proc;

Error, unexpected `local` declaration in procedure body

# This is OK, across versions.``

test := proc()
  local a;

  a := 3

end proc;

proc () local a; a := 3 end proc

# This is OK, across versions.
test := proc()
  local a;
  a := 3
end proc;

proc () local a; a := 3 end proc

kernelopts(version);

`Maple 2015.0, X86 64 LINUX, Feb 17 2015, Build ID 1022128`

 

Download DM_2015.0.mw

I could add the the "expected" error cases above also produce the same errors in the Command Line Interface (CLI, or TTY). It does seem like an unnecessary restriction, and I don't see why an empty statement couldn't also be a permitted exception.

acer

restart;                                                

ee := 3^(-(1/2)*n)*2^((1/6)*n)-2^((2/3)*n)*6^(-(1/2)*n):

simplify(combine(evalc(eval(ee,n=t+s*I)))) assuming t::real, s::real;

                                       0

simplify(combine(evalc(eval(ee,n=t+s*I))));                          

                                       0

Or,

simplify(combine(evalc(convert(eval(ee,n=t+s*I),exp))));

                                       0

acer

In your assignment to bcs you have an extra space between D(f) and (etainf) which makes that term be parsed as a product (multiplication) instead of a function call.

acer

One thing that seems to work here is converting the abs in the integrand to Heaviside (before integrating).

MWP44_edited.mw

acer

First 213 214 215 216 217 218 219 Last Page 215 of 336