Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The coeff procedure works on algebraic expressions, not equations.  Try coeff(lhs(functie3),t3,2). 

Maybe you can give an example.  The function sscanf would be useful mainly if you had to parse strings, is that the case?

How many conditions do you expect the piecewise to have?  The piecewise is not particularly efficient with lots of conditions (they are evaluated sequentially).

You might want to arrange the conditions to implement a binary search, which will make the average evaluation time O(lg(n)) rather than O(n).  That will require nested piecewises.  Here is one way to do that (creating new matrices isn't the best technique, but it is easy to implement):

dataToPW := proc(M :: Matrix, x::name, $)
local m, j;
description "create nested piecewise expression that represents the data in M";
    # This assume M is sorted in its first column
    m := op([1,1],M);
    if m=1 then
        return M[1,2];
    else
        j := iquo(m,2);
        return piecewise(x <= M[j,1]
                         , procname(M[1..j, ..], x)
                         , procname(M[j+1..,..], x)
                        );
    end if;
end proc:

n := 8:
data := Matrix([seq([i,i^2], i=1..n)]):
PW := dataToPW(data, x);
             { { { 1         x <= 1
             { { {                             x <= 2
             { { { 4        otherwise
             { {                                                x <= 4
             { { { 9          x <= 3
             { { {                            otherwise
             { { { 16        otherwise
       PW := {
             { { { 25         x <= 5
             { { {                             x <= 6
             { { { 36        otherwise
             { {                                               otherwise
             { { { 49         x <= 7
             { { {                            otherwise
             { { { 64        otherwise

The plotting is easy enough.  As you surmised, implicitplot3d will do the job:

plots:-implicitplot3d(z^2=1-(r-5)^2, r = 0..7, theta = 0..2*Pi, z = -3..3, coords = cylindrical);

The first argument has to be a procedure.  Also, the conditional has the else last. Finally, the operator arrow has one hyphen, not two.  I'm still not sure what you want, but the following is closer:

z -> if Re(z) >=0 then evalb(Im(z) > 0) else evalb(Re(z)=0) end if

 

Remove all the with(linalg) calls.  linalg is old and doesn't work with Matrices.  Never use with inside a procedure, it won't work properly there.

Using * to multiply Matrices doesn't work, use either the dot operator (.), or procedure calls (see LinearAlgebra).

To call a procedure you have to append parentheses.  For example, in Step4 change Print to Print();

Does A contain sublists?  Rather than convert, try

Array(1..nops(A), A);

Note also that this returns an Array, not an array.  The latter is an older Maple structure.

There are a few problems with this.  First, the if functions are evaluated immediately.  Second, the conditions of the if's are expressed as equalities, which will not work. The independent variable (t) is continuous, as such it makes no sense numerically to compare it to any value.  You should use inequalities (t<=0, t<=1, t<=2, t<=3). Third, the differential equation has the parameters b, c, and n, which are undefined.  Probably they are meant to be functions of e and f.

You can express the if's using the piecewise function.  Here is one approach; I arbitrarily reassigned b, c, and n:

a := .178131:

pw := piecewise(t <= 1, 6, t <= 2, 10, t <= 3, 15, 20):

e := -0.6814e-1*pw:
f := 0.16242e-1*pw^(1.5):

# Arbitrary assignments
n := 2:
b := e:
c := f:

dsys := [diff(Log10S(t), t) = -(a+b+c)*n*(-Log10S(t)/(a+b+c))^((n-1)/n), Log10S(0) = -0.1e-3]:
integ := dsolve(dsys, numeric):
integ(6);
                    [t = 6., Log10S(t) = -4.28489796949036]

Easier might be

(**) ans:=solve(x^4=16,{x});
                ans := {x = 2}, {x = -2}, {x = 2 I}, {x = -2 I}

(**) subs(x=m, [ans]);
                  [{m = 2}, {m = -2}, {m = 2 I}, {m = -2 I}]

selectremove( z -> Re(z) >= 0, ... );

Applying an assumption to a variable creates an assignment that assigns a new variable (theta~) to the original variable (theta). However, the left side of a Maple assignment is not evaluated, so

  theta := 0

assigns a new value to theta that replaces the theta~.   There are two way around this.  One is to use the assign procedure to assign the value:

  assign(theta,0);

That works because theta is evaluated (to theta~) before the assignment is made. The alternative---my preference---is to avoid assigning to the variable and use eval:

  eval(A, theta=0);

Its not clear to me what you are asking.  Regardless, using variables that start with underscores in not a good idea. See ?underscore:

Names Beginning with the Underscore Character

Description

o Any symbol beginning with an underscore (_) is effectively reserved for use
  only by library code. It is not available to users. Failure to observe this
  rule can lead to unexpected results.

I'm not suggesting that that is causing whatever problem you are having, just warning against the practice.

Another possibility is

add(x, x in L);

As a procedure:

f := proc(L) 
local x;
    add(x, x in L);
end proc:

Function composition can also be used

f := `+`@op:
f([a,b,c]);
                  a + b + c

 

From your examples I deduced that you wanted the first element in a list to be s if the number of elements in the list is odd, otherwise the first element is t. After that, the elements alternate between s and t.  This was an easy way to both alternate parity (with j) and ensure that the first element of each sublist was the appropriate term.  Your explanation is correct. 

(**) f := k -> x -> k*x:
(**) g := f(3):
(**) g(a); 
                                                  3 a

The proc form is more general.  It permits multiple statements and optional arguments.

 

[seq([seq(`if`((j+k)::even,s,t),j=1..k)],k=1..5)];
                         [[s], [t, s], [s, t, s], [t, s, t, s], [s, t, s, t, s]]
First 71 72 73 74 75 76 77 Last Page 73 of 114