acer

23890 Reputation

29 Badges

16 years, 68 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The edges of the filled region appear rough unless an accompanying outline curve is also rendered. That's why style=polygonoutline (default) has a border.

You're objecting that the fill color doesn't match the outline's color.

You can get a matching color for both filled region and outline (border) by calling the command twice -- once without border and once with as just a line (curve, as outline border) with forced matching color.

with(plots,display): with(plottools,ellipse):

display(
  ellipse([0, 0], 2, 1, filled=true, color = red, style=polygon),
  ellipse([0, 0], 2, 1, filled=true, color = red, style=line),
  size=[1000,500],scaling=constrained,axes=none)

And if you'd like to compare the variants side-by-side,

with(plots,display): with(plottools,ellipse):

display(Array([

  # One the left, the outline is rendered smoothly.
  display(ellipse([0, 0], 2, 1, filled=true, color = red, style=polygon),
          ellipse([0, 0], 2, 1, filled=true, color = red, style=line)),

  # In the middle, the undesirable black outline.
  display(ellipse([0, 0], 2, 1, filled=true, color = red, style=polygonoutline)),

  # One the right, the lack of any outline makes the filled edges jagged.
  display(ellipse([0, 0], 2, 1, filled=true, color = red, style=polygon))

              ]),size=[400,200],scaling=constrained,axes=none);

You might also see my comment on another Answer, in which I show a similar effect of matching colors using a single call to the plot command with a corresponding parametric form.

The plot may not be necessary.

F__A0 := 20;
X__Af := 0.9;
r__A := -2.52*1^2*X*(1 - X);

eq := V = (R + 1)*F__A0*int(1/(-r__A), X = X__Af*R/(R + 1) .. X__Af)
      assuming 0<X, X<1, 0<R, R<1;

    eq := V = 20 (R + 1) (-0.3968253968 ln(R) + 0.3968253968 ln(R + 10.))

Optimization:-Minimize(V, {eq, 0 <= R, R <= 1})[2];

          [R = 0.429944982482764, V = 36.1887187298120]

Solvingforlimitsofintegrals_ac.mw

I'm not quite sure what you're after. Is it something like this?

restart:

 

alias(X = X(t)):

alias(phi=k*X(t)):

alias(Phi=Phi(X(t))):

 

kin := 1/2*M*Diff(X, t)^2 + 1/2*m*Diff(Phi, t)^2;

(1/2)*M*(Diff(X, t))^2+(1/2)*m*(Diff(Phi, t))^2

eval(kin, Phi=phi);

(1/2)*M*(Diff(X, t))^2+(1/2)*m*(Diff(phi, t))^2

value(%);

(1/2)*M*(diff(X, t))^2+(1/2)*m*k^2*(diff(X, t))^2

convert(%, D);

(1/2)*M*(D(X))(t)^2+(1/2)*m*k^2*(D(X))(t)^2

Download alias_diff_ex.mw

If your goal is simply to print the procedure in way that is formatted suitably as 1D plaintext Maple notation source code then you could try the new %P format descriptor of the printf command.

Eg,

interface(verboseproc=3):
printf("%P",eval(RonanRoutines:-SignedArea));

If you want that exported to a text file then you could use fprintf instead of printf.

Note that showstat does not show "\" line-continuation characters, which may have been part of your problem. But (as used above) printf will include them. That can allow the 1D parser to properly deal with such split lines.

ps. In general you should not try to paste plaintext Maple notation code in as 2D Input. (That doesn't seem to have been your original problem. But I suggest you note it anyway.)

There are several reasons why the array data structure is deprecated in favour of the (newer, as of Maple 6) Array data structure.

Similar reasons exist for preferring Vector over vector, and Matrix over matrix. So I'll just use the words array and Array below, for brevity.

The Array structure is implemented underneath as a kind of rtable, which allows for the data to be stored according to various hardware (or higher precision) real and complex numeric datatypes. That allows the data to be stored in a contiguous region of memory. That allows many computations to be done using compiled code, which can be more efficient (by accessing the memory by location reference) and significantly faster.

The Array also allows a wider set of indexing functions to be used.

The array structure is implemented as a kind of table, which means that it gets (suffers) from having last-name-evaluation rules. That can make programming more awkward; for example it can involve a need for the evalm command, which is not needed for an Array.

That last-name-evaluation allows for an array to be passed to a procedure and acted on in-place. Computations with an Array structure can also be done in-place, but it does not have last-name-evaluation.

Your given example can also be handled as follows. (But without the bigger picture it's unnecessarily difficult to guess whether this will help with your broader goal.)

convert(a*x+6*x^2-10, 'horner', x);

           -10 + (a + 6 x) x

or perhaps,

sort(convert(a*x+6*x^2-10, 'horner', x), x);

            (6 x + a) x - 10

Your followup comments on other Answers indicate that you have some more involved example (and goal) which you have not yet shown.

A common scenario is that someone concocts their own approach for a larger goal, then gets bogged down in implementing one problematic step of that, and then asks only about how to resolve that particular step. It's often more useful to provide the more complete motivating example.

It did actually substitute, in your first example. It just didn't happen to simplify (in the way you apparently expected).  That can be done in several ways. Eg,

algsubs(n2+n1=n+6,a+(n1-b)*k+a+(n2-b)*k);

    k (-n2 + n + 6 - b) + (n2 - b) k + 2 a

simplify(%);

           k (-2 b + n + 6) + 2 a

If you don't like how algsubs works then you could also use simplify (with side-relations) here. Eg,

simplify(a+(n1-b)*k+a+(n2-b)*k, {n2+n1=n+6});

           k (-2 b + n + 6) + 2 a

By the way, you also mentioned a particular rearrangement of the simplified form. That too can be attained in several straightforward ways. Eg.

ans1 := algsubs(n2+n1=n+6,a+(n1-b)*k+a+(n2-b)*k):

collect(ans1,[a,b],simplify);

        2 a - 2 k b + k (n + 6)

collect(simplify(ans1),[a,b]);

        2 a - 2 k b + k (n + 6)

ans2 := simplify(a+(n1-b)*k+a+(n2-b)*k, {n2+n1=n+6}):

collect(ans2,[a,b]);

        2 a - 2 k b + k (n + 6)

One way is to utilize the showstat command, but using :: instead of :- as separator of the name, eg.

   showstat((Student:-Calculus1:-Roots)::RootsNumeric);

You may need to introduce extra round-brackets there, to resolve ambiguity.

Another way is to set,

   kernelopts(opaquemodules=false):

and then use showstat or print or the debugger as usual.

If you do not know the names of the local members of the module then you may utilize op for inspection, eg.

   op(eval(Student:-Calculus1:-Roots));
   op(3,eval(Student:-Calculus1:-Roots));

 

Another possibility is to use a parameter for the ratio x/r.

That sidesteps having to deal with the case that the x-Slider might have a value greater than the r-Slider.

restart;

A := (x,r) -> 2*sqrt(-x^2 + r^2)*x:

Explore(plots:-display(plot(p -> sqrt(r^2 - p^2), -r..r, color=blue),
                       plottools:-rectangle([-X*r,0], [X*r,sqrt(-(X*r)^2 + r^2)],
                                            style=line, color=red, thickness=4),
                       title=typeset("r = %1\nx = %2, Area = %3\n(Optimal: x=%4, Area=%5)",
                                     r, X*r, A(X*r,r), r/sqrt(2.), r^2 ),
                       axis[1]=[tickmarks=[`if`(X*r>r*0.05 and r-X*r>0.05, X*r="x",
                                                ceil(r)=ceil(r)),
                                           seq(u=u,u=floor(-r)..ceil(r))]],
                       scaling=constrained),
        parameters=[[r = 0.0 .. 4.0, label="r"],
                    [X = 0.0 .. 1.0, label="x/r"]],
        initialvalues=[X=1/sqrt(2.), r=2.0]);

 

Download rect_semicricle_explored.mw

Here are a few ways, involving purely numeric rootfinding (since you asked about that specifically).

r1 := fsolve(x^(1/x)=1.2);

         r1 := 1.257734541

r2 := fsolve(x^(1/x)=1.2, x, avoid={x=r1});

         r2 := 14.76745838

[fsolve(x^(1/x)=1.2, x=0..20, maxsols=2)];

      [1.257734541, 14.76745838]

Student:-Calculus1:-Roots(x^(1/x)=1.2, x=0..20);

      [1.257734541, 14.76745838]

Here's one way to get Maple to cough them up exactly. Note that the _BXXX coming out of solve is a boolean-valued parameter, ie. it has the assumption of having a value of 0 or 1. So we can evaluate using either of those values.

T := solve(x^(1/x)=12/10, real, allsolutions);

-LambertW(-_B6, -ln(6/5))/ln(6/5)

b := indets(T,And(name,Non(constant)));

{_B6}

eval(T, b[1]=1);

-LambertW(-1, -ln(6/5))/ln(6/5)

evalf(%);

14.76745838

eval(T, b[1]=0);

-LambertW(-ln(6/5))/ln(6/5)

evalf(%);

1.257734541

Download rfex.mw

This can be tidied up, but I've deliberately kept some steps separate in order to give you a better idea of what's going on.

You didn't make it clear whether N was a multiple of n, so I'll show a way that chops to length N, and another that pads the Matrix.

restart;

with(StringTools):

raw := "How. doIt   urnate**xtintoaM?\"atrixofle{{12345ttersinth   emostconvenient";

"How. doIt   urnate**xtintoaM?"atrixofle{{12345ttersinth   emostconvenient"

str := Select(IsAlpha,raw);

"HowdoIturnatextintoaMatrixoflettersinthemostconvenient"

n := 7;

7

L := Explode(str);

["H", "o", "w", "d", "o", "I", "t", "u", "r", "n", "a", "t", "e", "x", "t", "i", "n", "t", "o", "a", "M", "a", "t", "r", "i", "x", "o", "f", "l", "e", "t", "t", "e", "r", "s", "i", "n", "t", "h", "e", "m", "o", "s", "t", "c", "o", "n", "v", "e", "n", "i", "e", "n", "t"]

Matrix(iquo(nops(L),n),n,L[1..n*iquo(nops(L),n)]);

Matrix(7, 7, {(1, 1) = "H", (1, 2) = "o", (1, 3) = "w", (1, 4) = "d", (1, 5) = "o", (1, 6) = "I", (1, 7) = "t", (2, 1) = "u", (2, 2) = "r", (2, 3) = "n", (2, 4) = "a", (2, 5) = "t", (2, 6) = "e", (2, 7) = "x", (3, 1) = "t", (3, 2) = "i", (3, 3) = "n", (3, 4) = "t", (3, 5) = "o", (3, 6) = "a", (3, 7) = "M", (4, 1) = "a", (4, 2) = "t", (4, 3) = "r", (4, 4) = "i", (4, 5) = "x", (4, 6) = "o", (4, 7) = "f", (5, 1) = "l", (5, 2) = "e", (5, 3) = "t", (5, 4) = "t", (5, 5) = "e", (5, 6) = "r", (5, 7) = "s", (6, 1) = "i", (6, 2) = "n", (6, 3) = "t", (6, 4) = "h", (6, 5) = "e", (6, 6) = "m", (6, 7) = "o", (7, 1) = "s", (7, 2) = "t", (7, 3) = "c", (7, 4) = "o", (7, 5) = "n", (7, 6) = "v", (7, 7) = "e"})

Matrix(`if`(irem(nops(L),n)=0,nops(L)/n, iquo(nops(L),n)+1), n, L);

Matrix(8, 7, {(1, 1) = "H", (1, 2) = "o", (1, 3) = "w", (1, 4) = "d", (1, 5) = "o", (1, 6) = "I", (1, 7) = "t", (2, 1) = "u", (2, 2) = "r", (2, 3) = "n", (2, 4) = "a", (2, 5) = "t", (2, 6) = "e", (2, 7) = "x", (3, 1) = "t", (3, 2) = "i", (3, 3) = "n", (3, 4) = "t", (3, 5) = "o", (3, 6) = "a", (3, 7) = "M", (4, 1) = "a", (4, 2) = "t", (4, 3) = "r", (4, 4) = "i", (4, 5) = "x", (4, 6) = "o", (4, 7) = "f", (5, 1) = "l", (5, 2) = "e", (5, 3) = "t", (5, 4) = "t", (5, 5) = "e", (5, 6) = "r", (5, 7) = "s", (6, 1) = "i", (6, 2) = "n", (6, 3) = "t", (6, 4) = "h", (6, 5) = "e", (6, 6) = "m", (6, 7) = "o", (7, 1) = "s", (7, 2) = "t", (7, 3) = "c", (7, 4) = "o", (7, 5) = "n", (7, 6) = "v", (7, 7) = "e", (8, 1) = "n", (8, 2) = "i", (8, 3) = "e", (8, 4) = "n", (8, 5) = "t", (8, 6) = 0, (8, 7) = 0})

 

Download str2mat.mw

You didn't mention what you wanted to happen to capital letters. You can easily add a step to turn such into lowercase, utilizing the LowerCase command. Just replace the obvious line above with,

    str := LowerCase(Select(IsAlpha,raw));

str2mat_lower.mw

Naturally you could also throw away any capital letters (instead of converting them to lower-case), by utilized the IsLower command as part of the predicate passed to Select. It isn't clear which you want.

For fun, here's another way to get a result in terms of Psi (although, fwiw, it goes funny if assuming n<0).

You can also get a Psi form by directly converting that hypergeom call. I don't know how to do the reverse conversion.

restart;

kernelopts(version);

`Maple 2021.1, X86 64 LINUX, May 19 2021, Build ID 1539851`

F := int( 1/(1+x^n), x=0..1);

int(1/(1+x^n), x = 0 .. 1)

ans1 := IntegrationTools:-Change(F,x^(-n)=r) assuming n>0;

(1/2)*(Psi((1/2)*(n+1)/n)-Psi((1/2)/n))/n

targ := hypergeom( [1,1/n], [1+1/n], -1 );

hypergeom([1, 1/n], [1+1/n], -1)

convert(targ,Psi);

(1/2)*(Psi(1/2+(1/2)/n)-Psi((1/2)/n))/n

Download int_examp.mw

Heavy-handedly,

f := int( 1/(1+x^n), x);

x*LerchPhi(-x^n, 1, 1/n)/n

# limit at zero done under an assumption
raw := limit(f,x=1,left) - limit(f,x=0,right) assuming n>0;

LerchPhi(-1, 1, 1/n)/n

convert(raw, hypergeom);

hypergeom([1, 1/n], [1+1/n], -1)

simplify(convert(raw, Psi), size);

(1/2)*(Psi(1/2+(1/2)/n)-Psi((1/2)/n))/n

(I'll ignore that eval(f,x=0) produces 0 directly.)

Supplying the view option does not specify the range for the independent variable.

Either of these, where the input range for x is specified, work fine.

plot((x^3 - 4*x^2 - 9*x + 36)/(x^3 - 9*x), x = -3 .. 3,
     color = red, view = [-3 .. 3, -5 .. 5]);
plot((x^3 - 4*x^2 - 9*x + 36)/(x^3 - 9*x), x = -3 .. 3,
     color = red, view = -5 .. 5);

If you omit the x-range argument then plot will try to figure something out based on the expression -- but that doesn't utilize the supplied view option.

The view option only specifies how to restrict the display of the computed plotting data. It does not specify how that data should be taken.

Below I use printf, but it's just as easy write to a file by using fprintf.

You can interject any extra lines of text (or newlines) that you want.

Do you really need to create and store all of Fs at once, as opposed to merely checking that each entry of Es does not meet the criteria of being in Fs!? Are you using all Fs for something else? That's unclear, from your wording.

[edit] I keep the way you create the sets, below, since I cannot tell whether you use them for anything else later on. My main point is that the fprintf command is a convenient tool for writing your results to a text file, which was the question asked

restart;

with(GraphTheory):

n:=4:

L:=NonIsomorphicGraphs(n,output=iterator,outputform=graph):

Es:=Array([seq(Edges(L()),j=1..NonIsomorphicGraphs(n,output=count))]):

M:=NonIsomorphicGraphs(n-1,output=iterator,outputform=graph):

FS:={seq(Edges(M()),j=1..NonIsomorphicGraphs(n-1,output=count))}:

for i from 1 to numelems(Es) do
  if not member(Es[i],FS) then
    printf("%a\n",'G'=Es[i]);
    printf("text1\ntext2\ntext3\ntext4\ntext5\n\n");
  end if;
od;

G = {{1, 2}, {3, 4}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {2, 4}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {2, 4}, {3, 4}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {1, 4}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {1, 4}, {2, 3}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}}
text1
text2
text3
text4
text5

G = {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}}
text1
text2
text3
text4
text5
 

 

Download gprintf.mw

Those two piecewise are different from each other when t<0.

You'd have seen that if you'd plotted a range that included negative values for t.

my_sol_ver_1:=y(t) = piecewise(t < 1,-3+4*exp(-t)-exp(-2*t)+2*t,
                               t >= 1 ,4+4*exp(-t)-exp(-2*t)+3*exp(-2*t+2)-8*exp(-t+1),
                               t < 0, 0):

my_sol_ver_2:= y(t) = piecewise(t < 0, 0,
                                t < 1,-3+4*exp(-t)-exp(-2*t)+2*t,
                                t >= 1 ,4+4*exp(-t)-exp(-2*t)+3*exp(-2*t+2)-8*exp(-t+1)):

eval(my_sol_ver_1, t=-1);

y(-1) = -5+4*exp(1)-exp(2)

eval(my_sol_ver_2, t=-1);

y(-1) = 0

Download pw_compar.mw

1 2 3 4 5 6 7 Last Page 1 of 259