acer

32385 Reputation

29 Badges

19 years, 340 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Try,

  getenv("MAPLE");

instead of your attempt,

  getenv("$MAPLE"); 

Or see the examples on the ?getenv Help page, which do not include the dollar symbol.

 

Here is a way, for Maple 2015.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

L := 1:

AAA := 3.888022*10^(-42)*p*q-4.75389*10^(-42)*y*p*q+7.4699*10^(-43)*y*p*q^2+9.1169*10^(-43)*y*p^2*q:

map(int,(int(q*AAA/sqrt(p^2+q^2+1),p=0..L)),q=0..L);

-0.1867377355e-42*y+0.453450449e-42+int(-0.4558450000e-42*q^4*y*ln(1.+(q^2+2.)^(1/2)), q = 0 .. 1)+int(-0.4558450000e-42*y*ln(1.+(q^2+2.)^(1/2))*q^2, q = 0 .. 1)

factor(expand(%));

-0.4211444464e-42*y+0.453450449e-42

#
# The following suggestion doesn't work in Maple 2015, since
# IntegrationTools:-Expand incorrectly pulls q out of both integrals.
#

restart;

L := 1:

AAA := 3.888022*10^(-42)*p*q-4.75389*10^(-42)*y*p*q+7.4699*10^(-43)*y*p*q^2+9.1169*10^(-43)*y*p^2*q:

Int(q*AAA/sqrt(p^2 + q^2 + 1), [p = 0 .. L, q = 0 .. L]):

evalf(IntegrationTools:-Expand(%));

0.1464659791e-41*q^2-0.1568649000e-41*q^2*y+0.2813991838e-42*q^3*y

 

Download question_integration_ac.mw

After some investigation, it seems that the problem is due to the plotting substructure COLOR(NONE) that is in the encoded output for the odeplot call(s) in your worksheet saved in Maple 7.

In Maple 2015.2 and earlier that errant substructure seems to get ignored when the worksheet is reopened, but in Maple 2016 and later it causes the GUI's layout remndering to appear corrupted.

In Maple 16 through to Maple 2015, the errant substructure does not get stored in the encoded output in the re-saved XML .mw file.

I will submit a bug report, noting that:
  - Encountering a problematic PLOT substructure shouldn't ruin the whole sheet's rendering. At worst the plot's output could be ignored and discarded upon the problematic reopening.
  - Since Maple 7 allowed this to be created, and since versions up to Maple 2015 accomodated it fine, then later releases should also accomodate it upon re-opening  (and discard it).

I could write a script to that could fix up the problematic .mw file, and then open in a new GUI tab. But not until next week. The problem might even be isolated to the output returned by the odeplot command in the much older versions (I cannot check right now). It isn't a common issue.

Alternatively, in a single statement,

restart;
expr := Sum((-1)^n - 1, n = 1 .. infinity):

simplify(subs(n=nn,op(1,expr))) assuming nn::even;

                     0

I mention the above because it might help in a similar situation where the wrapping command is not simplify and doesn't provide for its own assume option.

I should probably also mention this mechanism.

restart;
Physics:-Setup(assumingusesAssume = true):

expr := Sum((-1)^n - 1, n = 1 .. infinity):

simplify(op(1,expr)) assuming n::even;
                     0

More tricky, ie. harder IMO to get right more generally,

value(simplify('`%assuming`'([op(1,expr)],[n::even])));

                     0

value('`%assuming`'(['simplify'(op(1,expr))],[n::even]));

                     0

Your call removes entries whose value equals the value of A[1], which is 1. Both the entries A[1] and A[3] satisfy that criterion of having the same value as A[1], and consequently both are removed.

If you simply want to chop off only the first entry then it's more efficient to do it via indexing, eg.
  A:=Array([1,4,1,7]);
  A[2..-1];  # without reindexing from 1
  rtable_redim(A[2..-1],1..op([2,2],A)-1); # with reindexing from 1

(If you care about reindexing a great deal then it could be easier to use a Vector instead of an Array.)

But you haven't indicated clearly what your actual purpose is, so it's tricky to guess what might be best.

 

I am not sure what you are shooting for. Is it an expression that you could manipulate symbolically, or a fast procedure to evaluate at numeric values, or...?

You can use a symbol j (in lieu of 6) if you utilize binomial, and obtain various forms. I don't really see why hypergeom would serve much better than inert Sum, primarily because you didn't tell us anything about how you plan to use your result. I don't really understand what kind of formula or general expression you might be hoping for.

Or you could use a procedure taking j (or j and w) as arguments.

restart;

Sg:=(n,w)->1-(1-w)^n*add(binomial(n-1+i,n-1)*w^i,i=0..n-1):
Sg(6,3);

-4682367

Sg(6,w);
eval(%,w=3);

1-(1-w)^6*(252*w^5+126*w^4+56*w^3+21*w^2+6*w+1)

-4682367

S:=sum(w*binomial(j+i,i+1)*w^(j-1)*(1-w)^(i+1),i=-1..j-2);

1-w*binomial(2*j-1, j)*w^(j-1)*(1-w)^j*hypergeom([1, 2*j], [j+1], 1-w)

S6:=convert(eval(S,j=6),elementary);

1-(1-w)^6*(252*w^5+126*w^4+56*w^3+21*w^2+6*w+1)

eval(S6,w=3);

-4682367

add(w*binomial(6+i,i+1)*w^(6-1)*(1-w)^(i+1),i=-1..6-2);

w^6+6*w^6*(1-w)+21*w^6*(1-w)^2+56*w^6*(1-w)^3+126*w^6*(1-w)^4+252*w^6*(1-w)^5

eval(%,w=3);

-4682367

add(eval(w*binomial(6+i,i+1)*w^(6-1)*(1-w)^(i+1),w=3),i=-1..6-2);

-4682367

A:=simplify(1-(1-w)^j*sum(binomial(j-1+i,j-1)*w^i,i=0..j-1));
convert(eval(A,[j=6,w=3]),elementary);
convert(eval(A,[j=6]),elementary);
eval(%,w=3);

binomial(2*j-1, j-1)*w^j*hypergeom([1, 2*j], [j+1], w)*(1-w)^j

-4682367

-w^6*(252*w^5-1386*w^4+3080*w^3-3465*w^2+1980*w-462)*(1-w)^6/(-1+w)^6

-4682367

 

Download addbinomial.mw

[edit] The OP has not said much about how this is to be used. There is at least one other interesting case -- where an expression denoting the case that j is unspecified has to be passed around, but which is supposed to compute to a numeric result when the parameter is subsequently substituted by a number. Using uneval-quotes around a function call can be tricky and fragile, and passing around such a beast can be irksome.

So another possible useful case is the procedure which returns unevaluated unless some arguments are numeric. For example, below the calls Sg(j,w) or Sj(j,3) can be passed around without worry of prematurely invoking add with wrong arguments -- until such time as j gets a numeric value. Modify as needed.

restart;

Sg:=proc(n,w)
      if not n::numeric then return 'procname'(args); end if;
      1-(1-w)^n*add(binomial(n-1+i,n-1)*w^i,i=0..n-1);
end proc:

Sg(6,3);

-4682367

Sg(j,3); # no error emitted
eval(%,[j=6]);

Sg(j, 3)

-4682367

# And, now, for example...
#plot([Sg(2,w),Sg(3,w)], w=0..1);

 

Download addbinomial2.mw

As I'm sure you're aware, there are several ways to manually store a Matrix between sessions, by issuing a command. Eg. storing to .mla, text file, or workbook.

But you seem to be asking about the Matrix being automatically and dynamically stored/saved so that its saved version matches its running values -- with no command needed prior to closing/restart apart from normal closing of the Worksheet/Document.

The answer is that this is one of the purposes why the DataTable was invented. It provides this functionality that otherwise did not conveniently and robustly exist.

(The "State" embedded-component provides a similar mechanism, but it is really just a kind of hidden DataTable -- and is designed more for programmatically constructed embedded-component assemblies.)

As I showed you in your earlier question, you can utilize eval(...,1) to useful effect. In particular, you can compare it against the result from a full eval call.

restart;

ode1 := :-parse("diff(y(x),x$2)=0"):

lprint(eval(ode1,1));

diff(y(x),x $ 2) = 0

evalb(eval(ode1)=eval(ode1,1));

false

f := proc()
  local ode1;
  ode1 := :-parse("diff(y(x),x$2)=0");
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

false

ode1 := eval(:-parse("diff(y(x),x$2)=0")):

lprint(eval(ode1,1));

diff(diff(y(x),x),x) = 0

evalb(eval(ode1)=eval(ode1,1));

true

f := proc()
  local ode1;
  ode1 := eval(:-parse("diff(y(x),x$2)=0"));
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

true

restart;

ode1 := 'sin(2.1)':

lprint(eval(ode1,1));

sin(2.1)

evalb(eval(ode1)=eval(ode1,1));

false

f := proc()
  local ode1;
  ode1 := 'sin(2.1)';
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

false

ode1 := sin(2.1):

lprint(eval(ode1,1));

.8632093666

evalb(eval(ode1)=eval(ode1,1));

true

f := proc()
  local ode1;
  ode1 := eval(sin(2.1));
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

true

 

Download eval_1.mw

If you call the parse command with no options then it does not evaluate its result. And inside your procedure the local ode gets only 1-level evaluation.

You can wrap parse with a call to eval, or you can supply the option statement.

restart;
foo:=proc()
  local ode,func;  
  local x,y; #adding this did not  help

  ode  :=  :-parse("diff(y(x),x$2)=0", statement);
  func :=  :-parse("y(x)");

  try
     dsolve(ode), DEtools:-odeadvisor(ode,func);
  catch:
     error lastexception;
  end try;

end proc:

foo();

y(x) = _C1*x+_C2, [[_2nd_order, _quadrature]]

restart;
foo:=proc()
  local ode,func;  
  local x,y; #adding this did not  help

  ode  :=  eval(:-parse("diff(y(x),x$2)=0"));
  func :=  :-parse("y(x)");

  try
     dsolve(ode), DEtools:-odeadvisor(ode,func);
  catch:
     error lastexception;
  end try;

end proc:

foo();

y(x) = _C1*x+_C2, [[_2nd_order, _quadrature]]

 

Download parse_example.mw

If that is assigned to the name M then try accessing the entry by indexing, eg.   M[1,1]

Upload and attach your worksheet, if you want to help us to help you.

I got this:

restart;
Digits:=16:
P:=...your long expression... :
newP:=eval(P,[k=0.1,beta=0.2]):
plot(newP,lambda=0.4..0.85);

fsolve(newP,lambda=0.4..0.85,maxsols=4);

   0.4632186949799427, 0.5169368305419582, 0.7781636733300423, 0.8094962147692479

help_rf_ac.mw

Are you saying the your fsolve call already works, and produces results like, say, this:

   SOL1 := fsolve({ODE11, ODE12}, {N, t__2});
                 SOL1 := {N=3, t__2=5.6666}

In that case you can do the following to access the values:

   eval(N, SOL1);
                               3
   eval(t__2,SOL1);
                          5.6666

And you can use those wherever you need the values, or you can assign each to temporary variables, etc.

If your situation is different then please explain in more detail what you need.

restart;

x:=proc(j)

option remember;

x(j-1) + 1;

end proc:

 

x(1):=2;

2

x(2), x(3), x(4);

3, 4, 5

x(2):=7;

7

forget(x, 3); forget(x, 4);

x(3), x(4);

8, 9

x(2):=13

13

map[2](forget, x, [3,4]):

x(3), x(4);

14, 15

x(2):=10

10

forget~(x, [3,4]):

x(3), x(4);

11, 12

 

Download EXAMPLES_ac.mw

If I understand you, here is one way to contruct it. (I expect that there are slicker ways.)

restart;

F:=(N::posint)->ArrayTools:-FlipDimension(Matrix(N,N,
  [seq([seq(j+i*(i-1)/2,
    j=`if`(i::odd,1..i,i..1),(-1)^(i+1))],i=1..N),
   seq([seq(N^2+1-(j+i*(i-1)/2),
    j=`if`(i::even,1..i,i..1),(-1)^(i))],i=N-1..1,-1)],
  scan=band[N-1,N-1]),1):

F(2);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

F(3);

Matrix(3, 3, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 6, (2, 1) = 3, (2, 2) = 5, (2, 3) = 7, (3, 1) = 4, (3, 2) = 8, (3, 3) = 9})

F(4);

Matrix(4, 4, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 6, (1, 4) = 7, (2, 1) = 3, (2, 2) = 5, (2, 3) = 8, (2, 4) = 13, (3, 1) = 4, (3, 2) = 9, (3, 3) = 12, (3, 4) = 14, (4, 1) = 10, (4, 2) = 11, (4, 3) = 15, (4, 4) = 16})

F(5);

Matrix(5, 5, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 6, (1, 4) = 7, (1, 5) = 15, (2, 1) = 3, (2, 2) = 5, (2, 3) = 8, (2, 4) = 14, (2, 5) = 16, (3, 1) = 4, (3, 2) = 9, (3, 3) = 13, (3, 4) = 17, (3, 5) = 22, (4, 1) = 10, (4, 2) = 12, (4, 3) = 18, (4, 4) = 21, (4, 5) = 23, (5, 1) = 11, (5, 2) = 19, (5, 3) = 20, (5, 4) = 24, (5, 5) = 25})

F(6);

Matrix(6, 6, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 6, (1, 4) = 7, (1, 5) = 15, (1, 6) = 16, (2, 1) = 3, (2, 2) = 5, (2, 3) = 8, (2, 4) = 14, (2, 5) = 17, (2, 6) = 26, (3, 1) = 4, (3, 2) = 9, (3, 3) = 13, (3, 4) = 18, (3, 5) = 25, (3, 6) = 27, (4, 1) = 10, (4, 2) = 12, (4, 3) = 19, (4, 4) = 24, (4, 5) = 28, (4, 6) = 33, (5, 1) = 11, (5, 2) = 20, (5, 3) = 23, (5, 4) = 29, (5, 5) = 32, (5, 6) = 34, (6, 1) = 21, (6, 2) = 22, (6, 3) = 30, (6, 4) = 31, (6, 5) = 35, (6, 6) = 36})

 

Download mattrav.mw

Here is one way to treat your example symbolically (exactly).

restart;

obj:=(x-2*y)/(5*x^2-2*x*y+2*y^2);

(x-2*y)/(5*x^2-2*x*y+2*y^2)

cond:=isolate(2*x^2-y^2+x*y=1,x);

x = -(1/4)*y-(1/4)*(9*y^2+8)^(1/2)

sol:=simplify([maximize(eval(obj,cond),location)]);

[(1/4)*2^(1/2), {[{y = -(1/6)*2^(1/2)*(3+3^(1/2))}, (1/4)*2^(1/2)]}]

pt:=[simplify(eval(cond,sol[2,1,1])), sol[2,1,1,1]];

[x = -(1/3)*6^(1/2), y = -(1/6)*2^(1/2)*(3+3^(1/2))]

simplify(eval(obj,pt));

(1/4)*2^(1/2)

 

Download maximize_exact.mw

First 115 116 117 118 119 120 121 Last Page 117 of 336