acer

32405 Reputation

29 Badges

19 years, 349 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

@vv I can't see your response at the moment. But I notice that the following seem equal:

LinearAlgebra:-CharacteristicPolynomial(A,x);
evala(expand(mul(x-rr,rr=evstheory)));

It seems to me that the primary issue here is obtaining the maximum for (only piecewise continuous) Mprof for arbitray tau0 values in your range.

The next issues seem to be doing so reasonably efficiently. And then producing nice individual plots woul be next. And then showing the multiple plots that happen to be on quite different scales would be next.

And mixed in there is the issue of whether delta is always equal to 1 at the optima. I'm deliberately not going to simplify to the methodology for such a case, since you may want to modify your formula/conditions so that no longer holds.

In comparison to all that, merely combining multiple plots or array data seems straightfoward in comparison.

Here are some ideas. I've used Maple 2019, as you did. One of the variants uses 3rd party add-on DirectSearch as fallback.

trial_question_acc.mw

And here's an Mprof plot.

@salim-barzani You need to use the appropriate Maple commands to get your plots.

Here are some examples. You could read the Help Pages for those commands, to adjust the coloring, etc.

You could even provide an actual explanation (in words) of what precisely you want, in terms of color, shading, etc.

graph-density-countour_ac.mw

That produces,

Here are some ways, to get you started.

Input_question_ac.mw

times := [-2.019619977*Unit('s'), 2.019619977*Unit('s'),
          17.019619977*Unit('s'), -11.019619977*Unit('s')];

[-2.019619977*Units:-Unit(s), 2.019619977*Units:-Unit(s), 17.019619977*Units:-Unit(s), -11.019619977*Units:-Unit(s)]

select(u->convert(u,unit_free)>0, times);

[2.019619977*Units:-Unit(s), 17.019619977*Units:-Unit(s)]

%[];

2.019619977*Units:-Unit(s), 17.019619977*Units:-Unit(s)

Download units_select.mw

number := 1;
Var2 := "b";

1

"b"

Using %s to denote a string for the second replacement.
I'd guess that this is like your goal here.

sprintf("file(%a)_%s",number,Var2);

"file(1)_b"

lprint(%);

file(1)_b

Using %a to denote a general algebraic quantity for the
second replacement.

This places the string value of Var2 literally inside the
result string (including the quotes, escaped). This might
not be what you want here.

sprintf("file(%a)_%a",number,Var2);

"file(1)_"b""

lprint(%);

file(1)_\"b\"


Download sprintf_1.mw

As worded, your query seems to be about the sprintf command, and the construction of the filename string to be assigned to fname by using multiple assigned names, rather than about the save command.

See also the Help page for sprintf, for explanation of the modifiers %a, %s, etc. (Apart from its ability to handle symbolic expressions, that Maple command is much like the C language command of the same name. You can find similar commands in C++, R, Matlab, etc.)

However, if you ever do have multiple assigned names (eg. A,C,F) that you wish to save to the .m file then you could pass them as follows,

   save A,C,F fname;

Is this along the lines of what you're trying to accomplish?

restart;

`≅`(a,b)

`≅`(a, b)

alias(`≅` = `union`);

`≅`

a union b;

`≅`(a, b)

Download congruence_symbol.mw

For the subscripts in italics,

   labels = [':-delta__0', ':-s__2']

For the subscripts in upright roman,

   labels = [':-delta[0]', ':-s[2]']

Those should both work even if those names are assigned values (before, or afterwards), and even if this code appears in a procedure with locals like those names.

Another (longer) way, with both base-name and subscript in upright roman,

   labels = [Typesetting:-msub(Typesetting:-mn("δ"),Typesetting:-mn("0")),
                  Typesetting:-msub(Typesetting:-mn("s"),Typesetting:-mn("2"))]

restart;


2D example

Env := x=0.8..3, y=0..1.3;

x = .8 .. 3, y = 0 .. 1.3


Note the `and` instead of And.

Dom := proc (x, y) options operator, arrow; `and`(y <= 1/(1+sinh(2*x)*ln(x)^2), .8 <= x, x <= 3, 0 <= y) end proc

proc (x, y) options operator, arrow; `and`(y <= 1/(1+sinh(2*x)*ln(x)^2), .8 <= x, x <= 3, 0 <= y) end proc


I see no issue (as yet) with having CharFunc return the piecewise,
for nunnumeric x and y. Doing it this way (or just using a piecewise
expression) is actually what I mean by a "bare piecewise".

CharFunc := unapply(piecewise(Dom(x, y), 1, 0),x,y);

CharFunc := proc (x, y) options operator, arrow; piecewise(y <= 1/(1+sinh(2*x)*ln(x)^2) and .8 <= x and x <= 3 and 0 <= y, 1, 0) end proc

CharFunc(x, y);

piecewise(`and`(`and`(`and`(y <= 1/(1+sinh(2*x)*ln(x)^2), .8 <= x), x <= 3), 0 <= y), 1, 0)

plot3d(
  [0, CharFunc(x, y)], Env
  , grid=[40, 40]
  , style=surface, color=[gray, blue], transparency=[0, 0]
  , title=typeset('CharFunc'(x, y))
);


I don't see the need to wrap it in a black-box, that might
return unevaluated for nonnumeric x and y.

CharFunc(x, y);

piecewise(`and`(`and`(`and`(y <= 1/(1+sinh(2*x)*ln(x)^2), .8 <= x), x <= 3), 0 <= y), 1, 0)


By using `and` instead of And in the piecewise, the piecewise is evalhf'able.

evalhf(CharFunc(1.0, 0.3));

1.


So we have something to compare against.

evalf[20](Int(1/(1+sinh(2*x)*ln(x)^2),x=0.8..3));

.67684007571564628609


The question now might be, which results do you trust...

CodeTools:-Usage(
  evalf(Int(CharFunc(x, y), Env, method=_MonteCarlo, epsilon=1e-4))
);

memory used=0.82MiB, alloc change=0 bytes, cpu time=10.00ms, real time=10.00ms, gc time=0ns

.7150000000

CodeTools:-Usage(
  evalf(Int(CharFunc(x, y), Env, method=_CubaDivonne, epsilon=1e-5))
);

memory used=8.45MiB, alloc change=0 bytes, cpu time=380.00ms, real time=380.00ms, gc time=0ns

HFloat(0.6768336654696097)

CodeTools:-Usage(
  evalf(Int(CharFunc(x, y), Env, method=_CubaVegas, epsilon=1e-3))
);

memory used=145.82KiB, alloc change=0 bytes, cpu time=358.00ms, real time=359.00ms, gc time=0ns

HFloat(0.6768739604529882)

CodeTools:-Usage(
  evalf(Int(CharFunc(x, y), Env, method=_CubaSuave, epsilon=1e-5))
);

memory used=145.49KiB, alloc change=0 bytes, cpu time=2.08s, real time=2.08s, gc time=0ns

HFloat(0.6740073134054702)

CodeTools:-Usage(
  evalf(Int(CharFunc(x, y), Env, method=_CubaSuave, epsilon=1e-5))
);

memory used=15.92KiB, alloc change=0 bytes, cpu time=1000.00us, real time=1000.00us, gc time=0ns

HFloat(0.6740073134054702)

 

 

Download Integration_issue_ac.mw

Do you mean this video, available on youtube? (There is also a static PDF document of that.)

One other simple way to handle this example, aside from just the previously mentioned convert(x in solve(sl10),relation), is,

sl10 := -1 <= (3-5*x)*(1/2) and (3-5*x)*(1/2) <= 9

`and`(op(solve(sl10, {x})))

-3 <= x and x <= 1

Download Combined_Inequality_ac.mw


This new example can also be handled with the procedure I gave you last week (capable of handling some more involved compound examples), ie.,

restart;

G := proc(R)
   (u->ifelse(nops(u)>1,%or(op(u)),op(u)))(
      map(u->ifelse(u::{set,list} and nops(u)>1,
                    `%and`(op(u)),op(u)),
          [solve(subsindets(convert(R,relation),
                            And({`<`,`<=`},satisfies(u->has(u,infinity))),
                            ()->NULL),{x})]));
end proc:

 

sl10 := -1 <= (3-5*x)*(1/2) and (3-5*x)*(1/2) <= 9

G(sl10)

%and(-3 <= x, x <= 1)

Download some_2D_range_ineq_2.mw


note: The call solve(sl10) returns RealRange(-3,1), and your Question from last week was just about turning such closed set forms into inequalities. So, this really is almost the same Question.

In future please add such close followup queries as Replies/Comments in your earlier Question thread (or at least use the Branch button from there to create a related/linked new Question), instead of spawning a wholly separate new Question thread.

Both the commands to generate the teams, and the commands to printf the teams, can be done as simple one-liners.

The number of members of a team (or that minus 1) only appears once in each of those one-liners.

restart;

new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben"]:

sets := [ListTools:-LengthSplit(new_team,2)];

[["Michael K", "Andy C"], ["Michael G", "Mitch"], ["Jez", "Dean B"], ["Anthony B", "Rik B"], ["Ilya", "Fariborz"], ["Eugene", "Tania"], ["Bill", "Stevs"], ["Victor", "Jane"], ["Nash", "Ben"]]

seq(printf(cat("set %a:"," %s,"$1," %s\n"),i,sets[i][]),i=1..nops(sets));

set 1: Michael K, Andy C
set 2: Michael G, Mitch
set 3: Jez, Dean B
set 4: Anthony B, Rik B
set 5: Ilya, Fariborz
set 6: Eugene, Tania
set 7: Bill, Stevs
set 8: Victor, Jane
set 9: Nash, Ben

new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben", "Malachi T", "R", "Sachin ", "Prakash Sn", "Graeme", "Nayu", "Martih", "Rickn", "Ahmed"]:

sets := [ListTools:-LengthSplit(new_team,3)];

[["Michael K", "Andy C", "Michael G"], ["Mitch", "Jez", "Dean B"], ["Anthony B", "Rik B", "Ilya"], ["Fariborz", "Eugene", "Tania"], ["Bill", "Stevs", "Victor"], ["Jane", "Nash", "Ben"], ["Malachi T", "R", "Sachin "], ["Prakash Sn", "Graeme", "Nayu"], ["Martih", "Rickn", "Ahmed"]]

seq(printf(cat("set %a:"," %s,"$2," %s\n"),i,sets[i][]),i=1..nops(sets));

 

set 1: Michael K, Andy C, Michael G
set 2: Mitch, Jez, Dean B
set 3: Anthony B, Rik B, Ilya
set 4: Fariborz, Eugene, Tania
set 5: Bill, Stevs, Victor
set 6: Jane, Nash, Ben
set 7: Malachi T, R, Sachin
set 8: Prakash Sn, Graeme, Nayu
set 9: Martih, Rickn, Ahmed


Download teams_ac.mw


If you wanted a reusable procedure that did both the construction and the printf,

restart;

G := proc(L,n)
  local sets:=[ListTools:-LengthSplit(L,n)];
  seq(printf(cat("set %a:"," %s,"$(n-1)," %s\n"),
             i,sets[i][]),i=1..nops(sets));
  sets;
end proc:


new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben"]:

sets := G(new_team, 2);

set 1: Michael K, Andy C
set 2: Michael G, Mitch
set 3: Jez, Dean B
set 4: Anthony B, Rik B
set 5: Ilya, Fariborz
set 6: Eugene, Tania
set 7: Bill, Stevs
set 8: Victor, Jane
set 9: Nash, Ben

[["Michael K", "Andy C"], ["Michael G", "Mitch"], ["Jez", "Dean B"], ["Anthony B", "Rik B"], ["Ilya", "Fariborz"], ["Eugene", "Tania"], ["Bill", "Stevs"], ["Victor", "Jane"], ["Nash", "Ben"]]


new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben", "Malachi T", "R", "Sachin ", "Prakash Sn", "Graeme", "Nayu", "Martih", "Rickn", "Ahmed"]:

sets := G(new_team, 3);

set 1: Michael K, Andy C, Michael G
set 2: Mitch, Jez, Dean B
set 3: Anthony B, Rik B, Ilya
set 4: Fariborz, Eugene, Tania
set 5: Bill, Stevs, Victor
set 6: Jane, Nash, Ben
set 7: Malachi T, R, Sachin
set 8: Prakash Sn, Graeme, Nayu
set 9: Martih, Rickn, Ahmed

[["Michael K", "Andy C", "Michael G"], ["Mitch", "Jez", "Dean B"], ["Anthony B", "Rik B", "Ilya"], ["Fariborz", "Eugene", "Tania"], ["Bill", "Stevs", "Victor"], ["Jane", "Nash", "Ben"], ["Malachi T", "R", "Sachin "], ["Prakash Sn", "Graeme", "Nayu"], ["Martih", "Rickn", "Ahmed"]]


Download teams_ac2.mw

It looks like you have mistakenly split the do-loop code across Document Blocks (or Execution Groups, though there's a slight hint in your posting that you might be pasting into Document Blocks).

Don't press Enter/Return, while typing/pasting in the Block/Group with that do-loop code. That would execute what's entered so far, and split it.

You can use Shift-Enter to get to a new line, when editing in a Block/Group.

If you look at the example in the subsection "Getting the Number of Elements in a List" of Section 4.3 or the Programming Guide (which seems to be your example), then you can see that all the red code of the while-do loop is within the same Execution Group.

That is, the beginning while, and the end do, and all the loop's contents between those, must be within the same Execution Group (or Document Block). Otherwise you'd get those kinds of error messages.

Here's what it might look like, if accidentally split. Notice the left border of the Maple GUI can show Markers that denote the Block/Group boundaries.

Download doc_block_oops.mw

I dug around and found this in the vault (edited slightly to get rid of the infinity, which solve only sometimes removes).

This kind of thing has been asked before, both the basic query about conversion of a real range to inequality relations, as well as simplification of compound examples.

The basic examples are a common flavor, for such there is a dedicated command, as has been mentioned: convert(...,relation).

A related idea is that one can do some simplification for some more involved examples. Also, on output, multiple conditions and multiple solutions can be displayed using Or/And, or %or if one wants, or (last link in end note) union/intersect.

I put the RealRange inputs into 2D form, for fun.

restart;

 

G := proc(R)
   # extra stuff to beautify multiple output
   (u->ifelse(nops(u)>1,%or(op(u)),op(u)))(
      map(u->ifelse(u::{set,list} and nops(u)>1,
                    `%and`(op(u)),op(u)),
          [solve(subsindets(convert(R,relation),
                            And({`<`,`<=`},satisfies(u->has(u,infinity))),
                            ()->NULL),{x})]));
end proc:


Now, shown as 2D Input,

G(x::(RealRange(1, Open(4))))

%and(1 <= x, x < 4)

G(x::(RealRange(Open(2), Open(infinity))))

2 < x

G(x::(RealRange(2, 3)))

%and(2 <= x, x <= 3)

G(x::(RealRange(Open(-infinity), -3)))

x <= -3


Alternatively,

G(`in`(x, RealRange(1, Open(4))))

%and(1 <= x, x < 4)

G(`in`(x, RealRange(Open(2), Open(infinity))))

2 < x

G(`in`(x, RealRange(2, 3)))

%and(2 <= x, x <= 3)

G(`in`(x, RealRange(Open(-infinity), -3)))

x <= -3


Some fun,

G(`or`(x::(RealRange(2, Open(infinity))), x::(RealRange(-3, 3))))

-3 <= x

G(`and`(x::(RealRange(2, Open(infinity))), x::(RealRange(-3, 3))))

%and(2 <= x, x <= 3)

G(`or`(x::(RealRange(Open(-infinity), -2)), x::(RealRange(-1, 3))))

%or(x <= -2, %and(-1 <= x, x <= 3))

G(`or`(x::(RealRange(Open(-infinity), -2)), x::(RealRange(-3, 3))))

x <= 3

G(`and`(x::(RealRange(-infinity, -2)), x::(RealRange(-3, 3))))

%and(-3 <= x, x <= -2)

G(`or`(`in`(x, RealRange(-infinity, 6)), `in`(x, RealRange(-4, 7))))

x <= 7

G(`and`(`in`(x, RealRange(-infinity, -2)), `in`(x, RealRange(-3, 3))))

%and(-3 <= x, x <= -2)

G(Or(`in`(x, RealRange(-infinity, 6)), `in`(x, RealRange(-4, 7))))

x <= 7

G(And(`in`(x, RealRange(-infinity, -2)), `in`(x, RealRange(-3, 3))))

%and(-3 <= x, x <= -2)

Download some_2D_range_ineq.mw

[edit] It's it's of interest, here are a few old postings on related (or more involved) queries: 1, 2, 3

Given the input ode, why not go straight to,

   has(convert(ode,D),y(x));

without any replacement by Z^N terms.

First 9 10 11 12 13 14 15 Last Page 11 of 336