Carl Love

Carl Love

28100 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Doug Meade Maple's dsolve does support the numerical solution of BVPs. For example,

dsolve({diff(y(x),x$2) - y(x) = sin(x), y(0)=0, y(1)=0}, numeric);

     proc(x_bvp) ... end proc

@acer wrote:

Carl, you wrote that the problem was also exhibited when the problematic subsection was not empty. When it was not empty did it have a title?

There probably was at least a moment when it had a body but no title:  When trying to delete the subsection, I probably deleted the title first and then the body. But I've also probably done that many other times without it causing a problem.

What happened to the Answers to this Question? This was important material that I need to refer back to! If you look at the number of Replies in the Active Conversations list, it says that there are 10.

@John Fredsted Thank you. It works.

@AndreMenezes 

I think that I see where you're going with this. Maple's ability to convert between formal products and formal sums is very limited. You're better off just defining the log-likelihood function straight away.

Computing a maximum likelihod estimator.

restart:

 

Define the pdf:

fx:= x-> theta*exp(-theta*x);

proc (x) options operator, arrow; theta*exp(-theta*x) end proc

Verify it's a pdf.

int(fx(x), x= 0..infinity);

limit(-exp(-theta*x)+1, x = infinity)

simplify(%) assuming theta > 0;

1

Define a general log-likelihood function.

LogLH:= (pdf::procedure)-> sum(ln(pdf(x[k])), k= 1..n):

Apply it to our pdf.

LogLH(fx);

sum(ln(theta*exp(-theta*x[k])), k = 1 .. n)

LH:= simplify(%) assuming positive;

n*ln(theta)-theta*(sum(x[k], k = 1 .. n))

Maximize LH with respect to the parameter theta.

est:= solve(diff(LH, theta), theta);

n/(sum(x[k], k = 1 .. n))

Apply second-derivative test.

eval(diff(LH, theta$2), theta= est);

-(sum(x[k], k = 1 .. n))^2/n

Obviously that's negative if the variables are positive. So the maximum-likelihood estimator for theta is the reciprocal of the arithmetic mean of the data.


Download Likelihood.mw

 

@AndreMenezes There are several ways. It would be best if you told me what your goal is. The most basic way is

Pfx:= unapply(prod, x);

A problem with that is that I suspect that you want n to represent the number of elements in x, and the function above doesn't encapsulate that. This does

Pfx:= ()-> mul(fx(x), x= args);

Then you can do

Pfx(x,y,z);

or apply Pfx to any number of arguments.

@Kitonum It's not entirely clear what the OP wants, but I assumed that they wanted the new to equal the old F, so k1 must contain C, and k2 must contain L. But perhaps you're correct that it's the linear terms of CL, and x1 that are wanted.

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

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