Joe Riel

9660 Reputation

23 Badges

20 years, 2 days

MaplePrimes Activity


These are replies submitted by Joe Riel

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)));
If you pressed shift-enter after each line, then the group should execute as one. Yes, I meant the F4 key (not command). It is a short-cut for the Edit -> Split or Join -> Join Execution Groups command. Ah, now I see. This is an interesting problem. It appears as though fsolve is using the wrong solution to the differential equation. Plotting them shows that dsolve is returning the proper plot for solution. Does fsolve use a remember table? Apparently. To get this to work, add a line before fsolve:
forget(fsolve);
tau := fsolve(S(t)= c, t, 0..infinity);
That appears to solve your problem. Read the second note in ?dsolve/numeric. It states that you might need to reduce Digits when using fsolve with a result. To avoid reassigning it you can change the call to
tau := eval[6](fsolve(S(t)= c, t, 0..infinity));
Are you sure that you executed all the statements? That is, if the input is entered on separate input lines in a worksheet, you cannot just reexecute the line that assigns to x and the plot statement. You have to reexecute all the lines that use x. You should use the F4 command to combine all the lines into one executable group. I just entered the lines into a text file and read them into maple. I then enclosed them in a do loop:
for x in [800,1000,1200] do
  ... # comment out the assignment to x
  print(plot[odeplot](...))
od:
and reread the file. It plotted three distinct plots.
There is, so for as I can tell, no consensus on the use of the terms "parameter" and "argument" in this context. Some documentation use the terms interchangeably. When I think about it, I generally use "argument" to mean "actual parameter", however, when clarity matters I'll use the two-word phrases.
First 190 191 192 193 194 195 Page 192 of 195