Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The following does what you want. The technique is to declare the parameters as ?uneval, and then evaluate them inside the body of the procedure.

f := proc(A::uneval, B::uneval)
local a,b,La,Lb;
    a := convert(A,string);
    b := convert(B,string);
    La := eval(A);
    Lb := eval(B);
    return a = La, b = Lb;
end proc:

A1 := [1,2]:
B1 := [3,4]:

f(A1,B1);
                         "A1" = [1, 2], "B1" = [3, 4]

 

It isn't apparent that a symbolic solution can be found; the equations correspond to a set of quartic polynomials.

You can always use backquotes (also known as left single quotes) to form a Maple ?name from non-alphabetic characters:

`Y*` := whatever;

You could manually restructure the sum:

H:=proc(y,a,b) local z;
    z := piecewise((y>0), a,b);
    z + y;
end proc:
prep2trans(H);
proc(y, a, b)
local z;
    z := (if 0 < y then a else b end if); z + y
end proc

As Acer points out, op(0,.) is the way to go. One might imagine that ?unapply could be used here.  That is, 

unapply(f(x),x);
                                    x -> f(x)

could return f, rather than a procedure.  Just thinking

Note that eval isn't doing anything special here, other than substituting and evaluating an expression.  In the first case, g(u) becomes proc() ll end(u), which evaluates to ll.  In the second, g(u) becomes ll(u), and unless ll is assigned a procedure, it returns unevaluated.

 

Maple doesn't normally return x*x. One way that can happen is if one of the x's is an escaped local.  For example,

x * proc() local x; x; end proc();
                                 x*x

You might run the output through indets and see if the variables are independent:

indets(%);
                     {x, x}

That's a pretty good sign that that is what has happened.

This is known as the "money-changing problem".  See Wilf's "GeneratingFunctionology" for a discussion of solving it with generating functions (per Robert's approach). You can download an older edition of Wilf's book from his site, but I recommend purchasing the book, it is both informative and enjoyable.

By default, prime notation represents differention with respect to x, not t. You want to use the dot notation.  To do that, select the symbol, type Ctrl-Shift-" (the last charater is a double-quote) then type the appropriate number of dots (periods).

How do you plan to use this model?  That is, is it part of a larger simulation? 

One way to model simple hysteresis is with events in dsolve, see ?dsolve/events.  For example

evts := [ [ i(t) - ihys(t), ihys(t)=-ihys(t)]  ]:
dsys := { diff(i(t),t)=sin(t), i(0)=-1, ihys(0)=1/2 }:
integ := dsolve(dsys, numeric
                , 'events' = evts
                , 'discrete_variables' = [ ihys(t) ]
               ):
plots:-odeplot(integ, [[t,i(t)],[t,ihys(t)]]);

Modeling the continuous hysteresis of a B-H loop in ferromagnetic material is more challenging. A typical approach is to use the Jiles-Atherton equations

Specify the colors as a list:   color=[blue,green,red].  

Attach a "World Applied Force" block to the end and set its resolved frame to "outboard".  That sets the frame of the resolved force to that of the frame to which it is attached.  Then drive the z-input of the force block with the desired orthogonal force.

An amusing way, which mostly works, is

eval(eval({op(Ex)},G=(x->exp(x))),exp=1);

But y=0 does not solve the equation. 

 

Peter's method is nice.  Less nice, here, but useful in other applications, is to use the two-argument form of ?op.  The first argument specifies the operand, it may be an integer, a range, or a list of integers, with the final element allowed to be a range.  Here you would do

op([1,1,1,2],minimum[2])

First 48 49 50 51 52 53 54 Last Page 50 of 114