sand15

1484 Reputation

15 Badges

11 years, 90 days

MaplePrimes Activity


These are answers submitted by sand15

(Shame there is no example in the corresponding help page about this way to use dualaxisplot)

restart

with(Optimization):

NULL

_local(Pi);

`Π_12` := (0.1455251030e-2*Ce+.5352049476)*(0.369876310e-1+`-`(0.3638127575e-2*Ce))+.8*(-.1671790360+1.121361872*Ce)*(0.1849381518e-1+`-`(0.1819063782e-2*Ce))+`-`(Ce*(0.1849381518e-1+`-`(0.1819063782e-2*Ce)));

(0.1455251030e-2*Ce+.5352049476)*(0.369876310e-1-0.3638127575e-2*Ce)+(-.1337432288+.8970894976*Ce)*(0.1849381518e-1-0.1819063782e-2*Ce)-Ce*(0.1849381518e-1-0.1819063782e-2*Ce)

(1)

`Π_22` := Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(0.1455251030e-2, Ce), .5356096675), Student:-VectorCalculus:-`+`(0.355258312e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.3638127575e-2, Ce)))), Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`*`(.8, Student:-VectorCalculus:-`+`(-.1184158360, Student:-VectorCalculus:-`*`(1.121361872, Ce))), Student:-VectorCalculus:-`+`(0.1776291535e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce))))), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(Ce, Student:-VectorCalculus:-`+`(0.1776291535e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce))))));

(0.1455251030e-2*Ce+.5356096675)*(0.355258312e-1-0.3638127575e-2*Ce)+(-0.9473266880e-1+.8970894976*Ce)*(0.1776291535e-1-0.1819063782e-2*Ce)-Ce*(0.1776291535e-1-0.1819063782e-2*Ce)

(2)

`Π_32` := Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(0.1455251030e-2, Ce), .5356038465), Student:-VectorCalculus:-`+`(0.355403838e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.3638127575e-2, Ce)))), Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`*`(.8, Student:-VectorCalculus:-`+`(-.1179012835, Student:-VectorCalculus:-`*`(1.121361872, Ce))), Student:-VectorCalculus:-`+`(0.1777019161e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce))))), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(Ce, Student:-VectorCalculus:-`+`(0.1777019161e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce))))));

(0.1455251030e-2*Ce+.5356038465)*(0.355403838e-1-0.3638127575e-2*Ce)+(-0.9432102680e-1+.8970894976*Ce)*(0.1777019161e-1-0.1819063782e-2*Ce)-Ce*(0.1777019161e-1-0.1819063782e-2*Ce)

(3)

S12 := plot(`Π_12`, Ce = 0 .. 0.9e-1, color = [red], labels = ["Ce", "Manufacturer Profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("W"));`]):

`Π_1` := Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.60726413e-1, Ce)), .6173851967), Student:-VectorCalculus:-`+`(0.1849381518e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.2500000000e-1, Student:-VectorCalculus:-`+`(0.1849381518e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))^2)));

(-0.60726413e-1*Ce+.6173851967)*(0.1849381518e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1849381518e-1-0.1819063782e-2*Ce)^2

(4)

`Π_2` := Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.60726413e-1, Ce)), .5929853242), Student:-VectorCalculus:-`+`(0.1776291535e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.2500000000e-1, Student:-VectorCalculus:-`+`(0.1776291535e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))^2)));

(-0.60726413e-1*Ce+.5929853242)*(0.1776291535e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1776291535e-1-0.1819063782e-2*Ce)^2

(5)

`Π_3` := Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`*`(Student:-VectorCalculus:-`+`(Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.60726413e-1, Ce)), .5932282299), Student:-VectorCalculus:-`+`(0.1777019161e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))), Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.2500000000e-1, Student:-VectorCalculus:-`+`(0.1777019161e-1, Student:-VectorCalculus:-`-`(Student:-VectorCalculus:-`*`(0.1819063782e-2, Ce)))^2)));

(-0.60726413e-1*Ce+.5932282299)*(0.1777019161e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1777019161e-1-0.1819063782e-2*Ce)^2

(6)

S1 := plot(`Π_1`, Ce = 0 .. 0.9e-1, color = [yellow], labels = ["Ce", "Retailer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("W"));`]):

dualaxisplot(
  display(S1, S2, S3)
  ,
  display(S12, S22, S32)
)

 
 

``

Download All_plots_Combined_sand15.mw


One way is to give rho a numeric value BEFORE solving the ode system, the other one (which I use in the attached file) is to use the dsolve/numeric option 'parameters'.
 

Before doing this I advice you to rewrite the system you want to solve, which is actually a DAE (Differential Algebraic System), as an ODE system (Maple can solve DAE systems but I can't see any reasons for doing so here unless adding unnecessary complexity).
 

Once all this done dsolve is then capable to compute a solution. 
Nevertheless you will see in the attached file that an arbitrary choice of the rho value (I took rho = 1), leads to a singularity at time 0.57: because I have no idea of the values rho might have

(rho is ought to represent the density of Mars atmosphere, something about 20g/m3, but I don't know what are the units you use) 

it's hard to say more about this dicontinuity (real or simple artefact due to unrealistic rho value?).
Nevertheless a quick analysis is provided at the end of this answer.


SimpleMarsEntryAndAeroBrakingModel_sand15.mw



Note that other choices enable computing the solution for arbitrary much larger times, for instance

ans(parameters=[0.1])
                          [rho = 0.1]

display(
  Matrix(2, 3, [seq(odeplot(ans, [t, u], t=0..100, title=typeset(u)), u in unknowns)])
)


Nevertheless I suppose you want to end the simulation when the probe hits the ground, don't you?  
If it is so, let landing_t the time when the probe reaches Mars surface. Given its average radius is 3389.5 Km, landing_t verifies  r(landing_t) = 3389.5. The easiest way to stop the simulation when this latter condition is fullfiled uses the dsolve/numeric 'events' option:

landing_r := 3389.5; # kilometers

ans := dsolve(
         ODESYS
         , numeric
         , method = rkf45
         , maxfun = -1
         , parameters = params
         , events = [[r(t) = landing_r, halt]]
       ):

# Specialize the solution for some given value of rho, here rho=0.1

ans(parameters=[0.1]);
                  [rho = .1]

# initialize the solution procedure for some time a priori larger than
# the expected landing time:

ans(100):

# Catch the value of landing_t (meaning the value of t which fires the event)

landing_t := ans(eventfired=[1])[]
Warning, cannot evaluate the solution further right of 264.44373, event #1 triggered a halt
                   landing_t := 11.9098649021394

Next do the plots from 0 to landing_t.
For more details download the worksheets at the end of this answer.


By the way: shouldn't  g be equal to the gravitational acceleration on Mars (about 3.73 m/s2 ... you seem to get a value of about 12.64 m/s2)?


Last but not least: the worksheet below provides a short analysis of the emergence of a singularity. From this analysis it is clear that the right hand side of the d𝜙(t)/dt equation takes an infinite value for some finite time and that comes from (cos(𝛾(t)) = 0 at this same time (cos(𝛾(t)) is present at the denominator of d𝜙(t)/dt equation).
This means the flight path angle 𝛾(t) is equal to -𝜋/2 at finite time (vertical drop)... which should not be possible when there is friction.
My advice: check your equations, data and units.

singularity_analysis_sand15.mw   see also   capturing_cos(gamma(t))=0.mw

I guess someone else could interpret your question differently and provide another answer.
Whatever here is mine: My_interpretation.mw (file can't be uploaded)

-0.06888275721

You write "I want to choose A to obtain the smallest absolute value of Em, preferably ~ -0.00005".
I suppose you want to say "I want to choose A to obtain the smallest absolute value of Em, preferably ~ +0.00005", don't you?

Whatever, Em is strctly negative for A > 0 and its limit when A goes to 0 from the right is -0.06888275721, which means that your requirement cannot be met.

Note that for A = 0 we have  E(𝜐) = C𝜐2 + -0.06888275721 which immediatly gives the value of C... but the fitted model is unacceptable has shown in the attached file.

At the very end I'm leaning to consider your problem is not correctly posed and I suggest you to consider carefully what you want to do.
ML_sand15.mw

for i2 varying from 0 to 1

doen't nmean anything at all as the 
Error, controlling variable of for loop must be a name or sequence of 2 names
says: between for and from you must have only one name (here you have i2 and varying).

Given the past worksheets you posted I don't even understand how you can have written  (sorry if I feel that rude) such a stupid  thing?
A few correct syntaxes are

for i2 from 0 to 1 do
...
end do:

for i2 from 0 to 1 by 1/3 do
...
end do:

# etc

Note that the first syntax seems quite stupid to me in your context:

# with K2 = 0.1968052257

for i2 from 0 to 1 do
  if i2 > K2 then 
    do_something
  else
    do_something_else
  endif:
end do:

because the counter (here i2) being an integer unless "by some_value" is specified, it takes only the values i1=0 and i2=1. So a simpler operation is 

Do_this := i2 -> piecewise(i2 > K2, do_something, do_something_else)

Nothing of what you try to achieve is clear to me.
Moreover, if you are not capable to manage correctly the 2D input document mode, just as I can't neither, use the 1D input worksheet mode (your file contains a lot of breaks which generate errors (yout for anf if structures do not end correctly).

Whatever... look to the attached file to see how to write something error free A_no_error_worksheet_sand15.mw and try to use it contents to formulate correctly your problem (which I repeat I do not understand).

(done with Maple 2015 but should work the same with Maple 2018)
One_way_sand15.mw   (read carefully the last comment in thiw worksheet)


Proceed the same way for the 3D plots by replacing p1_final by p1 in C11 and p2_final by p2 in C12.

Note: If you do some browsing on this same site you should be able to find several questions about the same subject.
@acer already gave a lot of answers too [moderator: eg. here, here, here]
[moderator: If you need to export the 3D plot with colorbar in such an old Maple version then see also here.]

[moderator: colorbars received direct support for 3D plotting commands in Maple 2024.]

restart;
n := 0:
L := []:

for a from 3 to 100 do
    for b from 3 to a do
        c2 := a^2 - a*b + b^2;
        c := isqrt(c2);
        if c^2 = c2 then
            if c < a + b and a < b + c and b < c + a then
                if igcd(a, b, c) = 1 then
                    x2 := (-a^2 + b^2 + c^2)/2;
                    y2 := (a^2 - b^2 + c^2)/2;
                    z2 := (a^2 + b^2 - c^2)/2;
                    if 0 < x2 and 0 < y2 and 0 < z2 then
                        # One way
                        S := [sqrt(x2), sqrt(y2), sqrt(z2)];
                        S := S[sort(evalf(S), output=permutation)];
                        x := S[1]; 
                        y := S[2]; 
                        z := S[3];
                        n := n + 1;
                        L := [op(L), [x, y, z, sqrt(x^2 + y^2), sqrt(y^2 + z^2), sqrt(x^2 + z^2)]];
                    end if;
                end if;
            end if;
        end if;
    end do;
end do;

n;
L;


Why was sort([sqrt(x2), sqrt(y2), sqrt(z2)]) ineffective?
Look at this

S0 := [6*sqrt(110), 2*sqrt(610), 3*sqrt(649)];
sort(S0, `>`)
Error, invalid input: a numeric list is expected for sort method ``>``

# To understand this "failure" look at this 
if S0[1] > S0[2] then "yes" else "no" end if;
Error, cannot determine if this expression is true or false: 2*610^(1/2) < 6*110^(1/2)

So sort, which vasically uses an if structure, simply doesn't know how to compare these two non rational numbers.

Note that is can do it:

is(S0[1] > S0[2]);
                             true
is(S0[1] < S0[2]);
                             false

 

(strangely it takes a long time to be processed)

restart

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

expr := sqrt((-alpha^2*x^2 + R^2 + x^2)/(-alpha^2*x^2 + R^2))/sqrt(R^4/((-alpha^2*x^2 + R^2 + x^2)^2*(-alpha^2*x^2 + R^2))):

subexpr := indets(expr, `+`);
CodeTools:-Usage( simplify(expr) assuming op(subexpr >=~ 0), R >= 0 )

{-alpha^2*x^2+R^2, -alpha^2*x^2+R^2+x^2}

 

memory used=0.59GiB, alloc change=429.34MiB, cpu time=8.33s, real time=8.16s, gc time=356.09ms

 

(-alpha^2*x^2+R^2+x^2)^(3/2)/R^2

(2)
 

 

Download simplify_radical_sand15.mw

From the code below you should be able to define any binary operator you want.

restart

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

Isom := `&cong;`:
Isom(A, B);

`&cong;`(A, B)

(2)

IsContained := `&#x2286;`:
IsContained(A, B)

`&#x2286;`(A, B)

(3)

IsNotContained := `&#x2288;`:
IsNotContained(A, B)

`&#x2288;`(A, B)

(4)

DoesNotContain := `&#x2289;`:
DoesNotContain(A, B)

`&#x2289;`(A, B)

(5)

# For details look to the answers to this QUESTION

`print/Fs` := proc(x,y)
   uses Typesetting;
   mrow(
     Typeset(x),
     mo("&InvisibleTimes;"),
     mover(mo("&rarr;"),mo("s")),
     mo("&InvisibleTimes;"),
     Typeset(y)
   );
end proc:

Fs(A, B)

Fs(A, B)

(6)

# For any other hexadecimal code see HERE , for instance here are different arrows:

`#mo("&mapsto;")`;

`#mo("&#x21a3;")`;

`#mo("&#x21a0;")`;

`#mo("&mapsto;")`

 

`#mo("&#x21a3;")`

 

`#mo("&#x21a0;")`

(7)
 

 

Download Special_Operators.mw

AA := value( eval(A, {Omega = (t -> 1), chi = (t -> 1), g = (t -> 1), i = 1, p = (t -> 1), i = 1}) );
has(AA, {int, Int})
                             false

h-pde-M_sand15.mw

t-plot_sand15.mw

Some functions, like 'sin' for instance, leads to an unevaluated integral.

Even using evalf/Int doesn't help for the the numeric values are Float(undefined).

restart

ode := x^2 = sum(x*(diff(y(x), [`$`(x, i)]))/factorial(i), i = 0 .. 3);

x^2 = x*y(x)+x*(diff(y(x), x))+(1/2)*x*(diff(diff(y(x), x), x))+(1/6)*x*(diff(diff(diff(y(x), x), x), x))

(1)
 

 

ics := y(0) = 0, (D(y))(0) = 0, ((D@@2)(y))(0) = 0;

y(0) = 0, (D(y))(0) = 0, ((D@@2)(y))(0) = 0

(2)

sol := dsolve({ics, ode});

y(x) = x-1+(1/6)*(4*(2^(1/2)+1)^(2/3)-2*2^(1/2)*(2^(1/2)+1)^(2/3)+2^(1/2)*(2^(1/2)+1)^(1/3)-(2^(1/2)+1)^(1/3)+1)*2^(1/2)*exp((2^(1/2)*(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(1/3)-1)*x)/((2^(1/2)+1)^(2/3)*(2*2^(1/2)-2))+(1/6)*(8*(2^(1/2)+1)^(2/3)-4*2^(1/2)*(2^(1/2)+1)^(2/3)-2^(1/2)*(2^(1/2)+1)^(1/3)+(2^(1/2)+1)^(1/3)-1)*2^(1/2)*exp(-(1/2)*(2^(1/2)*(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(1/3)+2)*x)*cos((1/2)*3^(1/2)*(2^(1/2)+1)^(1/3)*(2^(1/2)*(2^(1/2)+1)^(1/3)-(2^(1/2)+1)^(1/3)+1)*x)/((2^(1/2)+1)^(2/3)*(2*2^(1/2)-2))-(1/6)*(2^(1/2)*(2^(1/2)+1)^(1/3)-(2^(1/2)+1)^(1/3)-1)*3^(1/2)*2^(1/2)*exp(-(1/2)*(2^(1/2)*(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(2/3)-(2^(1/2)+1)^(1/3)+2)*x)*sin((1/2)*3^(1/2)*(2^(1/2)+1)^(1/3)*(2^(1/2)*(2^(1/2)+1)^(1/3)-(2^(1/2)+1)^(1/3)+1)*x)/((2^(1/2)+1)^(2/3)*(2*2^(1/2)-2))

(3)

plot([rhs(sol), lhs(ode)], x = 0 .. 1, color = [red, blue], legend = `~`[typeset]([y(x), lhs(ode)]))

 

plot([eval(rhs(ode), sol), lhs(ode)], x = 0 .. 1, color = [red, blue], style = [line, point], numpoints = 30, legend = `~`[typeset]([('rhs')('ode'), lhs(ode)]))

 

``

Download DGL_test_sand15.mw

@JoyDivisionMan 

Using "blindly" Maple (2015) provides a wrong result (see attached file) for, I guess, maple does not handle correctly the absolute value.

So here is he trick.
Let
fZ(z) the pdf of Z = |Y- Y2| and  fU(u) the pdf of U = Y- Y2.
Of course the support of Z is (0, 2) while U's is (-2, 2). But Y1 and Y2 both having the same symmetic distribution it is easy to see that 
fU(u) is symmetric too.
So consider only the restriction of
fU(u) the its half support (0, 2) and twice this latter: then 2fU(u) = fZ(u).

With that trixk Maple provides the corret result.

Note that fU(u) can be computed using a convolution product.
Indeed U = Y1 - Y2 = Y1 + (-Y2) = Y1 + Y2 because
fY(y) is symmetrc wrt y=0.
Then 
fU(u) = (fY * fY)(y) where '*' denotes the convolution produce.

Please, if that's okay with you, don't forget (as it was the case with your last question) to let me know.
(Doing work for someone without knowing whether they appreciated it or not is never pleasant.)

restart

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

with(Statistics):

f := x -> piecewise(abs(x) < 1, 2*sqrt(1 - x^2)/Pi, 0);

proc (x) options operator, arrow; piecewise(abs(x) < 1, 2*sqrt(1-x^2)/Pi, 0) end proc

(2)

F := unapply(int(f(t), t=-1..x), x);

proc (x) options operator, arrow; piecewise(x <= -1, 0, x <= 1, (1/2)*(2*x*(1-x^2)^(1/2)+2*arcsin(x)+Pi)/Pi, 1 < x, 1) end proc

(3)

d := Distribution(
       PDF = (x -> f(x)),
       CDF = (x -> F(x))
     ):

Y__1 := RandomVariable(d):
Y__2 := RandomVariable(d):

# From symmetry considerations the PDF of Z is twice the PDF of U restricted to U > 0

Z := abs(U):
U := Y__1 - Y__2:
 

# Note the  term in the case 0 < z < 1 !!!
# This is obviously a bug.

PDF(Z, z);

piecewise(z <= 0, 0, z < 1, (1/3)*(I*sqrt(2)*EllipticE(I*z/sqrt(-z^2+4))*sqrt(2*z+4)*sqrt(-z+2)*z^2+(4*I)*sqrt(2)*EllipticE(I*z/sqrt(-z^2+4))*sqrt(2*z+4)*sqrt(-z+2)-(4*I)*sqrt(2)*EllipticK(I*z/sqrt(-z^2+4))*sqrt(2*z+4)*sqrt(-z+2)+2*EllipticE((-2+z)/(2+z))*z^3+4*EllipticE((-2+z)/(2+z))*z^2-8*z^2*EllipticK((-2+z)/(2+z))+8*EllipticE((-2+z)/(2+z))*z-16*EllipticK((-2+z)/(2+z))*z+infinity+16*EllipticE((-2+z)/(2+z)))/Pi^2, z = 1, (20*EllipticE(1/3)-16*EllipticK(1/3))/Pi^2, z < 2, (1/3)*(I*sqrt(2)*sqrt(-2*z^2+8)*EllipticE((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8))*z^2+(4*I)*sqrt(2)*sqrt(-2*z^2+8)*EllipticE((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8))-(4*I)*sqrt(2)*sqrt(-2*z^2+8)*EllipticF((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8))+2*EllipticE((-2+z)/(2+z))*z^3+4*EllipticE((-2+z)/(2+z))*z^2-8*z^2*EllipticK((-2+z)/(2+z))+8*EllipticE((-2+z)/(2+z))*z-16*EllipticK((-2+z)/(2+z))*z+16*EllipticE((-2+z)/(2+z)))/Pi^2, z = 2, (1/3*I)*sqrt(2)*sqrt(-2*z^2+8)*(z^2*EllipticE((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8))+4*EllipticE((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8))-4*EllipticF((1/2*I)*sqrt(-2*z^2+8)*sqrt(2)/z, I*z*sqrt(2)/sqrt(-2*z^2+8)))/Pi^2, 2 < z, 0)

(4)

# To help Maple find the correct PDF we may observe that, from symmetry considerations,
# the PDF of Z is twice the PDF of U = Y__1 - Y__2 once restricted to U > 0

U := Y__1 - Y__2:

f__U := unapply( (2*PDF(U, u) assuming u > 0), u);

proc (u) options operator, arrow; 2*piecewise(u <= 1, -(2/3)*(-EllipticE((-2+u)/(2+u))*u^3+4*u^2*EllipticK((-2+u)/(2+u))-2*EllipticE((-2+u)/(2+u))*u^2+8*EllipticK((-2+u)/(2+u))*u-4*EllipticE((-2+u)/(2+u))*u-8*EllipticE((-2+u)/(2+u)))/Pi^2, u <= 2, ((1/3)*I)*2^(1/2)*(-2*u^2+8)^(1/2)*(u^2*EllipticE(((1/2)*I)*(-2*u^2+8)^(1/2)*2^(1/2)/u, I*u*2^(1/2)/(-2*u^2+8)^(1/2))+4*EllipticE(((1/2)*I)*(-2*u^2+8)^(1/2)*2^(1/2)/u, I*u*2^(1/2)/(-2*u^2+8)^(1/2))-4*EllipticF(((1/2)*I)*(-2*u^2+8)^(1/2)*2^(1/2)/u, I*u*2^(1/2)/(-2*u^2+8)^(1/2)))/Pi^2, 2 < u, 0) end proc

(5)

S__Z := Sample(Z, 10^6):

plots:-display(
  Histogram(S__Z, transparency=0.7, minbins=100, style=polygon)
  , plot(f__U(u), u=0..2, color=red, thickness=2, legend=typeset(:-PDF('Z')))
)

 

F__U := proc(u)
  option remember:
  local F1;
  F1 := 2*evalf(Int(op([2, 2], f__U(t)), t=0..1)):
  if _passed::numeric then
    if u <= 1 then
      2*evalf(Int(op([2, 2], f__U(t)), t=0..u))
    elif u <= 2 then
      F1 + 2*evalf(Int(Re(op([2, 4], f__U(t))), t=1..u, method = _d01ajc))
    end if:
  else
    procname(_passed)
  end if:
end proc:

plot([seq([u, F__U(u)], u=0..2, 0.1)], color=red, thickness=2, legend=typeset(:-CDF('Z')), gridlines=true)

 

# Because Y__1 and Y__2 both have the same symmetric PDF:
#
#      U = Y__1 - Y__2 = Y__1 + (-Y__2) = Y__1 + Y__2
#
# Thus the PDF of U can be obtained through a convolution product

f__Y := unapply(PDF(Y__1, y), y):

C := unapply( int(f__Y(y)*f__Y(u-y), y = -infinity..+infinity), u ):

plots:-display(
  Histogram(S__Z, transparency=0.7, minbins=100, style=polygon)
  , plot(2*C(u), u=0..2, color=red, thickness=2, legend=typeset(:-PDF('Z')))
)

 

Depending on what statistic you want it is sometimes more powerfull to use U instead of Z

:-Mean('Z') = Mean(Z);

Mean(Z) = (256/45)/Pi^2

(6)

:-Variance('Z') = Variance(Z);

Variance(Z) = (1/4050)*(2025*Pi^4-131072)/Pi^4

(7)

:-Median('Z') = Median(Z);
:-Median('Z') = Median(Z, numeric);

Median(Z) = FAIL

 

Median(Z) = FAIL

(8)

:-Median('Z') = fsolve('F__U'(u)=0.5, u=0..2);
med := rhs(%):

Median(Z) = .5039577742

(9)

  Spline approximation of F__U

S__U := unapply(CurveFitting:-Spline([seq([u, F__U(u)], u=0..2, 0.25)], u), u):

Procedure to compute quantiles of Z

quantile := proc(p)
  local guess:
  if F__U(1) > p then
  # guess := fsolve(S__U(u)=p, u=0..1)
    guess := fsolve('F__U'(u)=p, u=0..1)
  else
    guess := fsolve(S__U(u)=p, u=1..2)
  end if:
  return [guess, ``(F__U(guess))]:
end proc:

:-Quantile('Z', 0.05) = quantile(0.05);  # Exact, based on F__U
:-Quantile('Z', 0.80) = quantile(0.80);  # Exact, based on F__U
:-Quantile('Z', 0.85) = quantile(0.85);  # Approximation based on S__U
:-Quantile('Z', 0.95) = quantile(0.95);  # Approximation bBased on S__U

Quantile(Z, 0.5e-1) = [0.4632571579e-1, ``(0.5000000000e-1)]

 

Quantile(Z, .80) = [.9415058879, ``(.8000000000)]

 

Quantile(Z, .85) = [1.046701043, ``(.8500051833)]

 

Quantile(Z, .95) = [1.354720239, ``(.9500107106)]

(10)

L := limit(f__U(u), u=0, right);

if false then
  plots:-display(
    plot(f__U(u), u=0..2, color=red),
    plottools:-transform((x, y) -> [2-x, L-y])(plot(f__U(u), u=0..2, color=blue))
  );
end if;

(32/3)/Pi^2

(11)
 

 

Download PDF_Z_sand15.mw


𝛑_m is a priori quadratic wrt i1 so 𝛑_m has only one extremum swhose status (minimum vs maximum) depends on the sign of the coefficient of  i12.


Note: I say "𝛑_m is a priori quadratic wrt i1" for 𝛑_m writes P . i12 + Q . i1 + R where P, Q, R are expressions which depend on several parameters. It could therefore happen that, depending on the values of these parameters, P, or even P and Q, might be equal to 0.
The case P = 0, Q <> 0 is even simpler because 𝛑_m necessary reaches its the minimum at one of the two boundaries defined by A and B (see below the meaning of these two quantities)

As you did not provide more informations I considered arbitrarily that P was different from 0.



Let x* the location of this extremum and D the domain defined by the two primal feasibility conditions

  • f1 : A <= i1
  • f2 : i1 <=  B (B supposedly larger than A of course)

Assuming for instance that P <> 0 and that 𝛑_m reaches its minimum at some point  i= x*,  three cases are to be examined: 

  1. x* < A
    The constrained minimum is x* = A
  2.  x* > B
    The constrained minimum is x* = B
  3.  A < x* > B
    The constrained minimum is x* 

Assuming now that  P = 0 and Q <> 0, we find the location of the minimizer  i= x* of  𝛑_m corresponds to one of these two cases:

  1. 𝛑_m(A) < 𝛑_m(B)  
    The constrained minimum is x* = A
  2.  𝛑_m(A) > 𝛑_m(B) 
    The constrained minimum is x* = B


I don't really think it's necessary to write KKT conditions and solve grad(Lagrangian(i1, 𝛍1, 𝛍2)) = 0 wrt i1, 𝛍1, 𝛍2 to get this result.

Basically your problem can be parameterized by the four quantities P, Q, A, B.

Why not simply use solve/parametric to get all the possible solutions?

restart

SC_CS_sols := solve(
  {
    diff(P*i1^2 + Q*i1 + R, i1) - mu[1] + mu[2] = 0,
    mu[1]*(A-i1) = 0,
    mu[2]*(i1-B) = 0
  }
  ,
  {i1, mu[1], mu[2]}
  , 'parametric'='full', 'parameters'={P, Q, A, B}
)

-

(1)

pi__m := (w-i1)*(1/2+(i1-i2)/(2*tau))*(1-(Pn-Pr)/(1-delta))-C0-(1/2)*Cr*(1/2+(i1-i2)/(2*tau))^2*(1-(Pn-Pr)/(1-delta))^2+Ce*rho0*(1-(Pn-Pr)/(1-delta)):

collect(pi__m, i1):
PQR := [R, Q, P] =~ [coeffs(%, i1)]:

print~(PQR):

R = w*(1/2-(1/2)*i2/tau)*(1-(Pn-Pr)/(1-delta))-C0-(1/2)*Cr*(1/2-(1/2)*i2/tau)^2*(1-(Pn-Pr)/(1-delta))^2+Ce*rho0*(1-(Pn-Pr)/(1-delta))

 

Q = ((1/2)*w/tau-1/2+(1/2)*i2/tau)*(1-(Pn-Pr)/(1-delta))-(1/2)*Cr*(1/2-(1/2)*i2/tau)*(1-(Pn-Pr)/(1-delta))^2/tau

 

P = -(1/2)*(1-(Pn-Pr)/(1-delta))/tau-(1/8)*Cr*(1-(Pn-Pr)/(1-delta))^2/tau^2

(2)

AB := [A = (2*rho0-1)*tau+i2, B = tau+i2]

[A = (2*rho0-1)*tau+i2, B = tau+i2]

(3)

ind  := indets(rhs~(PQR)) union indets(rhs~(AB));

{C0, Ce, Cr, Pn, Pr, delta, i2, rho0, tau, w}

(4)

randomize();

data := { seq(i = rand(0. .. 1.)(), i in ind) };
PQRAB := { eval(PQR, data)[], eval(AB, data)[] };

all_solutions := allvalues~(eval(SC_CS_sols, PQRAB)):
all_pi        := map(s -> eval(eval(pi__m, data), s), all_solutions):
here          := ListTools:-Search(min(all_pi), all_pi):
SOLUTION      := [all_pi[here], all_solutions[here]];


plot(eval(pi__m, data), i1=eval(eval(A..B, AB), data), gridlines=true)

175924829835607

 

{C0 = .167064416, Ce = -.899672867, Cr = -.441294366, Pn = .503882321, Pr = 0.48254531e-1, delta = .489131329, i2 = -.636135505, rho0 = -.313162033, tau = .976577920, w = .776413374}

 

{A = -2.224367679, B = .340442415, P = -0.5468605776e-1, Q = -0.4411823164e-1, R = -0.6551927135e-1}

 

[-.2379604124, {i1 = -2.224367679, mu[1] = .1991655671, mu[2] = 0}]

 

 

 


 

Download proposal_sand15.mw

 

1 2 3 4 5 6 7 Page 3 of 10