acer

32333 Reputation

29 Badges

19 years, 323 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@brian bovril You were having difficulty using the with command. In the 10th bullet point in the Description of the Help page for the with command, it says this:

Some package export names are identical to top-level names with
a global meaning. In addition, two or more packages may export
some of the same names. Provided that a package whose exports
have been bound by using the with command is implemented as a
module, global names are still fully accessible. To access the
global name foo after having bound a package that exports the
name foo, use the prefix form of the 
                              ":-"
 operator, as in  
                            ":-foo"
 .

That pertains to your difficulty in utilizing with on the Calendar package following loading the Finance package which has an export of the same name. But it would be better with an illustrative example.

Also, the 3rd bullet point on the with Help page states this:

The with command is effective only at the top level, and intended
primarily for interactive use. Because with operates by using
lexical scoping, it does not work inside the bodies of procedures,
module definitions, or within statements. See the Examples section.

That relates to your original difficulty in this Question thread. Unfortunately the Example section only shows how not to utilize with in a procedure. And it lacks a correction to utilize use or uses, and has a cross-reference only to the former.

Neither the User Manual (eg. Section 1.5 Commands) nor the Programming Guide (Names?) explains the :- colon-dash syntax well. The Help page for with does also have a cross-reference to the colondash Help page.

I will submit some bug reports against the documentation, for better examples, etc.

The Explore command may offer you a convenient way to study the effects of the parameters (including the possibility of splitting K and Q into real and imaginary components as additional variables or parameters).

But it might help if you could tell us whether you'd prefer 2D plots (including implicit plots in some cases), or 3D plots, or 3D plots with some parameter information encapsulated by color shading, etc.

@sand15 Yes, I see, thanks.

Somebody else clearly thought that this kind of thing was a good idea, since there is a command
   Student:-Statistics:-ExploreRV

But that command doesn't allow one to pass in parameter ranges at all, and only admits them via a Maplet pop-up. (It does offer some handy check-boxes for disabling individual plots on the fly, which might something be expensive.)

I won't pretend to know what might be a better way to get the parameter range details into the App. I was really just imagining how to avoid the reliance on global name x, which is likely over-severe since the Explore parameters already have to be accessed globally.

A tip: when I'm experimenting with an Explore on a complicated mechanism (such as an appliable module, or something where an error may cause problems) I first ensure that the embedded Sliders have the continuous-action Property toggled off (right-click on them, say). That helps prevent an avalanche of popup error boxes if there's a problem when I try and slide far the first tiem. I also Save the sheet before each run.

Best regards.

@brian bovril Since Calendar is both a submodule of Finance as well as a top-level package (in Maple 2019) then you'll have to account for that if you intend on loading both.

restart;

kernelopts(version);

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

with(Finance):

DayCount("13/1/2019","1/1/2019");

-12

with(:-Calendar):

DateDifference(Date(2019,1,13),Date(2019,1,1),units=day);

-12*Units:-Unit(d)

convert(%,unit_free);

-12

 

Download datediff.mw

The with command brings some quick and easy convenience for off-the-cuff coding. But it's not the best tool for programming.

@Christopher2222 Sure, the (now deprecated) font tag is limited. But that's not specific to this use of it in Maple. I figured that you'd just research whatever HTML aspects you'd want to try.

Here is another variant on using the font-size style property.

SetProperty("Button0", ':-caption',
            "<html><p style=\"font-size:20px\">foo</p></html>",
            ':-refresh');

@Christian Wolinski I'm sorry, but I don't understand what you're asking. I'm not sure what you mean here by "the answer"?

This behavior of solve is not very robust, especially for more than one varaible. It's often more convenient to get it to generate a solution containing relations (inequalities) and then convert to RealRange manually if possible.

And, sure, I've seen examples where a second call to solve does indeed help (eg, by cleaning up and merging conditions).

Previously in this thread I was addressing this particular Question's original example, and I made no claim about more general applicability.

restart;

foo := solve({y < -1, y < x, 0 < (2*x)/(x^2 - 1), x < 1});

{-1 < x, x < 0, y < -1}

 

Of course we can check for the absence of mixed terms.

 

convert(And(remove(has,foo,x)[]),RealRange);

y::(RealRange(-infinity, Open(-1)))

convert(And(remove(has,foo,y)[]),RealRange);

x::(RealRange(Open(-1), Open(0)))

 

And (for the benefit of other readers) these can all be picked apart using op.

 

[op(%)];

[x, RealRange(Open(-1), Open(0))]

[op(%[2])];

[Open(-1), Open(0)]

op(map(op,%));

-1, 0

 

Download solve_rr_2.mw

@Christian Wolinski Or call solve just once, as I'd shown an hour ago.

solve(And(-1 < x, 0 < (2*x)/(x^2 - 1), x < 1), x);

Where did the image go?

If the OP removed the image then that would be incredbly rude, given that an answer was supplied.

@Christopher2222 What do you mean?

Do you mean that you want the clock to run k times as fast, from the moment the stopwatch is started?

@Christopher2222 Where it utilizes Today you can instead modify that using AdjustDateField.

Tod := Calendar:-Today():
New := Calendar:-AdjustDateField( Tod, "minute", 10 ):

Calendar:-Format(Tod, "hh:mm:ss a");
Calendar:-Format(New, "hh:mm:ss a");
                         "01:46:55 PM"
                         "01:56:55 PM"

clock_adj.mw

The original question was defaced. It went something like this:

"Does anyone knows how to calculate determinant of a matrix with a proc or function , i mean i don't have to use "det" in maple i need a whole..."

And the original title was, "Help me with determinant calculation of a matrix".

What is the class of optimization problems in which are you interested?

@mmcdara 
Just as a fun alternative,

restart;

f := (x__2+y^3)/(1+cos(y)):

H:=proc(e)
     uses T=Typesetting;
     nprintf(`#%a;`,
             subsindets(convert(T:-Typeset(T:-EV(e)),`global`),
                        identical('fontstyle')=anything,u->NULL));
   end proc:

 

H(f);

`#mfrac(mrow(msup(mi("y"),mn("3")),mo("&plus;"),mi("x__2")),mrow(mn("1"),mo("&plus;"),mrow(mi("cos"),mo("&ApplyFunction;"),mfenced(mi("y")))));`

lprint(%);

`#mfrac(mrow(msup(mi("y"),mn("3")),mo("&plus;"),mi("x__2")),mrow(mn("1"),mo("&p\

lus;"),mrow(mi("cos"),mo("&ApplyFunction;"),mfenced(mi("y")))));`

 

Download for_fun.mw

Of course your mileage may vary, depending on expression.

I recall that (7.5 years ago) I wrote this.

I'm pretty sure that I've duplicated a similar thing (that also adjusts colors of fencing, etc) in several responses over the years.

It's all inter-related: MathML, Maple's Typesetting, etc.

However none of this helps directly with your original question (unless you are willing to accept a space denoting multiplication of H__2 or H[2] and O__2 or O[2], or to remove it in such mechanisms).

Even Robert's suggestion to manually form the concatenated name of a pair of symbols -- both having subscripts -- as an atomic identifier is not entirely straightforward. Backing up over a space between subscripted terms may be one step. Obtaining a result with upright Roman symbols is yet another step. And all as a one-off.

One of the strengths of a programming language is that such constructs can be built programmtically.

restart;

 

mk:=module()
  local f, ModuleApply;
  ModuleApply:=proc(L::list([symbol,posint]))
    local u;
    cat(`#mrow(`,
      f(L[1]),
      seq([`,`,f(L[u])][], u=2..nops(L)), `)`);
  end proc:
  f:=proc(LL::[symbol,posint])
    if LL[2]=1 then
      nprintf("mo(\"%a\",mathcolor = \"blue\")",LL[1]);
    else
      nprintf("msub(mo(\"%a\"),mn(\"%a\"),mathcolor = \"blue\")",
                  LL[1],LL[2]);
    end if;
  end proc:
end module:

mk([[H,2],[O,1]]);

`#mrow(msub(mo("H"),mn("2"),mathcolor = "blue"),mo("O",mathcolor = "blue"))`

mk([[H,2]]);

`#mrow(msub(mo("H"),mn("2"),mathcolor = "blue"))`

mk([[C,8],[H,10],[N,4],[O,1]]);

`#mrow(msub(mo("C"),mn("8"),mathcolor = "blue"),msub(mo("H"),mn("10"),mathcolor = "blue"),msub(mo("N"),mn("4"),mathcolor = "blue"),mo("O",mathcolor = "blue"))`

salt := mk([[Na,1],[Cl,1]]);

`#mrow(mo("Na",mathcolor = "blue"),mo("Cl",mathcolor = "blue"))`

eq := salt = true;

`#mrow(mo("Na",mathcolor = "blue"),mo("Cl",mathcolor = "blue"))` = true

 

I can cut and paste from that 2D Output.

eval(`#mrow(mo("Na",mathcolor = "blue"),mo("Cl",mathcolor = "blue"))`, eq)

true

 

Download typemk_more.mw

@mmcdara If you lprint your example you should be able to detect that your problematic example has some hidden character or space in it.

First 195 196 197 198 199 200 201 Last Page 197 of 591