Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Note that it isn't just sqrt that will change the expression. Maple will automatically do the same with rational^rational:

 (3/4)^(1/2);
                               1/2  1/2
                              3    4
                              ---------
                                  4

@pagan Good point. I'm aware of the 2D disambiguation for functional style input, but had forgotten about it. I think in 1D.

@pagan Good point. I'm aware of the 2D disambiguation for functional style input, but had forgotten about it. I think in 1D.

You omitted some steps.  What is dsys?

You can create both sets at once by using ?selectremove

You can create both sets at once by using ?selectremove

@Marten To get fsolve to handle the krylov functions, the procedures need to be assigned. That has to be done in a way such that if the argument is non-numeric, the call is returned unevaluated.  The basic idea is

    K1 := proc(ex)
        if ex = 0 then
            return 1;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

The updated module follows.  I made K1,...,K4 exports rather than globals.

krylov := module()
option package;

export K1,K2,K3,K4,To, From, Simplify, Evalf;

local ModuleLoad, removeImaginary;

    ModuleLoad := proc()
    global `convert/tokrylov`, `convert/fromkrylov`, `simplify/krylov`
        , `evalf/K1`, `evalf/K2`, `evalf/K3`, `evalf/K4`
        , `diff/K1`, `diff/K2`, `diff/K3`, `diff/K4`
        ;

        `convert/tokrylov`   := To;
        `convert/fromkrylov` := From;
        `simplify/krylov`    := Simplify;
        `evalf/K1`           := x -> Evalf(K1(x));
        `evalf/K2`           := x -> Evalf(K2(x));
        `evalf/K3`           := x -> Evalf(K3(x));
        `evalf/K4`           := x -> Evalf(K3(x));
        `diff/K1`            := ex -> K4(ex)*diff(ex,_rest);
        `diff/K2`            := ex -> K1(ex)*diff(ex,_rest);
        `diff/K3`            := ex -> K2(ex)*diff(ex,_rest);
        `diff/K4`            := ex -> K3(ex)*diff(ex,_rest);

    end proc;

    To := proc(ex)
        eval(ex, [cos = K1-K3,
                  sin = K2-K4,
                  cosh = K1+K3,
                  sinh = K2+K4
                 ]);
    end proc:

    From := proc(ex)
        eval(ex, [K1 = 1/2*cosh + 1/2*cos,
                  K2 = 1/2*sinh + 1/2*sin,
                  K3 = 1/2*cosh - 1/2*cos,
                  K4 = 1/2*sinh - 1/2*sin
                 ]);
    end proc:

    Evalf := proc(ex)
        evalf(From(ex), _rest);
    end proc;

    Simplify := proc(ex)
        # a very basic simplification, Kx(I*z) --> Kx(z)
        evalindets(ex
                   , 'specfunc(anything,{K1,K2,K3,K4})'
                   , fx -> op(0,fx)(removeImaginary(op(1,ex)))
                  );
    end proc:

    removeImaginary := proc(ex)
        if ex :: imaginary
        or ex :: `*` and ormap(type,ex,imaginary)
        then
            return ex/I;
        else
            return ex;
        end if;
    end proc;

    K1 := proc(ex)
        if ex = 0 then
            return 1;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K2 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K3 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K4 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    ModuleLoad();

end module:

You can now do

with(krylov):
fsolve(K1(x)+K2(x) = 0.5);
                                 -0.5023876680

 

Probably some of the code in the Simplify routine should be moved into the assignments to K1, etc.

@Marten To get fsolve to handle the krylov functions, the procedures need to be assigned. That has to be done in a way such that if the argument is non-numeric, the call is returned unevaluated.  The basic idea is

    K1 := proc(ex)
        if ex = 0 then
            return 1;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

The updated module follows.  I made K1,...,K4 exports rather than globals.

krylov := module()
option package;

export K1,K2,K3,K4,To, From, Simplify, Evalf;

local ModuleLoad, removeImaginary;

    ModuleLoad := proc()
    global `convert/tokrylov`, `convert/fromkrylov`, `simplify/krylov`
        , `evalf/K1`, `evalf/K2`, `evalf/K3`, `evalf/K4`
        , `diff/K1`, `diff/K2`, `diff/K3`, `diff/K4`
        ;

        `convert/tokrylov`   := To;
        `convert/fromkrylov` := From;
        `simplify/krylov`    := Simplify;
        `evalf/K1`           := x -> Evalf(K1(x));
        `evalf/K2`           := x -> Evalf(K2(x));
        `evalf/K3`           := x -> Evalf(K3(x));
        `evalf/K4`           := x -> Evalf(K3(x));
        `diff/K1`            := ex -> K4(ex)*diff(ex,_rest);
        `diff/K2`            := ex -> K1(ex)*diff(ex,_rest);
        `diff/K3`            := ex -> K2(ex)*diff(ex,_rest);
        `diff/K4`            := ex -> K3(ex)*diff(ex,_rest);

    end proc;

    To := proc(ex)
        eval(ex, [cos = K1-K3,
                  sin = K2-K4,
                  cosh = K1+K3,
                  sinh = K2+K4
                 ]);
    end proc:

    From := proc(ex)
        eval(ex, [K1 = 1/2*cosh + 1/2*cos,
                  K2 = 1/2*sinh + 1/2*sin,
                  K3 = 1/2*cosh - 1/2*cos,
                  K4 = 1/2*sinh - 1/2*sin
                 ]);
    end proc:

    Evalf := proc(ex)
        evalf(From(ex), _rest);
    end proc;

    Simplify := proc(ex)
        # a very basic simplification, Kx(I*z) --> Kx(z)
        evalindets(ex
                   , 'specfunc(anything,{K1,K2,K3,K4})'
                   , fx -> op(0,fx)(removeImaginary(op(1,ex)))
                  );
    end proc:

    removeImaginary := proc(ex)
        if ex :: imaginary
        or ex :: `*` and ormap(type,ex,imaginary)
        then
            return ex/I;
        else
            return ex;
        end if;
    end proc;

    K1 := proc(ex)
        if ex = 0 then
            return 1;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K2 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K3 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    K4 := proc(ex)
        if ex = 0 then
            return 0;
        elif ex :: float then
            return Evalf('procname'(ex));
        else
            return 'procname'(ex);
        end if;
    end proc;

    ModuleLoad();

end module:

You can now do

with(krylov):
fsolve(K1(x)+K2(x) = 0.5);
                                 -0.5023876680

 

Probably some of the code in the Simplify routine should be moved into the assignments to K1, etc.

You could add the following to the module (assigned in the ModuleLoad procedure).  Or, if that is all you need, just use these by themselves:

        `diff/K1`  := ex -> K4(ex)*diff(ex,_rest);
        `diff/K2`  := ex -> K1(ex)*diff(ex,_rest);
        `diff/K3`  := ex -> K2(ex)*diff(ex,_rest);
        `diff/K4`  := ex -> K3(ex)*diff(ex,_rest);

If you put them in the module, you'll also need to declare them as global, similar to the evalf extensions.

You could add the following to the module (assigned in the ModuleLoad procedure).  Or, if that is all you need, just use these by themselves:

        `diff/K1`  := ex -> K4(ex)*diff(ex,_rest);
        `diff/K2`  := ex -> K1(ex)*diff(ex,_rest);
        `diff/K3`  := ex -> K2(ex)*diff(ex,_rest);
        `diff/K4`  := ex -> K3(ex)*diff(ex,_rest);

If you put them in the module, you'll also need to declare them as global, similar to the evalf extensions.

@Alejandro Jakubi  A rooted vector is just that, a single vector, not a vector field.  The position is fixed. Consequently, the symbol phi (or r or z) has no intrinsic meaning [to Maple] as elements of the vector components (this is different from a vector field).  Phi is just a symbol that happens to coincide with the name of a coordinate. 

Consider a vector in cylindrical coordinates rooted at [r,0,z].  Because the angle is 0, when we translate to cartesian coordinates, the components of the translated vector do not change.  That is, if the components of the cylindrical unit vectors are, say, [a,b,c], then the components of the cartesian unit vectors are also [a,b,c]. In this case, a=3*cos(phi), b=-2*r, and c=5.  The result is correct.  The confusion comes from assuming that the phi in the vector components corresponds to the value of the angle of the position (root). Maple doesn't make this association. I suppose it could be changed to do so, but that would allow some interesting specifications. 

For example, suppose the root position was assigned [2*r, 0, 0] in cylindrical coordinates.  What, then, is the radius of the root?  r?  2*r? 2^infinity?

@Alejandro Jakubi  A rooted vector is just that, a single vector, not a vector field.  The position is fixed. Consequently, the symbol phi (or r or z) has no intrinsic meaning [to Maple] as elements of the vector components (this is different from a vector field).  Phi is just a symbol that happens to coincide with the name of a coordinate. 

Consider a vector in cylindrical coordinates rooted at [r,0,z].  Because the angle is 0, when we translate to cartesian coordinates, the components of the translated vector do not change.  That is, if the components of the cylindrical unit vectors are, say, [a,b,c], then the components of the cartesian unit vectors are also [a,b,c]. In this case, a=3*cos(phi), b=-2*r, and c=5.  The result is correct.  The confusion comes from assuming that the phi in the vector components corresponds to the value of the angle of the position (root). Maple doesn't make this association. I suppose it could be changed to do so, but that would allow some interesting specifications. 

For example, suppose the root position was assigned [2*r, 0, 0] in cylindrical coordinates.  What, then, is the radius of the root?  r?  2*r? 2^infinity?

@Alejandro Jakubi The confusion is understandable, as, I think, is the operation.  With a vector field it is necessary to relate the components of a vector to the position of the vector.  That is done via the coordinate names.  For example, in cylindrical coordinates with [r,theta,z], the symbol r in the expression for a field vector corresponds to the value of the radius at the position.

With a rooted vector it is not necessary to relate the components in the vector to the position, rather they are specified independently. As such, Maple does not interpret coordinate names in either the base or the vector names in a special way.  Consequently, the phi in 3*cos(phi) in your example does not necessarily correspond to the angle component of the position. 

@Alejandro Jakubi The confusion is understandable, as, I think, is the operation.  With a vector field it is necessary to relate the components of a vector to the position of the vector.  That is done via the coordinate names.  For example, in cylindrical coordinates with [r,theta,z], the symbol r in the expression for a field vector corresponds to the value of the radius at the position.

With a rooted vector it is not necessary to relate the components in the vector to the position, rather they are specified independently. As such, Maple does not interpret coordinate names in either the base or the vector names in a special way.  Consequently, the phi in 3*cos(phi) in your example does not necessarily correspond to the angle component of the position. 

I'm curious as to the etymology.  Where did the "French" come from?  Is that an American usage?

First 79 80 81 82 83 84 85 Last Page 81 of 195