Carl Love

Carl Love

28055 Reputation

25 Badges

13 years, 0 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@tomleslie I think that everything in the OP's code works as it did 10 years ago. These are after all documented features, and they're still documented. If the OP were trying to use undocumented features that worked 10 years ago, that would be a different matter.

@mmcdara Using savelib combines the steps of putting expressions in .m-file format and adding them to the library. I only mentioned .m files because your original goal in this thread was to read .m files. Creating an intermediate .m file and then using march is one way of adding something to a library; savelib is the other way.

I made a mistake: My original Answer won't solve the problem in your original Question because the march(list, ...command will only list the index names that you used with the march(add...) command. It won't list the names of the variables themselves. Nonetheless, the variables are stored in the library by their original names. To find those original names, you should use Tom Leslie's method.

 

@mmcdara You wrote:

But, before your answer I thought naively that the concept of "archive" was related ONLY to mla files and the concept of "library

A library is stored in an .mla file. A .mla file is constructed from .m files by using march.

I naively thought that, in Maple, the term "library" had the same meaning  whereas it seems to have a broader sense and that a library may contain other things than just procedures  ... ???

Anything the can be assigned to a variable can be in a Maple library. And in Maple anything at all can be assigned to a variable.

I have to confess here that I am probably confused between the terms archive and library ?

AFAIK, they mean exactly the same thing.

An other source of mistake is my knowledge of Matlab, where .m files generally contain structures data, not code.

In Maple, everything is a first-class citizen (see linked Wikipedia article for definition). Thus Maple code can be treated as data.

@ I was wrong: The bug is in your code. It just wasn't in f. Each of the constraint procedures needs to have the same six parameters as f, in the same order, even though not every parameter is used in every procedure.

When any problem is specifed via procedural input (in any of the many Maplesoft commands that take procedural input), the only way that the variables can be identified is by their positions in the parameter sequences. The names of the variables are insignificant.

After I made the above correction, NLPSolve returns the initial point as optimal. If I change the initial point to another that satisfies the constraints, [.4 , .6, .3, .7, .2, .8], and use trace(f), it's eventually shown that certain values are being set to infinity (probably due to dividing by very small numbers). This is a bug in f that you'll have to track down.

I've also tried the third-party optimization package DirectSearch (available for free download in the Maple Applications Center) on your problem, using the command:

V:= [x||(1..6)]:
DirectSearch:-GlobalOptima(f, {x1+x2=1, x3+x4=1, x5+x6=1, (V=~ 0..1)[]}, variables= V);

Note that this procedure, which is not written by Maplesoft, differs from what I said in the second paragraph above: It has an API that allows the variables to be specified by name rather than by position.

Anyway, the above gets stuck in an apparently infinite loop on your problem. Again, I suspect a problem with f.

I'd appreciate it if someone could show me how to specify an intial point in DirectSearch:-GlobalOptima. Following the help, I tried initialpoints= [V=~ .5], but I get

Error, (in DirectSearch:-GlobalOptima) final value in for loop must be numeric or character

@alfarunner  Vote up. I was looking for something like this. This uasge of option explicit is undocumented!

Your and is superfluous: It's implied by the commas. The desired solutions were -Pi/2 and Pi/2. Your inequalities can be adjusted to obtain these. 

To get the root with the maximal absolute value, you could also use

[zeros][max[index](abs~([zeros]))];

This should be slightly more efficient than the sort, assuming that you're only interested in that one root. If you're also interested in the root of minimal absolute value, then you should use sort.

@Mac Dude I think that you mean with(Lattice), not use(Lattice).

@Østerbro I can't properly run your worksheet because it doesn't include the definitions of invTan and invCos.

@carsten moller 

Okay, I rewrote Display to deal with the problem of "staircase" expressions caused by using double-underscore subscripts. However, I think that this version is all-around better, even for input with no subscripts. So please consider this a replacement for my original Answer. This code includes the changes made by Acer. This version uses several undocumented but relatively widely known features of the Typesetting package. You may want to change the "*" (multiplication symbol) to a centered dot. Someone will have to tell me the codeword for that.

restart:

Display:= proc(e::uneval)
uses T= Typesetting;
local
     pre:= subsindets(e, uneval(name), eval, 1),
     r:= eval(pre),
     Ty_pre:= T:-Typeset(e)
;   
     if indets(pre, And(name, satisfies(u-> u<>eval(u)))) = {} then
          print(r);
     else
          print((
               Ty_pre =
               evalindets(                   
                    subs("&InvisibleTimes;"= "*", Ty_pre),
                    specfunc(string, T:-mi),
                    proc(n)
                    local pn:= eval(parse(op(n)));
                         if pn::numeric then T:-mn(sprintf("%a", pn)) else n fi
                    end proc
               )) =
               evalf(r)
          )
     end if;
     r
end proc:

C:= 1.1:
U__n:= 10000:
Z__min:= 0.154:

I__K3FMax:= Display(C*U__n/Z__min/sqrt(3)):

(Typesetting:-mfrac(Typesetting:-mrow(Typesetting:-mi("C"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mi("U__n")), Typesetting:-mrow(Typesetting:-mi("Z__min"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-msqrt(Typesetting:-mn("3")))) = Typesetting:-mfrac(Typesetting:-mrow(Typesetting:-mn("1.1"), Typesetting:-mo("*"), Typesetting:-mn("10000")), Typesetting:-mrow(Typesetting:-mn(".154"), Typesetting:-mo("*"), Typesetting:-msqrt(Typesetting:-mn("3"))))) = 41239.3049421162

 

 

Download Typeset_Display.mw

@carsten moller If you want the result in decimal form, then you should put a decimal point after the 3:

sqrt(3.)

Unlike a typical calculator, Maple assumes that the results are wanted in exact form unless it's told otherwise. If you know that you're always going to want decimal results, then you can change the second-to-last last line of Acer's procedure Display from r to evalf(r). Using evalf will convert anything to decimal form, to the furthest extent that that's possible.

@carsten moller If you mean that you want 0.75 as the result, then enter the input with decimal points:

(a,b):= (3., 4.); c:= Display(a/b);

@jamunoz Are you saying that you want a completely random, nowhere continuous initial function? Maybe you want to solve a stochastic PDE?

@Kitonum 

randpoly is more flexible than you might suppose. In particular, it's not strictly limited to polynomials; it handles "susbstituted" polynomials. Your example can be done like this:

opts:= degree= 1, coeffs= rand(0..10.):
randpoly(sin(randpoly(x, opts)), opts, homogeneous);

     1.25256292578366*sin(4.61174519622911*x+5.87291947310990)

 

@Kitonum

Vote up. That's one problem with retyping code. I missed that extra space, so the code worked for me.

@jjweimer Does it make any difference if you use Export As PDF rather than Print to PDF?

First 404 405 406 407 408 409 410 Last Page 406 of 709