## 28100 Reputation

17 years, 244 days

## is...

You could make the following kinds of checks, using the is command.

 > restart;
 > is( -7.5 in RealRange(Open(-10),-5) )

 > is( -7.5 in RealRange(Open(-6),infinity) )

 > is( -7.5 in Or(RealRange(Open(-6),infinity),                RealRange(Open(-10),-5)) );

 > is( A in Or(RealRange(Open(-6),infinity),                RealRange(Open(-10),-5)) )   assuming A>-9;

 > is( A in Or(RealRange(Open(-6),infinity),                RealRange(Open(-10),-5)) )   assuming A>-11;

 > coulditbe( A in Or(RealRange(Open(-6),infinity),                RealRange(Open(-10),-5)) )   assuming A>-11;

 > coulditbe( A in Or(RealRange(Open(-6),infinity),                RealRange(Open(-10),-5)) )   assuming A<-11;

You could also assign your disjunction (or other logical operator construction) to a name, and re-use it. Eg,

 > Dis := Or(RealRange(Open(-6),infinity),           RealRange(Open(-10),-5)):

 > is( -7 in Dis );

 > is( A in Dis ) assuming A<-11;

 > is( A::Dis ) assuming A>-9;

It is unfortunate that Maple 2023.0 does not have cross-reference links from the Help page for topic RealRange to the Help pages with topics assume (is) and property.

## syntax errors versus runtime errors...

Let's suppose that you have a worksheet with some Startup Code.

The "Maple Code Editor Diagnostics" panel shows syntax errors and some basic kinds of potential issues that might arise when the code is executed. A syntax error is different from an error raised when the code is executed.

If the code is executed using the Startup Code region's menu then runtime errors get reported to the "Maple Code Editor Console".

Those distinctions are why these appear in two separate bullet points in the Startup Code documentation; they relate to two different kinds of messages.

 • The Diagnostics panel at the bottom of the Startup Code Editor window displays the output from code analysis done on any Maple code entered into the code editor.
 • The Console panel displays output from the code entered in the Startup Code Editor. The Console can be used for prototyping and testing your code. To clear the Console, from the View menu, select Clear Console.

A simple (single, say) pass through the code may allow the code analyzer (here, mint, underneath) to deduce a few common and simple kinds of potential runtime problems -- procedure locals used before being initialized, unattainable code blocks, locals assigned values but then not used, etc. These kinds of issue are reported to the Diagnostics panel.

But these diagnostics don't execute the code in full. And hence they will certainly not find all kinds of future runtime error, since doing so without actual execution is logically impossible. Runtime error message get reported to the Console panel, if executed by the Startup Code's menu.

Code can be run under the debugger. Doing so can require learning its techniques.

## something...

I would prefer to pass {x} rather than unadorned x as the second argument to solve, for consistency of output, and then fix up the conversions to RealRange.

I don't know whether you'd prefer sets or Or to be used to denote logical disjunction. Having it be denoted by mere sequences seems dodgy to me, because more involved multiple solutions could become wrongly conflated. (I don't much like T1 below returning a mere sequence...)

I also don't know whether you'd want to handle univariate examples with names other than x. It's hardcoded in T3 at present. (Also, you can't sensibly have nameless RealRanges for multivariate examples, naturally.)

I also don't know what other, future, less trivial examples you'd want to handle.

 > restart;
 > #interface(prettyprint=0):

 > with(RealDomain):

 > RealRange(-infinity,infinity):='RealRange(-infinity,infinity)':

 > T1 := ()->subsindets([args],`<>`,u->(lhs(u)rhs(u)))[]:
 > T2 := ()->subsindets([args],And(name=name,':-satisfies'(evalb)),                     RealRange(-infinity,infinity))[]:
 > T3 := ()->subsindets([args],`::`(identical(x),anything),rhs)[]:
 > A := ()->T3(convert(T2(T1([args])), RealRange)[]):

 > A( solve(x-1 > 0, {x}) );

{RealRange(Open(1),infinity)}

 > A( solve(1/x^2 > 0, {x}) );

{RealRange(-infinity,Open(0)), RealRange(Open(0),infinity)}

 > A( solve(1/(x^2-1) > 0, {x}) );

{RealRange(-infinity,Open(-1))}, {RealRange(Open(1),infinity)}

 > A( solve(x^2+1 > 0, {x}) );

{RealRange(-infinity,infinity)}

 > A( solve(x^2+1 < 0, {x}) ); # NULL
 >

## solve, fsolve...

You are trying to use an exact solving methodology on an expression containing float exponents. (That can make solving fully over the complex numbers be quite a demand.)

Using fsolve is more suitable here.

```fsolve(.2894606222 = .4090662520/((1+0.1481289280e-2*x)^5.034901366
*(1/(1+0.1481289280e-2*x)^5.034901366)^.1986136226),
x);

60.41863487
```

Also note that converting to rationals (even "exactly") and forcing it through solve doesn't really help much to getting an accurate floating-point  result here.

 > expr := .2894606222 = .4090662520/((1+0.1481289280e-2*x)^5.034901366                                   *(1/(1+0.1481289280e-2*x)^5.034901366)^.1986136226):

 > eval(solve(subsindets(expr,float,__K),            {x}),      __K=(x->x));

 > evalf(%); evalf[10](evalf[50](%%));

 > eval(solve(subsindets(expr,float,                       u->__K(convert(u,rational,exact))),            {x}),      __K=(x->x));

 > evalf(%); evalf[10](evalf[50](%%));

 > fsolve(expr);

 > evalf[10](evalf[50](fsolve(expr)));

## example...

Here is a brief way to do that.

L := [seq(cos(x), x=0.1 .. 10.0, 0.1)];
S := sort(L);
S[35];

which produces -0.5885011173 as its last result.

Here's a slightly longer way, that shows a bit more. (figured that you're trying to learn some Maple. You could try and work out for yourself what these commands do...)

 > L := [seq([x,cos(x)], x=0.1 .. 10.0, 0.1)]:
 > Here is the list of 100 entries, cos(0.1) to cos(10.0) L[..,2];

 > S := sort( L, key=(u->op(2,u)) ):
 > Here is the sorted list. S[..,2];

 > S[35];

 > The 35th term of the sorted list is , which comes from cos(2.2) cos(2.2);

 > plots:-display(   plots:-listplot(S[..,2], size=[500,200]),   plots:-pointplot([[35,S[35][2]]],color=red,                    symbol=solidcircle,symbolsize=15),   axis[1]=[tickmarks=[seq(10..100,10)],            gridlines=[[seq(5..100,10)]]]);

You may have noticed that lists L and S each contain both the x-values as well as the cos(x) values. I only did it that way because I thought that it'd be fun/interesting to be able to immediately get the corresponding x-value which produced the 35th greatest cos-value, without doing any additional computation.

## {eq1, eq2, eq3, eq4} union ics...

You've already assigned ics itself as a set., ie.
ics := {V(0) = -65, h(0) = 0.6, m(0) = 0.05, n(0) = 0.32}

Having done that, you could pass either,
{eq1, eq2, eq3, eq4} union ics
or,
{eq1, eq2, eq3, eq4, op(ics)}
to dsolve.

That merges the differential equations and initial conditions together into a single (flat) set.

Or you could assign only the expression sequence of conditions to ics (and not itself a set), ie,
ics := V(0) = -65, h(0) = 0.6, m(0) = 0.05, n(0) = 0.32;
and then pass your original formulation to dsolve, ie.,
{eq1, eq2, eq3, eq4, ics}

Adjust the rest, as desired. I didn't look to see if your system and the results made sense.

 >
 >

 >

 >

 >
 >

 >

 >

 >

## :-diff...

Here's one way, collecting wrt the global :-diff.

The colon-minus prefix makes it refer to the global name diff rather than the Physics export going by the similar name.

 > restart;

Run the code with Physics loaded and it does not collect in diff but if you put a # infront of physics it works fine.

 > with(Physics):
 > CompactDisplay(varphi(X),psi(X))

 > X:=tau,x,y,z

 > expr := (6*alpha)*varphi(X)*A^4*1/a(tau)^2 + (-12*diff(Phi(X), tau) - 12*diff(psi(X), tau))*alpha*A^3*1/a(tau)^2 + (-4*diff(diff(Phi(X), x), x) - 4*diff(diff(Phi(X), y), y) - 4*diff(diff(Phi(X), z), z) - 4*diff(diff(psi(X), x), x) - 4*diff(diff(psi(X), y), y) - 4*diff(diff(psi(X), z), z))*alpha*A^2*1/a(tau)^2 + (-(6*varphi(X))*H(tau)^4 - (12*H(tau)^3)*diff(psi(X), tau) + (4*H(tau)^2)*diff(diff(psi(X), x), x) + (4*H(tau)^2)*diff(diff(psi(X), y), y) + (4*H(tau)^2)*diff(diff(psi(X), z), z))*alpha*1/a(tau)^2 - (6*H(tau))*diff(psi(X), tau) + 2*diff(diff(psi(X), x), x) + 2*diff(diff(psi(X), y), y) + 2*diff(diff(psi(X), z), z)

 > map(simplify, collect(expr, :-diff));

 > collect(expr, :-diff, simplify);

## subsindets, suffixed...

The following replaces all names of the form `x` followed by a positive integer.

It handles your set of names assigned to t, and it doesn't matter how many such names there are.

It also allows you to make such replacements within expressions more generally.

 > restart;
 > t:={seq(x||i,i=1..100)};

 > subsindets(t, 'suffixed(x,posint)',            nm->cat('y',String(nm)[2..]));

 > expr := x1*x2 + x5^2 + sin(x117);

 > subsindets(expr, 'suffixed(x,posint)',            nm->cat('y',String(nm)[2..]));

If you know that there are just that particular 100 such names then you could do it more tersely like, say,

subs('x||i=y||i'\$i=1..100,t);
or,
subs('x||i=y||i'\$i=1..100,expr);

Or, using it more than once,

S:='x||i=y||i'\$i=1..100:
subs(S,t);
subs(S,expr);

## equation versus assignment...

Don't make the assignment to C if you want it to remain as an unassigned name.

It looks as if you wanted to use only an equation involving C, not an assignment.

 > restart;
 > rho := `ρg`*ng + `ρp`*np + `ρw`*nw;

 > B := np/Kp + nw/Kw + ng/Kg;

 > eqn := C = (B/rho)^(1/2);

 > isolate( eqn, ng );

## temporary variables?...

You wrote of expressing them in terms of each other.

I'd be interested to know whether your wider investigations might have any use for expressing them all ("compactly") in terms of additional temporary variables.

For example,

 >
 >
 >
 >

 >
 >
 >
 >
 >
 >
 >

I made those additional temporary substitutions as assignments. But they could also be formulated as a sequence of equations (for substitution into each other, up the chain).

You could optionally (telescopically) collapse a portion of that sequence of subsitutions, from the top down.  Eg, you could retain only the knowledge in a5 & a6, or what have you.

Also, such a scheme can also support a wider set of operations (expression forms) than just mere polynomials. For polynomials there are various techniques (basis, triangularization, etc) to produce such a substituion chain. But there are also mechanisms for doing it for a wider (non-polynomial) class.

## those five...

The five you cited can be found pretty quickly, and exactly, as follows.

```restart;

nsd := 16*a*b*c*(9 + a^2 + b^2 + c^2)*(b*c + a*(b + c) + 3*(a + b + c))
- (3 + a + b + c)^2*(a*b + 3*c)*(3*b + a*c)*(3*a + b*c):

nsdac := eval(nsd,{c=a}):
rawac := solve({nsdac,a>0,b>0},[a,b]):
solac := map(s->{s[],c=eval(a,s)},rawac);

solac := [{a = 1, b = 1, c = 1}, {a = 3, b = 3, c = 3},
{a = 3, b = 9, c = 3}]

eval~(nsd, solac);

[0, 0, 0]
```

The remaining pair can be had immediately by noticing/proving the symmetry, or by re-running with each of the corresponding substitutions c=b and b=a.

Proving that there are no other solutions seems difficult or time-consuming. Let's see...

## draw...

You mistakenly placed the call to polygonplot inside the call to draw.

 > restart;
 > with(geometry):
 > with(plots):
 > _EnvHorizontalName = 'x':  _EnvVerticalName = 'y':
 > point(A, -1, 9): point(B, -5, 0): point(C, 6, 0): triangle(ABC,[A,B,C]): midpoint(M1,A,C): midpoint(M2,B,C):midpoint(M3,A,B): rotation(J, C, Pi/2, 'counterclockwise', M1):triangle(AJC,[A,J,C]): rotation(Ii, C, Pi/2, 'counterclockwise', M2):triangle(BIC,[B,Ii,C]): rotation(K, A, Pi/2, 'counterclockwise', M3):triangle(AKB,[A,K,B]): midpoint(O1,K,J): coordinates(O1): midpoint(O2,A,Ii): coordinates(O2):   poly:=[coordinates(A),coordinates(J),coordinates(Ii),coordinates(K)]:
 > display(   draw([A(color = black, symbol = solidcircle, symbolsize = 12),         B(color = black, symbol = solidcircle, symbolsize = 12),         C(color = black, symbol = solidcircle, symbolsize = 12),         J(color = black, symbol = solidcircle, symbolsize = 12),         ABC(color = red ),         BIC(color = green),         AKB(color = grey),         AJC(color =blue)]),   polygonplot(poly,color = "DarkGreen", transparency = 0.5),   textplot([[coordinates(A)[], "A"],[coordinates(J)[], "J"],[coordinates(Ii)[], "I"],      [coordinates(B)[], "B"], [coordinates(K)[], "K"],   [coordinates(C)[], "C"]],   align = [above, right]),  axes = none);

 >

## something like this?...

Are you trying to get an effect something like one of these?

 > restart:
 > temp1 := (coeff(aa,dudy^2))*dudy^2 + (coeff(aa,dudy^2))*dvdx^2:
 > eq := dudy^2+dvdx^2=PP: reveq := (rhs=lhs)(eq):

 > subs(reveq,collect(algsubs(eq,temp1),PP,simplify));

 > subs(reveq,collect(algsubs(eq,temp1),PP,u->simplify(u,size)));

 > temp2 := subs({gamma[1] = alpha[3]-alpha[2],          gamma[2] = alpha[6]-alpha[5]}, temp1):

 > subs(reveq,collect(algsubs(eq,temp2),[PP],u->simplify(u,size)));

 > subs(reveq,collect(algsubs(eq,temp2),PP,simplify));

If you actually wanted to "collect" that term within a modification of the original expression assigned to aa, then you could follow that up with either of,

subs(reveq,collect(algsubs(eq,expand(aa)),PP,simplify));

or,

subs(reveq,collect(algsubs(eq,temp1),PP,simplify))
+ simplify(aa-temp1);

## usage...

This can be done in your Maple 18 simply by,

convert([sol],rational)[]

You have an expression sequence assigned to sol, not a list or a set. By wrapping it in square backets you get [sol] as a list. This allows you to pass them all together, without any being misinterpreted as options to the command.

By prepending [] to the call you can turn the result from a list back into a mere expression sequence (if you so want...).

problem1_ac.mw

## See the Help page...

This issue is covered quite clearly on the Help page for topic if, in the section Nested Selection Statements. See also the Help page for topic printlevel.

I'll mention that the inner conditional code does indeed get executed. The effects you're seeing only relate to the display of the inner results.

These effects also cover such nesting involving do-loops.

A good place to start looking for details, when you have an issue with a particular command, would be the Help page for that command.

 1 2 3 4 5 6 7 Last Page 2 of 292
﻿