acer

32333 Reputation

29 Badges

19 years, 321 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

By using cylindrical coordinates one can easily construct either a whole cone or a partial cone having a round base.

R, H := 3.2, 4.7;

plot3d(R*(H-h)/H, th=-Pi..Pi, h=0..H, coords=cylindrical);

plot3d(R*(H-h)/H, th=-3*Pi/2..0, h=0..H, coords=cylindrical, view=[-5..5,-5..5,0..H]);

Other options such as the 'view',etc, may also be supplied.

In contrast, using plottools:-cone produces only a full cone, while using the default rectangular coordinates (with trig functions) produces a structure which renders with straight edges on the polygonal primitives around its base.

acer

An alternate way might be,

f := x1^2/((x2^3)*(x3^2)):

subsindets(f, name^negint, q->1/cat(op(1,q),b)^op(2,q));

                           2    3    2
                         x1  x2b  x3b 

acer

There are various ways to get it. It's not clear whether your expression will always be so simple, or whether it might have some symbolic coefficient, whether it is always a ratio of multivariable polynomials, etc. How simple you can make it will depend on how restricted is the nature of the expression.

ee:=x^2*y^3/z^7:

(t->zip(`^`,t,map2(degree,ee,t)))([indets(ee,And(name,Non(constant)))[]]);

                          [ 2   3  1 ]
                          [x , y , --]
                          [         7]
                          [        z ]

[op(ee)];

                          [ 2   3  1 ]
                          [x , y , --]
                          [         7]
                          [        z ]

[indets(ee,And(name,Non(constant))^anything)[]];

                          [ 2   3  1 ]
                          [x , y , --]
                          [         7]
                          [        z ]

As just one simple example of how these behave for a slightly more general expression,

ee:=Pi^3*x^2*y^3/z^7:

(t->zip(`^`,t,map2(degree,ee,t)))([indets(ee,And(name,Non(constant)))[]]);

                          [ 2   3  1 ]
                          [x , y , --]
                          [         7]
                          [        z ]

[op(ee)];

                       [  3   2   3  1 ]
                       [Pi , x , y , --]
                       [              7]
                       [             z ]

[indets(ee,And(name,Non(constant))^anything)[]];

                          [ 2   3  1 ]
                          [x , y , --]
                          [         7]
                          [        z ]

So you may be able to figure out whether `op` alone is enough.

acer

If you used the syntax,

(exp(x)-1)(1-exp(-x))

then you probably wanted this instead,

(exp(x)-1)*(1-exp(-x))

I don't know whether either of these will get you what you want for more constrained examples, but it might give you some ideas.

restart:

s:={A>E,F>Z,F<P,Z>E,P<A}:

sort([s[]],(a,b)->coulditbe(op(2,a)<op(1,b) or op(1,a)<op(2,b))=true) assuming op(s);

                    [E < A, E < Z, Z < F, F < P, P < A]

sort([s[]],(a,b)->is(op(2,a)<op(1,b) or op(1,a)<op(2,b))=true) assuming op(s);

                    [E < A, E < Z, Z < F, F < P, P < A]

acer

Attached is an example. The commands are in the Action code behind the buttons.

The basic idea is to use the DocumentTools:-SetProperty command and the properties for (an animation as the value of) a PlotComponent listed here.

animatortask.mw

I'm not sure how well the dial (approx. frames/sec) will work in general. It may be better to give up the FPS idea and just go with a frame-delay instead.

One of the actions that I miss is the ability to do a distributed divide (or multiply). By distributed I mean expanded. Sometimes I want the divided (or multiplied) factor distributed across a sum of terms, and sometime I don't. So a choice would be nice.

I find it awkward to cancel leading minus signs on both sides of an equation.

And I'd like to be able to customize the priorities, so that `normal` (which must seem like magic, and be uninstructive to many students) didn't supercede more understandable entries such as for expand,factor,combine,etc.

Here is a humble attempt, hopefully in the direction you were aiming.

spmanip.mw

acer

restart:

ee:=(exp(a+b)+exp(a+c))*exp(-a):

expand(ee);

                        exp(b) + exp(c)

acer

If you want to join the plotted data values by lines, then you can sort w.r.t. the first column of the pair.

A:=ArrayTools:-RandomArray(4,4);

plot(sort(convert(A[..,[1,3]],listlist)));

plot(A[sort(A[..,1],output=permutation),[1,3]]);

If you only want a point-plot (no joining lines) then it's easier.

plot(A[..,[1,3]],style=point);

acer

Your Maple procedure `mp` is heavy in terms of producing collectible garbage. And it's not just the sorting. The repeated unioning of temporary sets, conversion to temporary tables, and disposing of all these (memory managment) is expensive. 

That can be illustrated with a modification to your original `mp` procedure to get something like the following, where the partial results (computed in the loops within just a single non-recursed call to the central procedure) are instead stored in a single table whose entries are extracted into a set only once just prior to the procedure return.

Since `mp3` is recursive it still entails quite a bit of switching between temp sets and temp tables and so this modified version is still prone to slowdown as the problem size grows large -- but the idea is just to show that reducing it improves performance.

mp3 := proc(n)
    option remember;
    local count, rec, onef, res, f, asg, targ, t;
    if n=1 then return {}; fi;
    onef := op(2, ifactors(n))[1];
    rec := mp3(n/onef[1]);
    if nops(rec) = 0 then return {[n=1]} fi;
    count:=0:
    for f in rec do
        t := table(f);
        targ := onef[1];
        if type(t[targ], integer) then
            t[targ] := t[targ] + 1
        else
            t[targ] := 1;
        fi;
        count:=count+1: res[count]:=op(op(t));
        for asg in f do
            t := table(f);
            targ := onef[1]*op(1, asg);
            if type(t[targ], integer) then
                t[targ] := t[targ]+1;
            else
                t[targ] := 1;
            fi;
            if t[op(1,asg)]>1 then
                t[op(1,asg)] := t[op(1,asg)]-1;
            else
                t[op(1,asg)] := evaln(t[op(1,asg)]); 
            fi;
            count:=count+1: res[count]:=op(op(t));
        od;
    od;
    {entries(res,':-nolist')[]};
end:

On my machine your original `mp` handled 9! in about 35sec, and the edited `mp3` above took 1.2sec, while Factorings [due to Kitonum, Joe Riel, and Carl Love] took 0.14sec. Of course, more important than just single timings are the performance as the problem size grows.

acer

In the Standard GUI,

restart:
test := proc(x)
  local out;
  out:=cat(`#mrow(mo(\"x is equal to: \",mathcolor=\"#00aa00\"),`,
                sprintf("%a",convert(Typesetting:-Typeset(x),`global`)),`)`);
  return out;
  #print(out);
  #return NULL;
end proc:

test(2);

test(Pi/sqrt(2));

test(Int(f(x),x));

This post may be of interest here.

acer

x2:=y=a+b;

                           y = a + b

map2(map,f,x2);

                       f(y) = f(a) + f(b)

acer

You may want to adjust the domain (wider than -20..20), or the quadrature tolerance (smaller than 1e-5), or the plotting options.


restart:

ee:=(1/2)*(-4*dilog(-(exp(2*t)*s-(-s^2+1)^(1/2)+1)/(-1+(-s^2+1)^(1/2)))
*exp(4*t)+arctanh((-1+s)/(-s^2+1)^(1/2))*s^2+arctanh((exp(2*t)*s
-exp(2*t)-s+1)/((exp(2*t)+1)*(-s^2+1)^(1/2)))*s^2+8*(-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1/2)))*exp(8*t)*s^2+exp(8*t)*arctanh((-1+s)/(-s^2+1)^(1/2))*s^2
+2*exp(4*t)*arctanh((-1+s)/(-s^2+1)^(1/2))*s^2-6*(-s^2+1)^(1/2)*ln(exp(4*t)*s
+2*exp(2*t)+s)*exp(4*t)+6*(-s^2+1)^(1/2)*ln(s)*exp(4*t)-2*dilog(-(exp(2*t)*s
-(-s^2+1)^(1/2)+1)/(-1+(-s^2+1)^(1/2)))*exp(4*t)*s^2)/((-s^2+1)^(1/2)
*exp(8*t)*s^2-2*arctanh((-s^2+1)^(1/2)/(1+s))*exp(8*t)*s^2+4*(-s^2+1)^(1/2)
*exp(6*t)*s-8*arctanh((-s^2+1)^(1/2)/(1+s))*exp(6*t)*s+2*(-s^2+1)^(1/2)
*exp(4*t)*s^2-4*arctanh((-s^2+1)^(1/2)/(1+s))*exp(4*t)*s^2+4*(-s^2+1)^(1/2)
*exp(4*t)-8*arctanh((-s^2+1)^(1/2)/(1+s))*exp(4*t)+4*(-s^2+1)^(1/2)
*exp(2*t)*s-8*arctanh((-s^2+1)^(1/2)/(1+s))*exp(2*t)*s+(-s^2+1)^(1/2)*s^2
-2*arctanh((-s^2+1)^(1/2)/(1+s))*s^2):

ff:=simplify(ee,size) assuming s>0, s<1, t::real:

H:=S->evalf(Int(unapply(eval(ff,s=S),t),-20..20,epsilon=1e-5,method=_d01ajc)):

CodeTools:-Usage( H(0.5) );

memory used=54.83MiB, alloc change=4.00MiB, cpu time=733.00ms, real time=769.00ms

-.3439176104

CodeTools:-Usage( plot(H,0..1,numpoints=40,adaptive=false,smartview=false) );

memory used=1.84GiB, alloc change=0 bytes, cpu time=25.71s, real time=31.16s

 

 


Download numint.mw

acer

If you are willing to admit an approximating expression of the form P(R_i_t)/Q(R_i_t) where P and Q are both polynomials then you can get pretty good behaviour near the right-end-point or R_i_t=1.

Also, you can get some speed up of the original omega_i evaluations by delaying the `Quantile` computation in G_PD until such time that R_i_t takes on numeric values. Of course, the timing doesn't matter once you do obtain the approximating expression which will itself evaluate very quickly. But it may help to have the attempts at computing the approximant run faster. It seems to be about a factor of 3, for the problem at hand. The speed up helps even more if you are not aware that the lower-end-point for R_i_t should be 0.25, and try it from say 0.0 intsead.

You might compare these two version, then.

restart;
with(Statistics):
i=F:
C_i:=50:
M_i:=2.5:
LGD_i:=0.75:
PD_i:=(1-R_i_t)/LGD_i:
b_i:=(0.11852-0.05478*ln(PD_i))^2:
B_i:=(1-1/(exp(C_i*PD_i)))/(1-1/exp(C_i)):
R_i:=0.12*B_i+0.24*(1-B_i): 
G_C:=3.09023230616741:
G_PD:=unapply('Quantile'(Normal(0,1),PD_i),R_i_t,numeric):
t:=sqrt(1/(1-R_i))*G_PD(R_i_t)+sqrt(R_i/(1-R_i))*G_C:
N_t:=CumulativeDistributionFunction('Normal'(0,1),t):
k_i:=(LGD_i*N_t-PD_i*LGD_i)*((1+(M_i-2.5)*b_i)/(1-1.5*b_i)):
omega_i:=12.5*k_i:

CodeTools:-Usage( plot(omega_i,R_i_t=0.25..1.0) );

AP:=CodeTools:-Usage(numapprox:-minimax(omega_i, R_i_t= 0.25..0.9999, [6,1]));
plot([AP],R_i_t=0.25..1.0);


restart;
with(Statistics):
i=F:
C_i:=50:
M_i:=2.5:
LGD_i:=0.75:
PD_i:=(1-R_i_t)/LGD_i:
b_i:=(0.11852-0.05478*ln(PD_i))^2:
B_i:=(1-1/(exp(C_i*PD_i)))/(1-1/exp(C_i)):
R_i:=0.12*B_i+0.24*(1-B_i): 
G_C:=3.09023230616741:
G_PD:=Quantile(Normal(0,1),PD_i):
t:=sqrt(1/(1-R_i))*G_PD+sqrt(R_i/(1-R_i))*G_C:
N_t:=CumulativeDistributionFunction('Normal'(0,1),t):
k_i:=(LGD_i*N_t-PD_i*LGD_i)*((1+(M_i-2.5)*b_i)/(1-1.5*b_i)):
omega_i:=12.5*k_i:

CodeTools:-Usage( plot(omega_i,R_i_t=0.25..1.0) );

AP:=CodeTools:-Usage(numapprox:-minimax(omega_i, R_i_t= 0.25..0.9999, [6,1]));
plot([AP],R_i_t=0.25..1.0);

acer

Apply the `combine` command to your expression. You could also apply `simplify`, after that.

acer

First 243 244 245 246 247 248 249 Last Page 245 of 336