Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are answers submitted by Joe Riel

:: is the type testing operator (at least in this context).  'w' is not a type, unless have created a type w, which can be done with ?TypeTools or by assigning to `type/w` (the former method is preferred). Hmm. Maybe the issue you are having is that the second if function has forward-quotes around it rather than back-quotes, as the first does.  Back-quotes are needed.

This is doable, at least on Linux, I'm not sure about Windows. However, it may not be the best way to go.  Rather than using the Optimization template directly, I'd consider extracting the code you need from it to do whatever computations are necessary, putting them in a Maple script, and calling it from command line Maple (cmaple in Windows).  That will be faster and cleaner since you won't have to interface with the GUI.  

To execute command line maple from a script, use

cmaple some_maple_script.mpl

Of course, cmaple needs to be in the PATH. 

The xml was missing some tags.  Not sure I restored it properly, but it opens now and is usable. 

Optimal_Portfolio_C.mw

It would be helpful to upload the worksheet (green arrow), or paste the code into a text region so it can be copied. Note that you should probably have used Pi rather than pi.

Connect the revolute joint to the tip of a rigid body frame.  Change the orientation of the tip of that frame, either by using Euler angles or a rotation Matrix.

There are several ways to handle this. A useful technique is to separate the grading data from the algorithm that computes the grade. Here is one way to do that---a bit overkill for this task, but maybe it will give you some ideas.  An Array of records stores the grading data.  Note, by the way, that there is a bug in your routine: try entering 100.

Marks := module()
export ModuleApply;
local  Grades;

    Grades := Array(1..5
                    , [ NULL
                        , Record['packed']('upperbound' = 40,  'grade' = "Fail")
                        , Record['packed']('upperbound' = 50,  'grade' = "Third Class")
                        , Record['packed']('upperbound' = 60,  'grade' = "Lower Second Class")
                        , Record['packed']('upperbound' = 70,  'grade' = "Upper Second Class")
                        , Record['packed']('upperbound' = 100, 'grade' = "First Class")
                      ]);

    ModuleApply := proc(mark :: positive)
    local i,rec,threshold;

        for i to upperbound(Grades) do
            rec := Grades[i];
            threshold := rec:-upperbound;
            if mark < threshold then
                printf("%s%s: %a\n"
                       , rec:-grade
                       , `if`(threshold-mark < 3
                              , " (borderline)"
                              , ""
                             )
                       , mark
                      );
                return NULL;
            end if;
        end do;
        printf("Obviously cheating: %a\n", mark);
    end proc;

end module:

Another issue is that the declaration of the parameters is wrong.  As given, only parameter c is type-checked.  You want

proc( a :: positive, b :: positive, c :: positive ) ... end proc

Note that this declaration won't allow, say, IsTriange(1,2,Pi), since Pi is not considered numeric; whether you want to allow that is up to you.  If you do, you might declare them as type realcons, then inside the procedure convert them to floats with evalf, check that they are positive, then check that the longest is shorter than the sum of the other two.

Maple's relation operators are nonassociative, so your condition is not syntactically correct. You could express that as 0 < m and m <= 39.99, however, that is neither necessary nor desirable.  Well, probably not desirable.  Despite the given table, you are better off considering any value less than 40 as a fail.  Otherwise a value such as 39.995 leads to an indeterminate condition.  It could be handled as an error, but that seems a poor choice.  

I'd so something like

Grade := proc(mark :: nonnegative)
   if mark < 40 then return (mark, "fail");
   elif mark < 50 then return (mark "3rd");
   ...
  end if;
end proc:

Note that the single argument is declared as nonnegative.  Consequently, calling it with, say, Grade("hello") will return an appropriate error message. 

You can do this with ?VolumeOfRevolution. For example

with(Student[Calculus1]):
y := sqrt(r^2-x^2):
a := int(y, x=-r..r) assuming r>0;
                            1  2   
                            - r  Pi
                            2      
v := VolumeOfRevolution(y,x=-r..r);
                            4  3   
                            - r  Pi
                            3      
solve({a=A,v=V},{V,r},Explicit);
   /           (1/2)       (1/2)         (1/2)       (1/2)\   
   |      8 A 2      (Pi A)             2      (Pi A)     |   
  < V = - ----------------------, r = - ------------------ >,
   |               3 Pi                         Pi        |   
   \                                                      /   

     /         (1/2)       (1/2)       (1/2)       (1/2)\
     |    8 A 2      (Pi A)           2      (Pi A)     |
    < V = ----------------------, r = ------------------ >
     |             3 Pi                       Pi        |
     \                                                  /

Click the component in the MapleSim editor, to view its parameters. In the parameter inspector there is an Advanced Variables Setting section.  It lists the unresolved override, Q[mistura].  Click the garbage can icon adjacent to it to revert it.  You should now be able to simulate with no warnings.

Let eqs be your set of equations.  Then do

eqs1 := subsindets(eqs, indexed, convert, symbol):

pass that set to the RealRootCounting.  To convert the solution back you can do

subsindets(sol, symbol, parse);

You can do this using the Iterator package available in the Application Center

s := hashmset:-new( [ a, 4 ], [ c,3 ] );
S := hashmset:-entries(s):
with(Iterator):
iter := MixedRadixTuples([seq(e[2]+1, e=S)]
                         , transformer = ( V -> {seq}(`if`(V[i]=0
                                                           , NULL
                                                           , [op([i,1],S),V[i]]
                                                          )
                                                      , i=1..upperbound(V)))
                        ):
seq(v, v=iter);
     {}, {[c, 1]}, {[c, 2]}, {[c, 3]}, {[a, 1]}, {[a, 1], [c, 1]}, {[a, 1], [c, 2]},
    {[a, 1], [c, 3]}, {[a, 2]}, {[a, 2], [c, 1]}, {[a, 2], [c, 2]},
    {[a, 2], [c, 3]}, {[a, 3]}, {[a, 3], [c, 1]}, {[a, 3], [c, 2]},
    {[a, 3], [c, 3]}, {[a, 4]}, {[a, 4], [c, 1]}, {[a, 4], [c, 2]},
    {[a, 4], [c, 3]}


plot([seq([i,a[i]], i=0..100);

Be aware that ?length uses a naive computation that doesn't account for common terms. For example

(**) L := [seq(1..100)]:  
(**) length(L);
                                                         295

(**) length([L$100]);
                                                        29603

The "actual" word length of that is significantly smaller, around  300.

Because continuity was not specified

 L:=[f(-6)=2400, f(-4)=432, f(-3)=120, f(-2)=16, f(-1)=0, f(0)=0, f(1)=-8, f(2)=0]:
 f := unapply(piecewise(seq('x=op(lhs(eq)),rhs(eq)', eq=L), x), 0):

Actually, the clever way to do this is

f := ()->0:
assign(op(eval(L,1)));



First 33 34 35 36 37 38 39 Last Page 35 of 114