stefanv

210 Reputation

6 Badges

14 years, 178 days

Stefan Vorkoetter is a Senior Architect at Maplesoft, a position that is a combination of design consultant and developer-at-large.

He has been with Maplesoft since May of 1989 after completing a graduate program at the University of Waterloo under Maplesoft co-founder Gaston Gonnet. During his undergraduate career, he worked part time at UW's Symbolic Computation Group, where the Maple system was born.

Stefan's areas of expertise are in algorithms, data structures, and programming language design and implementation. He has worked extensively on various aspects of the Maple kernel, and more recently, the Modelica compiler component of MapleSim. Despite holding a Master of Mathematics degree, he considers himself a computer scientist first.

Stefan was born in Germany, but immigrated to Canada at the age of three. Like many at Maplesoft, he moved to Waterloo to attend the University of Waterloo, met his wife there, and never left. When not working, Stefan is an active participant in the Norwegian Fjordhorse farm he and Lori call home. He also dabbles in electronics, model and full-scale aviation, music, and collecting slide rules and old calculators, and maintains a web site documenting his hobbies.

MaplePrimes Activity


These are answers submitted by stefanv

First, define the following procedure. You can type it into your session, or could do this in your .mapleinit (Linux/Mac) or maple.ini (Windows) file.

SaveAll := proc( fileName :: string )
    subs(_NAMES = anames(':-user'),
         proc() save _NAMES, fileName end proc)()
end proc; 

You can then use, for example, SaveAll("myvars.m") to save all your variables. In a later session, you can use read "myvars.m" to read everything back in.

When the file name ends in ".m", the save will be in Maple's internal format. If you use any other file extension (or none at all), the save will be in Maple language form, meaning you'd be able to edit it before reading it back.

Illustrated here with printf:

> V := <1,2,3,4,5>:
> printf("V=%d\n",V);
V=1 2 3 4 5

There are many additional formatting options that can be applied. For more details, see the ?rtable_printf help topic.

I assume your question is, why does the last line not work?

There are two ways to generate the answer you are looking for:

c := LinearAlgebra:-MatrixVectorMultiply(A,V);

or,

c := A.V;

The behaviour you are seeing in Maple 2018 has been the behaviour for a long as I can remember (1986). The writeto function redirects all output to the file until redirected elsewhere by another writeto call.

If I add interface(echo=0) to the commands (after the restart) and pass the file to Maple by command line redirection, then only Hello appears in the file.

An error such as, "cannot determine if x<0 is true or false", typically means that x doesn't have a numeric value at that point in time (hence we can't tell if it's true).

What's probably happening is that your second if-statement is not being satisfied, so Stability2 doesn't get assigned any value. When you get to the third if-statement, the test Stability2 > 0 fails, since we don't know what Stability2 is.

Is the body of your _first_ if-statement supposed to assign to Stability1, or did you mean to write Stability2 there as well?

BTW, your if-statements would be much easier to read if you used "and" instead of nested if-statements, e.g.:

if X1 >= 0 and 0 < Scr1 and 0 < Skr1 and 0 < Icr1 then
    Stability1 := det(eval(s, {c = Scr1, k = Skr1, mu = m, x = X1, y = Icr1, delta = del, gamma = g, omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac, beta[1] = b1, beta[3] = b3}));
end if;

Stefan Vorkoetter - Maplesoft

First, here's your code again, reformatted for easy readability:

    for Lambda from 40 to 80 do
        R0 := eval(R[0], {mu = m, delta = del, gamma = g, omega = o,
            d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        qq := eval(Y, {mu = m, delta = del, gamma = g, omega = o,
            d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        x1 := RootOf(qq, index = 1);
        x2 := RootOf(qq, index = 2);
        X1 := simplify(x1);
        X2 := simplify(x2);
        Icr1 := eval(Ic, {mu = m, x = X1, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        Scr1 := eval(Sc, {mu = m, x = X1, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        Skr1 := eval(Sk, {mu = m, x = X1, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        Icr2 := eval(Ic, {mu = m, x = X2, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        Scr2 := eval(Sc, {mu = m, x = X2, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        Skr2 := eval(Sk, {mu = m, x = X2, delta = del, gamma = g,
            omega = o, d[1] = dk, d[2] = dc, alpha[1] = ak, alpha[2] = ac,
            beta[1] = b1, beta[3] = b3});
        if 0 <= X1 then
            if 0 < Scr1 then
                if 0 < Skr1 then
                    if 0 < Icr1 then
                        print('one', Lambda, R0, X1, Icr1, Scr1, Skr1)
                    end if
                end if
            end if
        end if;
        if 0 <= X2 then
            if 0 < Scr2 then
                if 0 < Skr2 then
                    if 0 < Icr2 then
                        print('two', Lambda, R0, X2, Icr2, Scr2, Skr2)
                    end if
                end if
            end if
        end if
    end do

Are the points that you're printing as 'one' the stable points, and the 'two' points the unstable ones?

Assuming that's the intent, I'd proceed like this. Efficiency isn't a great concern here, so we'll just build up two sequences of points. So, before the code above, add:

    stablePoints := NULL;
    unstablePoints := NULL;

Next, replace the two print statements with:

    stablePoints := stablePoints, [R0,X1];

and

    unstablePoints := unstablePoints, [R0,X2];

Finally, after your code, generate two point plots, and then combine them:

    plot1 := plots[pointplot]([stablePoints],connect=true,linestyle=solid);
    plot2 := plots[pointplot]([unstablePoints],connect=true,linestyle=dash);
    plots[display](plot1,plot2); 

Stefan Vorkoetter - Maplesoft

As Joe has pointed out, Maple's tables are hash tables, and as such can be indexed by any expression(s), not just numbers. This makes them very flexible, but they aren't the best choice of data structure if you plan to be working with integer-indexed rectangular arrays of numbers. For this, the Vector, Matrix, or Array structures (with an uppercase V, M, and A respectively) are more appropriate. If you plan on doing any linear algebra with your structures, use Vectors and Matrices (i.e. mathematical structures). If you just want n-dimensional arrays (where n is 0 to 63) to store data in, use Arrays (i.e. computer-science structures).

The drawback to these structures is that you have to declare their size in advance (unless you are using Maple 13 or newer). Your example becomes:

a := Array(1..4,1..3);
for i from 1 to 4 do
  for j from 1 to 3 do
    a[i,j]:=5*i;
  end do;
end do;
print(a);

The output becomes:

                       [ 5     5     5]
                       [              ]
                       [10    10    10]
                       [              ]
                       [15    15    15]
                       [              ]
                       [20    20    20]

If you are using Maple 13 or newer, you still have to declare the Array, but you can set the dimensions to 1..1,1..1. Then, you can use round brackets instead of square brackets for indexing, and the Array will grow automatically to suit.

Stefan Vorkoetter - Maplesoft

Page 1 of 1