acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The reason that you see "so many" solutions is that by default for your example solve computes both real and complex solutions.

If you only want purely real solutions of your system of polynomial equations then pass the additional option real to the solve command.

restart;

f1:=x^2+y^2=1:

f2:=y=x^3:

solve({f1,f2},{x,y},real,explicit);

{x = -(1/6)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(1/2), y = -(1/216)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(3/2)}, {x = (1/6)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(1/2), y = (1/216)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(3/2)}

 

Download solvepolysysreal.mw

 

It is simply -> which are the keystrokes minus - , and greater-than > .

You can have a blank space before or after them, but no space between them.

As for the manual, see this section of the Programming Guide.

The following was all done in a terminal session (Command Line Interface, or CLI).

( x->sin(x)+x )( 5 );                                                                        

                     sin(5) + 5

( x -> sin(x)+x )( 5 );                                                                      

                     sin(5) + 5


map( x->sin(x)+x, [2,3,7] );                                                                 

          [sin(2) + 2, sin(3) + 3, sin(7) + 7]

f := x->sin(x)+x;                                                                            

                 f := x -> sin(x) + x

f(t);                                                                                        

                     sin(t) + t

expr := cos(x)^2;                                                                            

                                  2
                    expr := cos(x)

g := unapply( expr, x );                                                                     

                                  2
                  g := x -> cos(x)

g(t);                                                                                        

                         2
                   cos(t)

x -> tan(x)^2;                                                                               

                          2
               x -> tan(x)

proc(x) option operator, arrow; tan(x)^2; end proc;

                          2
               x -> tan(x)

Why do you expect the conjugate on r^(1/4) to resolve just because r is assumed real? You seem to be overlooking the possibility that r could be negative.

restart;

Psi00 := exp(-(1/2)*r^2)/sqrt(Pi):

ig := conjugate(Psi00*r^(1/4))*Psi00*r^(1/4)*r assuming r>0;

(exp(-(1/2)*r^2))^2*r^(3/2)/Pi

int(int(ig, r = 0 .. infinity), phi = 0 .. 2*Pi);

(1/4)*Pi*2^(1/2)/GAMMA(3/4)

restart;

assume(r>0);

Psi00 := exp(-(1/2)*r^2)/sqrt(Pi):

ig := conjugate(Psi00*r^(1/4))*Psi00*r^(1/4)*r;

(exp(-(1/2)*r^2))^2*r^(3/2)/Pi

int(int(ig, r = 0 .. infinity), phi = 0 .. 2*Pi);

(1/4)*Pi*2^(1/2)/GAMMA(3/4)

 

Download conj.mw

Let us know if you want to build these things programmatically and have any trouble with that (it should be pretty straightfroward). Or if you want additional aspects like color, or fonts/color/weight on 2D Math.

restart;

MyTitle:=Typesetting:-mrow(Typesetting:-mn("Identity function",
                                           fontfamily=Times,size=14,bold=true),
                           Typesetting:-mn("\n(illustration)",
                                           fontfamily=Times,size=12)):

plot(x, x=0..1, title=MyTitle);

 

Download plottitlefont.mw

While the ShowSolutions command fails on this example (because of the presence of parameter s, I suspect), a step-by-step solution is still attainable.

restart;

with(Student:-Calculus1):

floatJ:=Int(.5*exp(-s*t)*exp(-4.5*t)*sin(2*Pi*t), t):

J:=convert(floatJ,rational);

Int((1/2)*exp(-s*t)*exp(-(9/2)*t)*sin(2*Pi*t), t)

(1)

j:=value(J):
simplify(j);

((-2*s-9)*sin(2*Pi*t)-4*Pi*cos(2*Pi*t))*exp(-s*t-(9/2)*t)/(16*Pi^2+4*s^2+36*s+81)

(2)

Rule[constantmultiple](J):
Rule[change, u = -(s+9/2)*t, u](%):
Rule[constantmultiple](%):
Rule[parts, exp(u), int(sin(4*Pi*u/(2*s+9)),u)](%):
Rule[constantmultiple](%):
Rule[parts, exp(u), int(cos(4*Pi*u/(2*s+9)),u)](%):
Rule[constantmultiple](%):
Rule[solve](%):
ans := Rule[revert](%);

CALCULUS1OBJECT([1, [], []], {s, t}) = -exp(-(1/2)*(2*s+9)*t)*(4*Pi*cos(2*Pi*t)+2*s*sin(2*Pi*t)+9*sin(2*Pi*t))/(16*Pi^2+4*s^2+36*s+81)

(3)

simplify(ans);

CALCULUS1OBJECT([1, [], []], {s, t}) = ((-2*s-9)*sin(2*Pi*t)-4*Pi*cos(2*Pi*t))*exp(-s*t-(9/2)*t)/(16*Pi^2+4*s^2+36*s+81)

(4)

 

Download stepbystepexample.mw

The case of a parsing error can be handled by doing the parse before calling dsolve. And you could put that in a try...catch and deal with it as you prefer.

When there is no previous parsing error, there's no hard set of rules that will always allow you to distinguish subsequently between cases like your 1.) and 2.), for arbitrary commands. It varies from command to command.

You can often make some distinctions of case 3) versus the other two, according to lastexception[1] which you have not utilized yet. It will often denote which named procedure emitted the error. So you could programmatically test -- or otherwise distinguish -- between the case that dsolve threw the error or some other procedure did. For example, simply printing it:

restart;

try
  ode := parse( "diff(y(x),x) +? y", ':-statement' );
catch:
  print("parsing error");
  print(StringTools:-FormatMessage( lastexception[2..-1]));
end try;

"parsing error"

"incorrect syntax in parse: character `?` unexpected (near 15th character of parsed string)"

ode := parse( "diff(y(x),x) + y", ':-statement' );

diff(y(x), x)+y

try
   dsolve(ode,y(x));
catch:
   # Or do something else if lastexception[1] is not `dsolve`
   print(cat(sprintf("%a: ",lastexception[1]),
         StringTools:-FormatMessage( lastexception[2..-1])));
end try;

 

"dsolve: y(x) and y cannot both appear in the given ODE."

 

Download lastexception1.mw

ps. Please don't delete your question once someone's responded and you've resolved your difficulty, as like last week on stackexchange.

The situation you're describing involves what's called a optional positional parameter.

You should use the quote-protected global name as the default value, to avoid problems such as when the global name is already assigned a value.

Eg,

restart;

sim := proc( x, n,
             o::identical(exactly,maximum,minimum) := ':-exactly' )
          return o;
       end proc:

sim();
                            exactly

exactly := 4:

sim();
                            exactly

That also helps avoid undesirable side-effects even if exactly were an unevaluated function call. (Such situations do occur.) Defensive programming is a good habit -- and I'll advocate it even if I don't always follow my own advice.

Your expectation is not valid.

Perhaps you meant to query   max(abs(Q))  ?

restart

A := Matrix(10, 10, {(1, 1) = 0.358665012985547e-3, (1, 2) = -0.164628637225196e-2, (1, 3) = 0.808705603350256e-3, (1, 4) = 0.131914692392149e-2, (1, 5) = -0.120745384995453e-2, (1, 6) = -0.127685186328850e-3, (1, 7) = -0.368262140727460e-3, (1, 8) = 0.722934152182773e-3, (1, 9) = 0.406838157326509e-3, (1, 10) = -0.270949354604275e-3, (2, 1) = -1.04811784877605, (2, 2) = -0.227246433636184e-2, (2, 3) = 1.12987295590946, (2, 4) = 0.320910227706809e-2, (2, 5) = -0.837137925723646e-1, (2, 6) = -0.590494756927829e-3, (2, 7) = 0.141893953127997e-2, (2, 8) = -0.431705701475750e-3, (2, 9) = 0.529611988652095e-3, (2, 10) = 0.876913927974057e-4, (3, 1) = -0.186537779517955e-2, (3, 2) = 0.731113455007046e-3, (3, 3) = -0.916700660778503e-2, (3, 4) = -0.429742144388156e-2, (3, 5) = 0.171402262358938e-1, (3, 6) = 0.147242552352914e-2, (3, 7) = -0.837021118160759e-2, (3, 8) = 0.348174114649671e-2, (3, 9) = 0.225687533471807e-2, (3, 10) = -0.139775301206369e-2, (4, 1) = -1.52107139964422, (4, 2) = 0.808077875491177e-2, (4, 3) = 1.64372029140351, (4, 4) = -0.847286100516818e-2, (4, 5) = -.127335986762229, (4, 6) = 0.118070315638635e-2, (4, 7) = 0.424032693235149e-2, (4, 8) = -0.111038208252920e-2, (4, 9) = 0.434602411991222e-3, (4, 10) = 0.318930385884084e-3, (5, 1) = 0.289424730370674e-2, (5, 2) = -0.172887794344293e-2, (5, 3) = 0.157061251396572e-1, (5, 4) = -0.363778806608431e-2, (5, 5) = -0.221497403961738e-1, (5, 6) = 0.205810013144210e-2, (5, 7) = 0.290388608347142e-2, (5, 8) = 0.554530769943721e-2, (5, 9) = 0.645600822073613e-3, (5, 10) = -0.223995662113480e-2, (6, 1) = 4.05367823691209, (6, 2) = -0.669541776787987e-2, (6, 3) = -4.37687402333541, (6, 4) = 0.100071882622313e-1, (6, 5) = .331612307231483, (6, 6) = -0.222866442868341e-2, (6, 7) = -0.854247230826875e-2, (6, 8) = -0.198825849939076e-2, (6, 9) = 0.144764377225621e-3, (6, 10) = 0.887581546748840e-3, (7, 1) = 0.437884803847533e-3, (7, 2) = -0.468560550990847e-2, (7, 3) = -0.274035269283456e-2, (7, 4) = 0.132221205985872e-2, (7, 5) = 0.587286710360397e-2, (7, 6) = 0.141670610986008e-2, (7, 7) = -0.324890905770655e-2, (7, 8) = 0.346314407352620e-2, (7, 9) = -0.313507643096885e-3, (7, 10) = -0.150449109852917e-2, (8, 1) = -1.74365543905306, (8, 2) = 0.329936253329467e-2, (8, 3) = 1.88180005384087, (8, 4) = -0.307966351872919e-2, (8, 5) = -.141724173079475, (8, 6) = 0.461487956516473e-3, (8, 7) = 0.455622531837965e-2, (8, 8) = -0.147959204065083e-2, (8, 9) = -0.964311997155483e-3, (8, 10) = 0.776900663643289e-3, (9, 1) = -0.182153308681337e-2, (9, 2) = 0.731579627122705e-2, (9, 3) = -0.459671306590223e-2, (9, 4) = 0.528628529817773e-2, (9, 5) = 0.340926625224384e-3, (9, 6) = -0.480044705401815e-2, (9, 7) = 0.906564729308528e-2, (9, 8) = -0.131891681339107e-1, (9, 9) = -0.298963526401197e-2, (9, 10) = 0.539189475787896e-2, (10, 1) = .259153153490112, (10, 2) = -0.239896326933024e-2, (10, 3) = -.278509331317189, (10, 4) = -0.165332320182602e-2, (10, 5) = 0.211686310866469e-1, (10, 6) = 0.115660284907533e-2, (10, 7) = -0.165524436062079e-2, (10, 8) = 0.496708050164578e-2, (10, 9) = -0.161592001287913e-3, (10, 10) = -0.203232293033617e-2})

Q := A/max(abs(A))

max(Q)

.926158307610656317

(1)

max(1/max(A).A)

1.00000000011419887

(2)

max(1/max(abs(A)).abs(A))

1.00000000021082958

(3)

L := [4, -10]:

max(abs~(L));

10

(4)

1/max(abs~(L)) * L;
max(%); # so what!

[2/5, -1]

 

2/5

(5)

1/max(abs~(L)) * abs~(L);
max(%);

[2/5, 1]

 

1

(6)

1/max(L) * L;
max(%);

[1, -5/2]

 

1

(7)

``

Download suuual_ac.mw 

 

One way that the error message "bad index into Array" can occur is where Maple tries to access the Array using a non-numeric index.

A typical example would be where Maple tries to access, say, Y[i] where the name i does not yet have an integer value. Eg,

restart;
Y := Array(1..10, i->i):

Y[i];
Error, bad index into Array

The seq command has special evaluation rules, which prevents Y[i] from being evaluated until i gets actual values. So this works.

restart;
Y := Array(1..10, i->i):

seq(Y[i], i=1..10);
               1, 2, 3, 4, 5, 6, 7, 8, 9, 10

But the sum command does not have special evaluation rules. The following produces the same error as does the first example above,

restart;
Y := Array(1..10, i->i):

sum(Y[i], i=1..10);
Error, bad index into Array

What just happened was that Maple tried to evaluate the first argument passed to the sum call before i got any value, which is Maple's usual evaluation rules for procedure calls. But, for what you are trying to accomplish, the Array reference Y[i] was evaluated prematurely.

Here are two alternative ways to do summation involving Array elements:

1) Use the add command instead of the sum command, since the add command also has special evaluation rules.

restart;
Y := Array(1..10, i->i):
add(Y[i], i=1..10);
                           55

2) Delay the indexed Array reference using unevaluation quotes (single right-quotes).

restart;
Y := Array(1..10, i->i):
sum('Y[i]', i=1..10);
                           55

Now, I am guessing that this kind of premature evaluation of an indexed Array reference is your problem, mostly based on your use of the words, "summation index" and the particular error message you cited. If I've guess wrongly then please provide the full example.

I'll note that at least one other Answer seems to be indicating that you've accessed Array entries using invalid numeric values for the index. I suspect that is not your problem, however, mostly because the error message for that situation is different than your Question's title.

restart;
Y := Array(1..10, i->i):

seq(Y[i+1]-Y[i], i=1..10);
Error, Array index out of range

seq(Y[i+1]-Y[i], i=0..9);
Error, Array index out of range

On MS-Windows and Linux you can use the keyboard short-cuts Ctl-r to temporarily switch from text mode to 2D Input mode, and Ctl-t to switch back.

On Mac OS X I believe that it's similar, Cmd-r and Cmd-t .

See the help-pages for more.

In general the solve command does not return all solutions for transcendental equations, while also not returning a warning about solutions being lost. This has some mention on the help-page for topic solve,details .

What that page fails to say is that, when the number of solutions can be determined by Maple as being bound by additional, supplied inequalities, the use of the explicit option as well as the allsolutions option can (sometimes, if it can be worked out by Maple) get an explicit full answer or additional solutions.

Sorry, I only have access to back to Maple 16.02 today, and not Maple 15 which seems to be indicated on your Question.

restart;

H := sqrt(1-2*r*cos(theta)):

eqs := { 0=2*r*(H*(2-H)-3*sin(theta)^2),
         0=-3*sin(2*theta) }:

solve( {r>=0, op(eqs)}, [r,theta] ):
map(print, %):

[r = 0, theta = 0]

 

[r = 1/2, theta = 0]

 

[r = 3/2, theta = Pi]

(1)

sols := solve( {r>=0, op(eqs), theta>=0, theta<=2*Pi},
               [r,theta], explicit, allsolutions ):
map(print, %):

[r = 0, theta = 0]

 

[r = 0, theta = (1/2)*Pi]

 

[r = 0, theta = Pi]

 

[r = 0, theta = (3/2)*Pi]

 

[r = 0, theta = 2*Pi]

 

[r = 1/2, theta = 0]

 

[r = 1/2, theta = 2*Pi]

 

[r = 3/2, theta = Pi]

(2)

 

Download solvert.mw

If you are just trying to get the right-hand sides of the equations in L,

map(rhs, L);
                             {b, f}

If you are trying to use L as a lookup key for a and e,

L := {a = b, e = f};
                      L := {a = b, e = f}

eval({a, e}, L);
                             {b, f}

eval([a, e], L);
                             [b, f]

eval(a, L);
                               b

eval(e, L);
                               f

Perhaps you are looking for a syncronized side-by-side Array of animations.

With the Table borders toggled off (via right-click Table->Properties), and with scaling=constrained, you could get it like so:

animarray.mw

The correct syntax would be Eigenvectors(A) instead of Eigenvectors[A] as you had it. But that seems to take too long.

restart;

local gamma;

E := [q2, q2^2/q1+(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1), q2*q3/q1, q4*q2/q1, q5*q2/q1+q2*(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1)/q1, q6*q2/q1]:

F := [q3, q2*q3/q1, q3^2/q1+(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1), q4*q3/q1, q5*q3/q1+q3*(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1)/q1, q6*q3/q1]:

G := [q4, q4*q2/q1, q4*q3/q1, q4^2/q1+(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1), q5*q4/q1+q4*(gamma-1)*(q5-(1/2)*q2^2/q1-(1/2)*q3^2/q1-(1/2)*q4^2/q1)/q1, q6*q4/q1]:

Ebar := expand(E*xi_x+F*xi_y+G*xi_z):
U := [q1, q2, q3, q4, q5, q6]:

A := subs(q1 = rho, q2 = rho*u, q3 = rho*v, q4 = rho*w, q5 = rho*e, q6 = rho*nu, VectorCalculus:-Jacobian(Ebar, U)):

A := subs(e = P/((gamma-1)*rho)+(1/2)*u^2+(1/2)*v^2+(1/2)*w^2, A):

A := subs(P = rho*c^2/gamma, A):

A := simplify(A):

op(1,A);

6, 6

(1)

with(LinearAlgebra):

evalsA:=LinearAlgebra:-Eigenvalues(A);

Vector(6, {(1) = u*xi_x+v*xi_y+w*xi_z+sqrt(c^2*xi_x^2+c^2*xi_y^2+c^2*xi_z^2), (2) = u*xi_x+v*xi_y+w*xi_z-sqrt(c^2*xi_x^2+c^2*xi_y^2+c^2*xi_z^2), (3) = u*xi_x+v*xi_y+w*xi_z, (4) = u*xi_x+v*xi_y+w*xi_z, (5) = u*xi_x+v*xi_y+w*xi_z, (6) = u*xi_x+v*xi_y+w*xi_z})

(2)

DetK:=Determinant(CharacteristicMatrix(A,K)):

seq(simplify(eval(DetK,K=evalsA[ii])), ii=1..6);

0, 0, 0, 0, 0, 0

(3)

#N6gen:=LinearSolve(eval(CharacteristicMatrix(A,K),K=evalsA[6]), Vector(6));

#simplify(eval(CharacteristicMatrix(A,K),K=evalsA[6]) . N6gen);
#simplify( A.N6gen - evalsA[6]*N6gen );

for ii from 1 to 3 do
  evecsA[ii]:=simplify(NullSpace(eval(CharacteristicMatrix(A,K),K=evalsA[ii])));
end do:

for ii from 1 to 3 do
  seq( simplify( A . evecsA[ii][jj] - evalsA[ii] * evecsA[ii][jj] ), jj=1..nops(evecsA[ii]));
end do;

Vector(6, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0, (6) = 0})

 

Vector(6, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0, (6) = 0})

 

Vector[column](%id = 18446884146858440574), Vector[column](%id = 18446884146858442254), Vector[column](%id = 18446884146531192950), Vector[column](%id = 18446884146531194390)

(4)

 


Download eigs.mw

Since the answer you expected has just F on the left-hand side then it is understandable that people give you answers about isolating or solving for F.

But another way to interpret your question involves cancellation of common factors in the left- and right-hand sides. For your given example that just happens to provide the same result as isolating for F.

But it's not a silly question. The simplify command will not "cancel" such common factors.

I don't promise that the following will work for all kinds of equations. But here's your example as well as another slightly more complicated one.

restart;

fact := (expr::equation) -> frontend(gcd,[numer(lhs(expr)),numer(rhs(expr))])/
                            frontend(gcd,[denom(lhs(expr)),denom(rhs(expr))]):

eq1 := F*R=(1/2*M*R^2)*(a/R);

                                       M R a
                          eq1 := F R = -----
                                         2

eq1/fact(eq1);

                                    M a
                                F = ---
                                     2

eq2 := (F+G)*R/sqrt(W-1)=(1/2*M*R^2)*(a/(R*sqrt(W-1)));

                          (F + G) R       M R a
                   eq2 := ---------- = ------------
                                 1/2            1/2
                          (W - 1)      2 (W - 1)

eq2/fact(eq2);

                                      M a
                              F + G = ---
                                       2
First 173 174 175 176 177 178 179 Last Page 175 of 336