Carl Love

Carl Love

28050 Reputation

25 Badges

12 years, 336 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@ 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?

@taro These customs may vary from country to country, but I think it likely that the postdoc worked under a contract where all copyrights were forfeited to the university/institute that employed him.

Still, it'd be worth it to ask him to convert the files to plaintext. Like I said above, it'd only take less than a minute per file.

@RES I think that you don't understand Preben's suggestion: You upload your files here and someone here will use their copy of Maple to convert the Maple code in the files to plaintext files and send them back to you. The whole process (download, export as text, upload) would take less than a minute per file for someone who had Maple.

Maple code for numeric programming (i.e., that doesn't use symbolic features) can be automatically translated by Maple to a variety of other languages: C, C#, Fortran, Java, JavaScript, Julia, Matlab, Perl, Python, R, and VisualBasic.

You say "dimensions", plural. So, you don't seem to be aware that you must view the array as one-dimensional on the C side (AFAIK).

Can't you precompute, on the Maple side, at least a reasonable upper bound for the number of elements? Then you can pass in an array with that number of elements.

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