19502 Reputation

29 Badges

14 years, 315 days

Social Networks and Content at

MaplePrimes Activity

These are answers submitted by acer

Not all of Maple takes advantage of all assumptions.

If there isn't an example on a routine's help-page of it working with assumptions, then that's a hint that the routine doesn't respect assumptions.

In the case of `solve`, the help-pages describe `solve`'s ability to deal with assumptions on parameters but not on the main variables (unknowns for which to solve).

There was a time when almost nothing of interest in Maple took advantage of assumptions. This has been changing, slowly. Making some routines utilize assumptions would be very difficult, and could conceivably require a near-full rewrite for the routine in question.

ps. were you expecting a null return for your example, under the assumptions?


Please tell us what `Ranges` and `Img` are.

I am imagining that an efficient in-place solution using the container=V option may be possible. But it'd help to see the structure of Ranges and Img.


fff := proc(dist, s_one, d, n)
option hfloat;
# parameters:
#   sample procedure
#   Starting price stock
#   Trailing distance#
#   Number of periods
# returns:
#   Profit/loss with stop loss,
#   Profit/loss without stop loss
local rand_, i, A, C, w, w_w_, w_w, C_C,
      Exit_period, Exit_price, Last_close;


    # Stock price
    A[1]:=s_one: # Starting price stock
    for i from 2 to n do
    end do:

    # Trailing Stop-Loss
    for i from 2 to n do
        if A[i]>A[i-1] and A[i]>(A[i]-d)
          and (A[i]-d)>C[i-1] then
        end if;
    end do:

    for i from 2 to n do
        if A[i]>C[i] then
        end if;
    end do;

    for i from 2 to n do
    end do;

    for i from 2 to n do
    end do;

    # Final Corrections
    for i from 2 to n do
        if w_w[i]=0 then
        end if;
    end do:

    ############## Results #########
    # Exit period due to stop loss

    # Exit price stop-loss

    # Last close stock price

    # Profit/loss with stop loss,
    # Profit/loss without stop loss

end proc:

X := Statistics:-Sample(Statistics:-RandomVariable(Normal(0,1))):

fff( X, 100, 4, 100 );

seq( fff( X, 100, 4, 100 ), i=1..10 );

time( seq( fff( X, 100, 4, 100 ), i=1..1000 ) );

If you need this to be really fast, then the local tables (A, C_C, etc) could be created as float[8] Vectors outside of fff and then get passed in and re-used.


How about putting the whole thing in a procedure called f (which might even take no arguments at all. Have it return that final result. Then call f() repeatedly, or call seq(f(),i=1..10).


I thought that _S01 (and other names similarly prefixed by _S) are what `solve`  uses to manage substitutions internally. That is to say, that they are temporary placeholders that `solve` uses while it does its work. If that's true, then it could well be a bug if they appear in the return value.

Could you post or upload an example of input, and say what Maple version you're using?


Have you read the Maple help-page for limit and limit,return ?


I've tried to lay out a method, and prototype code, for doing this here.


It's not clear what you're asking. It appears to be a question about how to write an assignment. Here's an example,

x := 2*sin(y);

The colon-equals is what does the assignment of the expression 2*sin(y) to name (variable) x. The semicolon at the end is a statement terminator, and completes the command. If I had used a colon at the end then it would still do the assignment but the printing of the output would be suppressed.

Are you also wondering about the rules (eg. arithmetic operators, etc) that can be used to form expressions?


The following should find the radius which minimizes the sum of the distances from the points to the circle.

p1:=[-10,2]: p2:=[-8,5]: p3:=[-1,-12]: p4:=[4,6]: p5:=[10,-1]:
L := [p1,p2,p3,p4,p5]:
CX:=-1: CY:=-4: # the given center
PC:=plots:-implicitplot( subs(r=R,ceq), x=-20..20, y=-20..20):


Your idea about how to go about showing it is good.

Write the equation of the line in parametric form, using say the parameter name t.

Now, substitute the formulae(in terms of t) for x, y, and z of that parametric form in for the x, y, and z that appear in the equation for the sphere. That results in a quadratic equation in the parameter t. Now solve that quadratic equation, to get two solutions for t. Plug each of those two values of t into the parametric form of the equation of the line, and those results are the two intersecting points.

Here's how to do those steps in Maple. First, create the points, line, and sphere.

_EnvXName := x: _EnvYName := y: _EnvZName := z:
sphere(s,x^2+y^2+z^2 = 36,[x,y,z]):

Maple can now give the answer right away,


Or you can do each step in Maple,

eL:=Equation(L,'t'); # equation of line

# substitute components of line form into sphere's equation

# solve the quadratic equation

# plug both t values into the line (parametric form).
seq(eval(eL,t=tval),tval in [tsols]);


What is the output from the shell command,


What is your machine, a G5? And the OSX, is it 10.5? (I'm wondering whether there's a 32/64bit mismatch between the shared library and the Maple binary. I'm wondering whether the shared object needs to be compiled/linked with a -arch flag to force its architecture to match Maple's. Just an idea...)


There are two factors at play here, in the multivariate Newton's method solver. One is the number of iterations that get done, for a given starting point. Another is the number of different starting points from which iteration gets done.

Try setting,

> _EnvTry:='hard':

This line in `fsolve/sysnewton` hints that the number of allowed iterations gets affected by this.

> showstat(`fsolve/sysnewton`,41);

  41     for it to `if`(_EnvTry = ('hard'),max(Digits-7,50)*n+60,(Digits-7)*n+16) do
end proc

As you can see, the value of Digits also affects that maximal number of allowed iterations. You had said that increasing Digits (and hence increasing the number of iterations allowed) didn't help much. So this may not suffice.

The number of different starting points from which it begins iterating isn't an option that can be set, however.

The very brave might try to surgically alter the routine, to change the maximum number of starting points,

> showstat(`fsolve/sysnewton`,20);

  20   maxguess := 20;

In this post Jacques did live surgery on another routine.

I would advise not tightening the bounds too much. I realize that it seems intuitive that doing so would assist the solver. But there may be bounds check going on, which (inappropriately) short-circuits a guess/iteration-loop if an intermediate value steps out of bounds. So with very tight bounds such early cut-out can actually prevent a root from being located.


When you pass S(n) as an argument to plot, it is evaluated right away. Ie, it evaluates with the unassigned n, just as if you'd entered S(n) on its own.

Error, (in F) final value in for loop must be numeric or character

Try plot('S'(n),n=1..10) or plot(S,1..10) instead.

ps. There are ways to speed up the sampling, if you're interested...


I won't go into efficiency. But, given what you have so far,

> with(Statistics):
> S:=Sample(Bernoulli(0.5),2):
> S := 2*(S-<0.5,0.5>);
                                S := [1., -1.]
Also, what's k? Is it supposed to be n?


You have declared pos as a local variable of procedure treach. And treach doesn't assign to the pos variable. So when treach runs it cannot figure out the conditionals involving the pos[n] term.


First 195 196 197 198 199 200 201 Last Page 197 of 222