MaPal93

90 Reputation

4 Badges

2 years, 341 days

MaplePrimes Activity


These are questions asked by MaPal93

Details here: non-dimensionalization.mw. Thanks!

In short, I want to plot all the ten roots of a 10th-degree polynomial in _Z with 4 or 5 primitive parameters. To do so, I need to find that combination of parameters that allows me to transform/scale/non-dimensionalize the original polynomial in a polynomial in _Z with just (1) one parameter or at maximum (2) two parameters. In the case of (1), I can plot its roots in a standard 2D plot against the single parameter. In the case of (2), I can plot the roots in a standard 3D plot against the two parameters.

I want to export plots as PNG but found in the past that when using commands to automate the process (and explicitly controlling for image quality) some symbolic notation on the axes or in the plots themselves are translated to 1D.

Anyway, regardless of the reason just provided, I have a preference for exporting plots as PNG manually rather than automatically in some of my scripts. How to do this while ensuring the best quality? By default, manual exports into PNG have quite bad quality. 

How to interpret the output to limit()?

restart;
local gamma;

gamma

(1)

A := -sigma__v^2*(((-2*gamma^2*sigma__d^4*sigma__e^4 - 16)*sigma__v^6 + (-6*gamma^2*sigma__d^4*sigma__e^6 - 4*gamma^2*sigma__d^2*sigma__e^4 - 48*sigma__e^2)*sigma__v^4 - sigma__e^4*(gamma^4*sigma__d^6*sigma__e^6 + 4*gamma^2*sigma__d^4*sigma__e^4 + 8*gamma^2*sigma__d^2*sigma__e^2 + 48)*sigma__v^2 - 4*gamma^2*sigma__d^2*sigma__e^8 - 16*sigma__e^6)*sqrt(gamma^2*sigma__d^2*sigma__e^4 + 4*sigma__e^2 + 4*sigma__v^2) + (2*sigma__d^2*sigma__v^8 + (12*sigma__d^2*sigma__e^2 + 8)*sigma__v^6 + 2*(12 + gamma^2*sigma__d^4*sigma__e^4 + sigma__d^2*(gamma^2 + 13)*sigma__e^2)*sigma__e^2*sigma__v^4 + 8*(3 + gamma^2*sigma__d^4*sigma__e^4 + sigma__d^2*(gamma^2 + 6)*sigma__e^2/2)*sigma__e^4*sigma__v^2 + sigma__e^6*(gamma^2*sigma__d^2*sigma__e^2 + 4)*(gamma^2*sigma__d^4*sigma__e^4 + 2*sigma__d^2*sigma__e^2 + 2))*sigma__v^2*gamma*sigma__d)*sigma__d/(4*(sigma__e^2 + sigma__v^2)^2*(gamma^2*sigma__d^2*sigma__e^4 + 4*sigma__e^2 + 4*sigma__v^2)^2);

-(1/4)*sigma__v^2*(((-2*gamma^2*sigma__d^4*sigma__e^4-16)*sigma__v^6+(-6*gamma^2*sigma__d^4*sigma__e^6-4*gamma^2*sigma__d^2*sigma__e^4-48*sigma__e^2)*sigma__v^4-sigma__e^4*(gamma^4*sigma__d^6*sigma__e^6+4*gamma^2*sigma__d^4*sigma__e^4+8*gamma^2*sigma__d^2*sigma__e^2+48)*sigma__v^2-4*gamma^2*sigma__d^2*sigma__e^8-16*sigma__e^6)*(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2)+(2*sigma__d^2*sigma__v^8+(12*sigma__d^2*sigma__e^2+8)*sigma__v^6+2*(12+gamma^2*sigma__d^4*sigma__e^4+sigma__d^2*(gamma^2+13)*sigma__e^2)*sigma__e^2*sigma__v^4+8*(3+gamma^2*sigma__d^4*sigma__e^4+(1/2)*sigma__d^2*(gamma^2+6)*sigma__e^2)*sigma__e^4*sigma__v^2+sigma__e^6*(gamma^2*sigma__d^2*sigma__e^2+4)*(gamma^2*sigma__d^4*sigma__e^4+2*sigma__d^2*sigma__e^2+2))*sigma__v^2*gamma*sigma__d)*sigma__d/((sigma__e^2+sigma__v^2)^2*(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^2)

(2)

# Limits

A__0 := limit(A, gamma = 0);
A__inf_wo_assumptions := limit(A, gamma = infinity);
A__inf_with_assumptions := limit(A, gamma = infinity) assuming 0 < sigma__e, 0 < sigma__v, 0 < sigma__d;

(1/2)*sigma__v^2*sigma__d/(sigma__e^2+sigma__v^2)^(1/2)

 

signum(sigma__d^3*sigma__e^2*sigma__v^4*(-sigma__d*sigma__e^2+(sigma__d^2*sigma__e^4)^(1/2))/(sigma__e^2+sigma__v^2)^2)*infinity

 

0

(3)

Download limits_signum.mw

Question is attached:

I describe in words the problem I want to solve with Maple. I'll need to work with random variables.

I want to compute Var[A+B+C] where A, B, and C are not independent of each other. In particular, I don't know how to compute Cov[A,B], Cov[A,C], and Cov[B,C]. The model specifications follow.

Let:

A = X__1*(-lambda__1*X__1-lambda__1*delta__1+nu__1-nu__01);
B = X__2*(-lambda__2*X__2-lambda__2*delta__2+nu__2-nu__02);
A = X__3*(-lambda__3*X__3-lambda__3*delta__3+nu__1+nu__2-nu__01-nu__02);

A = X__1*(-X__1*lambda__1-delta__1*lambda__1-nu__01+nu__1)

 

B = X__2*(-X__2*lambda__2-delta__2*lambda__2-nu__02+nu__2)

 

A = X__3*(-X__3*lambda__3-delta__3*lambda__3-nu__01-nu__02+nu__1+nu__2)

(1)

where lambda__1, lambda__2, and lambda__3 are constants. Moreover, nu__01 is the mean of nu__1~N(nu__01,sigma__nu^2)
and nu__02 is the mean of nu__2~N(nu__02,sigma__nu^2). Note that nu__1 and nu__2 have the same variance and are independent of each other.

In addition:

X__1 = beta__1*(nu__1+nu__2-nu__01-nu__02)+alpha__1*delta__1+alpha__2s*delta__2;
X__2 = beta__2*(nu__1+nu__2-nu__01-nu__02)+alpha__2*delta__2+alpha__1s*delta__1;
X__3 = beta__3*(nu__1+nu__2-nu__01-nu__02)+alpha__3*delta__3;

X__1 = beta__1*(nu__1+nu__2-nu__01-nu__02)+alpha__1*delta__1+alpha__2s*delta__2

 

X__2 = beta__2*(nu__1+nu__2-nu__01-nu__02)+alpha__2*delta__2+alpha__1s*delta__1

 

X__3 = beta__3*(nu__1+nu__2-nu__01-nu__02)+alpha__3*delta__3

(2)

where beta__1, beta__2, beta__3, alpha__1, alpha__2, alpha__3, alpha__1s, alpha__2s are constants. Moreover, delta__1~N(0,sigma__d^2), delta__2~N(0,sigma__d^2), and delta__3~N(0,sigma__d3^2) (note the different variance for delta__3). The variables delta__1, delta__2, and delta__3 are independent of each other. Moreover, nu__1 and nu__2 are independent of delta__1, delta__2, and delta__3.

Now, A, B, C are all products of the form W*Q. In general, Var[W*Q] can be found by applying a formula*** which here reduces to Var[W*Q] = sigma__W^2*sigma__Q^2+(Cov[W,Q])^2, where Cov[W,Q] is simply E[W*Q] since E[W]=0 and E[Q]=0 in my three cases. In short, it's relatively straightforward to find Var[A], Var[B], and Var[C]. However, I don't know about the covariance terms. How to tackle the covariance terms, i.e., Cov[A,B], Cov[A,C], and Cov[B,C]?


***See @whuber's comment in Prof. Dilip Sarwate's answer here https://stats.stackexchange.com/questions/15978/variance-of-product-of-dependent-variables


Perhaps it would be useful to automate the computation of E[A+B+C] as well. However, I managed to compute the expectation by hand, with pen and paper. It would be nice to double check with a script.

Download variance_of_sum_of_products.mw

I have an expression Z_val which I would like to rewrite in a compact, more readable form. Assuming that simplify() did its job, I thought of using (1) alias(), and (2) eval() with some combination of my parameters, since such combination occurs repetitively in my expression.

(1) is not particularly useful for my problem at hand. In particular, powers are not recognized and the alias I defined did not substitute the combination in all the places I was expecting to.

(2) is somehow effective but my expression becomes arguably even more complicated.

What else would you suggest?

EDIT:

restart;

local gamma;

gamma

(1)

M := -lambda*(beta^2*(sigma__v^2+sigma__e^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2;
V := simplify((1+(Cov__XY/(sigma__X*sigma__Y))^2)*(sigma__X*sigma__Y)^2);

-lambda*(beta^2*(sigma__e^2+sigma__v^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2

 

sigma__X^2*sigma__Y^2+Cov__XY^2

(2)

# Specify the terms, calculated by hand

sigma__X := beta^2*(sigma__v^2+sigma__e^2)+alpha^2*sigma__d^2;
sigma__Y := lambda^2*(beta^2*(sigma__v^2+sigma__e^2)+sigma__d^2*(alpha+1)^2)+sigma__v^2*(1-2*lambda*beta);
Cov__XY := M;

beta^2*(sigma__e^2+sigma__v^2)+alpha^2*sigma__d^2

 

lambda^2*(beta^2*(sigma__e^2+sigma__v^2)+sigma__d^2*(alpha+1)^2)+sigma__v^2*(-2*beta*lambda+1)

 

-lambda*(beta^2*(sigma__e^2+sigma__v^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2

(3)

V;

(beta^2*(sigma__e^2+sigma__v^2)+alpha^2*sigma__d^2)^2*(lambda^2*(beta^2*(sigma__e^2+sigma__v^2)+sigma__d^2*(alpha+1)^2)+sigma__v^2*(-2*beta*lambda+1))^2+(-lambda*(beta^2*(sigma__e^2+sigma__v^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2)^2

(4)

Z := M-(gamma/2)*V;

-lambda*(beta^2*(sigma__e^2+sigma__v^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2-(1/2)*gamma*((beta^2*(sigma__e^2+sigma__v^2)+alpha^2*sigma__d^2)^2*(lambda^2*(beta^2*(sigma__e^2+sigma__v^2)+sigma__d^2*(alpha+1)^2)+sigma__v^2*(-2*beta*lambda+1))^2+(-lambda*(beta^2*(sigma__e^2+sigma__v^2)+alpha*sigma__d^2*(alpha+1))+beta*sigma__v^2)^2)

(5)

# Specify lambda, beta, and alpha

l := simplify(-gamma*sigma__e^2*sigma__v^2/(2*(sigma__e^2 + sigma__v^2)) + sigma__v^2*sqrt(gamma^2*sigma__d^2*sigma__e^4 + 4*sigma__e^2 + 4*sigma__v^2)/(2*(sigma__e^2 + sigma__v^2)*sigma__d));
b := simplify(eval(sigma__v^2/((gamma*sigma__e^2 + 2*lambda)*sigma__v^2 + 2*lambda*sigma__e^2), lambda = l));
a := simplify(eval(-lambda*(sigma__e^2 + sigma__v^2)/((gamma*sigma__v^2 + 2*lambda)*sigma__e^2 + 2*lambda*sigma__v^2), lambda = l));

(1/2)*sigma__v^2*(-gamma*sigma__e^2*sigma__d+(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2))/((sigma__e^2+sigma__v^2)*sigma__d)

 

sigma__d/(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2)

 

(1/2)*(gamma*sigma__e^2*sigma__d-(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2))/(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2)

(6)

Z_val := simplify(eval(Z, [lambda = l, beta = b, alpha = a]));

-(1/4)*sigma__d*sigma__v^2*(((-2*gamma^2*sigma__d^4*sigma__e^4-16)*sigma__v^6+(-6*gamma^2*sigma__d^4*sigma__e^6-4*gamma^2*sigma__d^2*sigma__e^4-48*sigma__e^2)*sigma__v^4-sigma__e^4*(gamma^4*sigma__d^6*sigma__e^6+4*gamma^2*sigma__d^4*sigma__e^4+8*gamma^2*sigma__d^2*sigma__e^2+48)*sigma__v^2-4*gamma^2*sigma__d^2*sigma__e^8-16*sigma__e^6)*(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^(1/2)+(2*sigma__d^2*sigma__v^8+(12*sigma__d^2*sigma__e^2+8)*sigma__v^6+2*(12+gamma^2*sigma__d^4*sigma__e^4+sigma__d^2*(gamma^2+13)*sigma__e^2)*sigma__e^2*sigma__v^4+8*(3+gamma^2*sigma__d^4*sigma__e^4+(1/2)*sigma__d^2*(gamma^2+6)*sigma__e^2)*sigma__e^4*sigma__v^2+sigma__e^6*(gamma^2*sigma__d^2*sigma__e^2+4)*(gamma^2*sigma__d^4*sigma__e^4+2*sigma__d^2*sigma__e^2+2))*sigma__d*sigma__v^2*gamma)/((sigma__e^2+sigma__v^2)^2*(gamma^2*sigma__d^2*sigma__e^4+4*sigma__e^2+4*sigma__v^2)^2)

(7)

eval(Z_val, gamma = Gamma/sigma__e/sigma__d);

-(1/4)*sigma__d*sigma__v^2*(((-2*Gamma^2*sigma__d^2*sigma__e^2-16)*sigma__v^6+(-6*Gamma^2*sigma__d^2*sigma__e^4-4*Gamma^2*sigma__e^2-48*sigma__e^2)*sigma__v^4-sigma__e^4*(Gamma^4*sigma__d^2*sigma__e^2+4*Gamma^2*sigma__d^2*sigma__e^2+8*Gamma^2+48)*sigma__v^2-4*Gamma^2*sigma__e^6-16*sigma__e^6)*(Gamma^2*sigma__e^2+4*sigma__e^2+4*sigma__v^2)^(1/2)+(2*sigma__d^2*sigma__v^8+(12*sigma__d^2*sigma__e^2+8)*sigma__v^6+2*(12+Gamma^2*sigma__e^2*sigma__d^2+sigma__d^2*(Gamma^2/(sigma__e^2*sigma__d^2)+13)*sigma__e^2)*sigma__e^2*sigma__v^4+8*(3+Gamma^2*sigma__e^2*sigma__d^2+(1/2)*sigma__d^2*(Gamma^2/(sigma__e^2*sigma__d^2)+6)*sigma__e^2)*sigma__e^4*sigma__v^2+sigma__e^6*(Gamma^2+4)*(Gamma^2*sigma__d^2*sigma__e^2+2*sigma__d^2*sigma__e^2+2))*sigma__v^2*Gamma/sigma__e)/((sigma__e^2+sigma__v^2)^2*(Gamma^2*sigma__e^2+4*sigma__e^2+4*sigma__v^2)^2)

(8)

Download expression_to_simplify.mw

1 2 3 4 5 6 Page 1 of 6