Joe Riel

9565 Reputation

23 Badges

18 years, 355 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The module action is assigned in the startup region; click the Edit Startup Code button on the toolbar, the button has two filled circles. The module exports procedures used by the embedded components.  The code appears to be working, but I don't understand how to use it. Clicking the "Laes and Plot Data" button prints the equivalent of "you must select at least two points", which wasn't obvious to me.  Ah, I see.  Need to highlight a region in the Data.  That works.

Note the error "unterminated procedure".  The input region (starting with far left ">") ends before the procedure.  Being lazy, I just exported the worksheet as 1D maple input then edited it.  It runs. Note that FirmModelPP does not reference parameter alpha.
 

restart;
with(plots):
c := 1:
cr := 0.0300000000*c:
u := 1:
sExp := 0.0600000000*c:
s := 0.6500000000*c:
v := 3*c:

FirmModelPP := proc(alpha, delta)
local p0, xi0, q0, Firmpf0, G0, Recpf0, Unsold0, Environ0;
option remember;
    xi0 := 1; p0 := min(s + sqrt((v - s)*(c - s)), delta*v + sExp);
    q0 := u*(v - p0)/(v - s);
    f(N) := 1/u;
    F(N) := N/u;
    G0 := int(F(N), N = 0 .. q0);
    Firmpf0 := (p0 - c)*q0 - (p0 - s)*G0;
    Recpf0 := (sExp - cr)*xi0*q0;
    Environ0 := G0 + q0;
    Unsold0 := G0;
    return p0, q0, Firmpf0, Recpf0, Unsold0, Environ0;
end proc:

FirmModelFC := proc(alpha, beta, delta)
local p00, xi00, q00, Firmpf00, G00, Recpf00, Unsold00, Environ00, pr00;
option remember;
    xi00 := 1;
    p00 := s + sqrt((v - s)*(c - s));
    if p00 < delta*v + sExp then q00 := u*(v - p00)/(v - s);
        f(N) := 1/u;
        F(N) := N/u;
        G00 := int(F(N), N = 0 .. q00);
        Firmpf00 := (p00 - c)*q00 - (p00 - s)*G00;
        Recpf00 := `&xi;00*q00*`(sExp - cr);
        Unsold00 := G00;
        Environ00 := q00 + Unsold00;
    else q00 := alpha*u*(v - p00)/(v - s);
        f(N) := 1/u;
        F(N) := N/u;
        G00 := int(F(N), N = 0 .. q00/alpha);
        pr00 := p00 - delta*v;
        Firmpf00 := (p00 - c)*q00 - alpha*(p00 - s)*G00;
        Recpf00 := (beta*(pr00 - sExp) + sExp - cr)*xi00*q00 - 1/2*(pr00 - sExp)*beta^2*xi00^2*q00^2/(u*(1 - alpha));
        Unsold00 := G00;
        Environ00 := q00 + Unsold00;
    end if;
    return p00, q00, Firmpf00, Recpf00, Unsold00, Environ00;
end proc:

CurrentMetrics:= proc(alpha,beta,delta) option remember;
local  p, q, Firmpf,Recpf,Unsold,Environ;

    if (FirmModelFC(alpha,beta,delta)[3]>=FirmModelPP(alpha,delta)[3]) then
        p := FirmModelFC(alpha,beta,delta)[1];
        q := FirmModelFC(alpha,beta,delta)[2];
        Firmpf := FirmModelFC(alpha,beta,delta)[3];
        Recpf:=FirmModelFC(alpha,beta,delta)[4];
        Unsold:=FirmModelFC(alpha,beta,delta)[5];
        Environ:=FirmModelFC(alpha,beta,delta)[6];
    else
        p:=FirmModelPP(alpha,delta)[1];
        q:=FirmModelPP(alpha,delta)[2];
        Firmpf:=FirmModelPP(alpha,delta)[3];
        Recpf:=FirmModelPP(alpha,delta)[4];
        Unsold:=FirmModelPP(alpha,delta)[5];
        Environ:=FirmModelPP(alpha,delta)[6];
    end if ;
    return p,q,Firmpf,Recpf, Unsold,Environ;
end proc:



plot(['CurrentMetrics(alpha, 0.2000000000, 0.2000000000)[3]']
     , 'alpha' = 0.0000000000 .. 1.0000000000
     , 'linestyle' = ['solid']
     , 'legend' = ["Firm's profit with delta=0.2"]
     , 'labels' = [alpha, "Firm profit"]
     , 'labeldirections' = ["horizontal", "vertical"]
     , 'color' = ['blue']
     , 'axes' = 'boxed'
    );

 

I'm not sure I understand your objection.  Assume the first call to randpoly, randpoly([y], terms=1, degree=1, coeffs=rand(-4..1)),  returns -y-4, which it can.  Is the problem the inclusion of the -4 term?  Admittedly it's a bit unexpected when terms=1. You can eliminate it by passing the option 'homogeneous' to randpoly.

A workaround is to disable the start page by checking the "Do not show this page" checkbox in the home page.  To restore it, or change it, use Tools > Options > Interface and change the Open worksheet at startup menu selection. While I've normally have that set to "New, blank", am currently not noticing a slowdown when "Default home page" is selected.

The first has 24*kPa, the second 24.5*kPa.

Pass the option 'datasetlabels=contents' to the call to VennDiagram.  You'll see why the default is 'absolute'.

A workaround is to replace int with Int, then apply eval, say with map(eval@Int, ... ).

Later
A problem is the occurrence of varphi(t) in the call to int, when varphi is the variable of integration.

Drop the y = -1 .. 1 argument in the call to plot

I don't know of a direct way to do this.  It can be manually be done by first selecting the text, typing Control X (to delete and copy the text), then typing a pair of matched parentheses, moving back one character, then typing Control V to insert the text.

By default Iterator creates and uses compiled procedures.  Possibly Compiler:-Compile is unable to write to that directory (I have no idea why).  As a workaround, pass the option compile=false to the call to FillRucksack.

Later In Maple Standard, open Tools > Options > Security and see if you have activated any of the security settings that might prevent writing.

Have you tried using a table to position the various elements?   Split the table into an appropriate number of rows and columns, possibly joining some cells to make larger cells, and insert the embedded components into the cells.  You can make the dividers invisible.  While it's not perfect, it works reasonably well.

You stated the input is a set, but assigned a list to S.  I'm going to assume that the elements are symbols, but the same symbol can appear more than once.  Solving that is equivalent to finding all partitions of a multiset, which can be achieved with the Iterator:-MultiPartition procedure.   Presumably this could be simplfied if only distinct symbols are allowed (i.e partitions of a set).  Here's a solution

SumsOfList := proc(L :: list(symbol) )
local A, M, N, S, W, i, j, l, n, x;
    x := convert(L, 'compose', 'set', 'list');
    n := numelems(x);
    S := add(L);
    N := map2(coeff, S, x);
    M := Iterator:-MultiPartition(N);
    A := Array(1..0);
    for W in M do
        l := length(M);
        A ,= [seq(add(W[i,j]*x[i],i=1..n),j=1..l)];
    end do;
    convert(A, 'list');
end proc:

SumsOfList([a,b,c]);
                 [[a + b + c], [a + b, c], [a + c, b], [a, b + c], [a, b, c]]
SumsOfList([a,a,b,c]);
        [[2 a + b + c], [2 a + b, c], [2 a + c, b], [2 a, b + c], [2 a, b, c], [a + b + c, a], [a + b, a + c], [a + b, a, c], [a + c, a, b], [a, a, b + c], [a, a, b, c]]

 

An immediate issue is that simplify is not threadsafe, so parallelizing the routine using Threads is doomed.  You could do so using the Grid package, for example

CleanExpr := proc(expr, i, phi, coe, coefmodel)
local aaa, bbb, ccc, ind;
    try
        aaa := simplify(subs(coefmodel,expr)):
        if has(aaa,I) then
            return NULL;
        else
            bbb := simplify(subs(coefmodel,phi)):
            ccc := simplify(subs(coefmodel,coe)):
            ind := i:
            return [aaa,bbb,ccc,ind];
        end if:
    catch:
        return NULL;
    end try:
end proc:


sys := [NULL
        , (-x*rho*xi[6]*(beta - 1)*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) - xi[8]*(-2*y*sigma*xi[7]*xi[6]^2*(beta - 1)^2 + (sigma*rho + (sigma + 1)*(beta - 1))*x*rho*xi[6] + 2*sigma*z*rho^2*xi[8]))/(2*xi[6]*xi[8]*rho*(beta - 1))
        , (-(beta - 1)*(-y*sigma*xi[7]*xi[6]^2*(beta - 1)^2 + rho^2*(sigma*z*xi[8] + x^2))*xi[6]*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) - (2*sigma*(beta - 1)^2*(y*xi[7]*(rho + beta - 1)*sigma/2 + x^2*rho + y*(beta - 1)*xi[7]/2)*xi[6]^3 + 2*x*z*rho*sigma*xi[8]*(beta - 1)^2*xi[6]^2 + (-z*xi[8]*(rho + beta - 1)*sigma^2 + ((2*beta^2*z - 3*beta*z + z)*xi[8] + x^2*rho - (beta - 1)*(-2*beta*y*xi[7] + x^2))*sigma + x^2*(beta - 1))*rho^2*xi[6] + 2*x*z*rho^3*sigma*xi[8])*xi[8])/(2*xi[8]*sigma*(beta - 1)*(rho^2 + (beta - 1)^2*xi[6]^2)*xi[6]*xi[7])
        , (-(-x*sigma*(beta - 1)^2*xi[6]^3 + (beta - 1)^2*(sigma*y*xi[7] + x^2)*xi[6]^2 - rho^2*sigma*x*xi[6] - sigma*z*rho^2*xi[8])*(beta - 1)*rho*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) + xi[8]*(-2*y*sigma^2*xi[7]*(beta - 1)^4*xi[6]^4 + 2*(rho*(rho + beta - 1)*sigma/2 + (beta - 1)*((-beta + 1/2)*rho + y*(beta - 1)*xi[7]))*sigma*(beta - 1)^2*x*xi[6]^3 + (beta - 1)^2*(((-y*xi[7] + 2*z*xi[8])*rho + y*(beta - 1)*xi[7])*sigma^2 + (x^2*rho + (beta - 1)*(-2*beta*y*xi[7] - 2*beta*z*xi[8] + x^2 + y*xi[7]))*sigma - x^2*(beta - 1))*rho*xi[6]^2 + 2*(rho*(rho + beta - 1)*sigma/2 + (beta - 1)*((-beta + 1/2)*rho + y*(beta - 1)*xi[7]))*sigma*x*rho^2*xi[6] + xi[8]*sigma*z*((rho - beta + 1)*sigma - beta + 1)*rho^3))/(2*xi[8]^2*sigma*(beta - 1)*rho*(rho^2 + (beta - 1)^2*xi[6]^2))
       ]:
coefmodel := {beta = 8/3, rho = 28, sigma = 10}:
phi := [[], [], []]:
coe := [[], [], []]:

result := [Grid:-Seq](CleanExpr(sys[i], i, phi[i], coe[i], coefmodel), i = 1 .. numelems(sys)):
op(ListTools:-Transpose(result));

 

You have declared xpsn, ypsn, and zpsn as local to ppp; as such they are not accessible in Qprj.  Maybe you meant to make them local to rt?

MapleSim comes with DA and AD components; look in Electrical -> Analog -> Converters.

1 2 3 4 5 6 7 Last Page 2 of 114