acer

31317 Reputation

29 Badges

19 years, 114 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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.

The simplest (and most effective and efficient way, IMO) is to use a so-called operator form calling sequence of the evalf(Int(...)) or int(...,numeric) or int(...,0..6.0) commands, where the integrand is supplied as an operator/procedure f rather than a function call like f(x).

There are several ways to get it to work instead with something that looks like an unevaluated function call (of x, like f(x), say) as the integrand. But they are often unnecessarily more complicated than the above. I'll show a few such ways.

restart

with(Interpolation)

X := [2, 4, 8, 12, 14, 20]

Y := [1, 3, 11, 8, 19, 23]

Z__lin := LinearInterpolation(X, Y)

Z__spline := SplineInterpolation(X, Y)


These first ones are all pretty straightforward, easy, and terse, IMO.

These first four examples all use calling sequences of the command
with so-called operator-form for the integrand.

I'll do it for both your interpolations.

evalf(Int(Z__lin, 0 .. 6))

HFloat(13.999999999999517)

evalf(Int(Z__spline, 0 .. 6))

HFloat(14.878464818761161)

int(Z__lin, 0 .. 6, numeric)

HFloat(13.999999999999517)

int(Z__spline, 0 .. 6, numeric)

HFloat(14.878464818761161)

int(Z__lin, 0 .. 6.0)

HFloat(13.999999999999517)

int(Z__spline, 0 .. 6.0)

HFloat(14.878464818761161)


Now, for brevity, I'll just deal with just one of your interpolations,
while showing some so-called expression-form (function call) forms
for the integrand..

The next needs exactly two pairs of single quotes-quotes.

int((''Z__lin'')(x), x = 0 .. 6.0)

HFloat(13.999999999999517)


The next needs exactly three pairs of single right-quotes.

evalf(int(('''Z__lin''')(x), x = 0 .. 6))

HFloat(13.999999999999517)


The next MakeFunction (or unapply) require a special incantation.

fZ__lin := MakeFunction('Z__lin(x)', x, numeric)

int(fZ__lin(x), x = 0 .. 6.0)

HFloat(13.999999999999517)

evalf(int(fZ__lin(x), x = 0 .. 6))

HFloat(13.999999999999517)

NULL

Download Using_interpolation_ac.mw

You could add the dirfield option, eg.
   dirfield=[11,11]

And you can blend this with other options, eg.
   'arrows'='comet',dirfield=[11,11],arrowsize=1.2

You can save all the assigned names (including just user-defined names), but there's no easy way to save&restore all internal state including memoized results in remember tables and caches.

That's not to say that it's generally impossible (for, say, an expert), especially for Library routines. However there's no stock command for it.

Saving/restoring all the remembered results in all kernel built-ins (eg. evalf, series, etc) might be much harder and perhaps not possible.

Since there are several flavors to this, it would be better if you supplied a concrete, representative example.

Your eval calls attempt to replace names like f__1, f__2, etc, but your expression M actually contains f[1], f[2], etc.

plot_a_ac.mw

Here are a few ways, which you might adjust with options, etc.

My "trick" is to create a system for each param1 value, instead of trying to use it as a DS TransferFunction `parameter` in that routine's technical sense.

[edit: I added plots:-animate]

simple_bode_ac.mw

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