Joe Riel

8049 Reputation

22 Badges

15 years, 13 days

MaplePrimes Activity


These are replies submitted by Joe Riel

On my system the TZ environmental variable is not set. However, if I do assign and export it, FormatTime displays it:
$ export TZ=PDT
$ maple -q
> StringTools:-FormatTime("%Z");
                                 PDT
You should be displaying the output in a MathMLViewer element, not a text field. MathML:-Export, which is needed to convert a maple expression to a MathML expression does not, alas, properly handle tables, and the output of tensor[create] is a table with two indices: index_char and compts. Fortunately, you don't want to display the value of index_chars, but rather the matrix stored in compts. Here is the code that does that
restart;
with(Maplets[Elements]):
A := matrix([[a,0,0],[0,a,0],[0,0,a]]);
with(tensor):

maplet := Maplet( Window(
    'title'="test"
    ,[NULL
      ,["g_compts "
       ,TextField['TF1']('value' = eval(A), 60)
       ]
      ,MathMLViewer['MMLV1'](value = "")
      ,[NULL
        ,Button("create tensor", Evaluate('MMLV1' = 'MathML[Export](eval(tensor[create]([-1,-1],eval(TF1))[compts]))'))
        ,Button("OK", Shutdown())
       ]
     ])):

Maplets[Display]( maplet );
You should be displaying the output in a MathMLViewer element, not a text field. MathML:-Export, which is needed to convert a maple expression to a MathML expression does not, alas, properly handle tables, and the output of tensor[create] is a table with two indices: index_char and compts. Fortunately, you don't want to display the value of index_chars, but rather the matrix stored in compts. Here is the code that does that
restart;
with(Maplets[Elements]):
A := matrix([[a,0,0],[0,a,0],[0,0,a]]);
with(tensor):

maplet := Maplet( Window(
    'title'="test"
    ,[NULL
      ,["g_compts "
       ,TextField['TF1']('value' = eval(A), 60)
       ]
      ,MathMLViewer['MMLV1'](value = "")
      ,[NULL
        ,Button("create tensor", Evaluate('MMLV1' = 'MathML[Export](eval(tensor[create]([-1,-1],eval(TF1))[compts]))'))
        ,Button("OK", Shutdown())
       ]
     ])):

Maplets[Display]( maplet );
Will, your post should have been in plain text; as it is, the unterminated <b> and <i> do not show and effect the rest of the page. I'd like to see <c> as an abbreviation for <code>. I use code a lot, but the extra typing is a bit painful.
The procedure assume assigns a local variable named (say) a~ to the global variable a. However, the assignment statement does not evaluate its left-side symbol (for good reason), so following the assignment statement, the global a is assigned 0 (etc). However, the Matrix A has the local variable a~, so there is no effect on it. To assign values to the assumed variables you could replace the line a:=0; b:=1/2; c:=0 with assume(a=0,b=1/2,c=0). That works because, unlike the assignment statement, the procedure assume evaluates the variables.
Here I'll enter the previously mentioned code, this time using Filtered HTML mode with tags:
plot(pts, style=point);
As Stephen mentioned, the missing text does not show up in the page source. I added a second </pre> tag. Without it this text was in the preformatted font (with no line breaks).
Well, I'd prefer for bold, rather than the more cumbersome . Oh, wait, I see that it is listed; never mind. Note that is listed twice in the "allowed HTML tags" bullet under "Filtered HTML".
Here's a slight improvement. By using a neutral operator you don't need to use parentheses. If you do use parentheses, each separate (string) argument is entered as a separate comment line.
fn := proc(n)
local x;
    &//("A multiline comment"
        ,"Here is the second line");
    x := n;
    &// "another comment, no parentheses";
    x := x + n;
end proc:

use CodeGeneration in
    LanguageDefinition:-Define(
        "C_with_comments"
        ,extend = "C"
        ,AddFunction("&//", anything::anything
                     ,proc()
                          Printer:-Print(map(Printer:-Comment,[args])[])
                      end proc));
    Translate(fn, language = "C_with_comments");
end use:

double fn (double n)
{
  double x;
    // "A multiline comment"
  // "Here is the second line"
;
  x = n;
    // "another comment, no parentheses"
;
  x = x + n;
  return(x);
}
Thanks for the explanation of Print:-Comment. Notice, though, that it appears to add another level of indentation, which may not be desired. Does the Maple help system describe Names:-Statement? I've seen, I believe, it used in some of the examples, but don't recall seeing an actual description---at least I cannot find it.
Thanks for the explanation of Print:-Comment. Notice, though, that it appears to add another level of indentation, which may not be desired. Does the Maple help system describe Names:-Statement? I've seen, I believe, it used in some of the examples, but don't recall seeing an actual description---at least I cannot find it.
I'm not the original poster, but believe that he wants to annotate the generated C program with comments. Using a Maple comment in the source won't work, maple never sees it. One solution is to enclose a string in a function that has been defined to expand to a comment. For example:
restart;
fn := proc(n)
local x;
    comment("here's my math");
    x := n + n;
end proc:

use CodeGeneration in
    LanguageDefinition:-Define(
        "C_with_comments"
        ,extend = "C"
        ,AddFunction("comment", anything::anything
                     ,proc(s)
                          Printer:-Print(sprintf("// %s",op(s)))
                      end proc));
    Translate(fn, language = "C_with_comments");
end use;

int fn (int n)
{
  int x;
  // here's my math;
  x = 2 * n;
  return(x);
}
This isn't ideal; note the appended semicolon. There should be a better way to do this, probably using the Printer:-Comment procedure, but I couldn't quickly figure it out.
Guess I'm slow today, I cannot guess what you want. The original expression had no vx[i]'s. It had vx[1], but that was repeated several times. That is, there was no vx[1], vx[2], etc. If you meant otherwise, you need to show it. You said that you could create a piecewise version by changing lists to expression sequences. Maybe you should show what you did, that is, the output that you want. When you say that you only want to display "function", do you mean that this is for display purpose only? That is, you don't intend to actually make use of the "function".
Guess I'm slow today, I cannot guess what you want. The original expression had no vx[i]'s. It had vx[1], but that was repeated several times. That is, there was no vx[1], vx[2], etc. If you meant otherwise, you need to show it. You said that you could create a piecewise version by changing lists to expression sequences. Maybe you should show what you did, that is, the output that you want. When you say that you only want to display "function", do you mean that this is for display purpose only? That is, you don't intend to actually make use of the "function".
You can use the sort command, with optional argument ascending or descending to control the order of the terms. For example,
p := randpoly(x):
sort(p,x,'descending');
                       5       4       3       2
                   -7 x  + 22 x  - 55 x  - 94 x  + 87 x - 56

sort(p,x,'ascending');
                                    2       3       4      5
                   -56 + 87 x - 94 x  - 55 x  + 22 x  - 7 x
Here is the relevant part of the note: Numerical solutions can be used in combination with fsolve, but the Digits setting on the call to fsolve must be lower (usually by 5 or more) than the precision for the dsolve procedure (because fsolve requires a higher accuracy on the residual than the current Digits setting). That has nothing to do with this problem, but it is relevant to your code. You are using fsolve with a solution returned by dsolve/numeric. I wasn't aware that dsolve/numeric could use symbolic values that could later (after constructing the procedure) be assigned as globals. The following works (it is a simplification of your problem).
if not assigned(sys) then
    sys := {NULL
            ,diff(s(t),t) = A*(1 - rho^((1 - r^(theta * t)) * x)) - v
            ,s(0) = 0
           }:

    dsol := dsolve(sys, numeric, output = listprocedure):
fi:

A     := 100:
v     := 80:
rho   := 0.996:
r     := 0.9:
theta := 0.993:
c     := 200:

xvals := [700,800,900]:
plts := table():

for i to nops(xvals) do
    x := xvals[i];
    print(x);
    S := eval(s(t), dsol):
    plts[i] := plot([c,S(t)],t=0..50);
    print(fsolve(S(t) = c, t, 0..infinity));
od:

plots[display](seq(plts[i],i=1..nops(xvals)));
First 177 178 179 180 181 182 Page 179 of 182