Joe Riel

9530 Reputation

23 Badges

20 years, 29 days

MaplePrimes Activity


These are answers submitted by Joe Riel

b[1] := b1:
b1_func := unapply(b[1]+t,t):
b1_func(x);
                                    b1 + x

b[1] := b2:
b1_func(x);
                                    b1 + x

Another approach, less efficient than nested seq's but possibly easier to comprehend, is to use nested loops and store the intermediate result in a table that you later convert to a set. To reduce the size I'll only save ordered pairs.

pairs := table():
cnt := 0:
for i from 100 to 110 do
    for j from i+1 to 110 do
        if igcd(i,j) = 1 then
            cnt := cnt+1;
            pairs[cnt] := [i,j];
        end if;
    end do;
end do:

convert(pairs, set);

I assume regexprep is your own procedure.  Why are you passing true/false to ArrayTools:-AllNonZero?

Followup: I'm slow today. I hadn't realize that was the output of FromMFile.  The problem there is that the Matlab local variable fi is a Maple reserved word. Change it, say to ffi.  That won't fix the other issues with this translation...

Maybe your expectation of what Eval does is incorrect?  Eval is an inert version of eval. Contrast

Eval(x,x=1);
                                                      x|
                                                       |x = 1

eval(x,x=1);
                                                         1


Oh, now I understand. You want to show the unevaluated version of your sin. First off, I don't believe that your technique will work, at least not if done at top-level.  The reason is that, at top-level, :-sin is the same as sin, so your assignment leads to an infinite recursion.  It will work if done inside a procedure or module.  Here I'll use the name Sin which avoid the issue.

Sin := proc(x)
    if x :: numeric then
        :-sin(x*Pi/180);
    else
        'procname'(x)
    end if;
end proc:

Eval(y=Sin(x), x=30);
                              (y = Sin(x))|
                                          |x = 30

value(%);
                                    y = 1/2

A disadvantage with this method is that it doesn't allow, say, Sin(44) to exist unevaluated.  An alternative is to leave Sin inert but extend value so that it know how to evaluate it.

restart;
`value/Sin` := x -> sin(x*Pi/180):
Eval(y = Sin(x), x=30);
                              (y = Sin(x))|
                                          |x = 30

value(%);
                                    y = 1/2

Sin(30);
                                    Sin(30)

value(%);
                                      1/2

Another possibility is to use %Sin as the inert version:

restart;
Sin := proc(x)
    if x :: realcons then
        :-sin(x*Pi/180);
    else
        'procname'(x)
    end if;
end proc:

Eval(y = %Sin(x), x=30);
                             (y = %Sin(x))|
                                           |x = 30

value(%);
                                    y = 1/2

That works because value converts %XXX to XXX

That method will not work.  The reason is that the ideal op-amp is modeled as one would by hand, that it, it impresses a virtual-short between its two input terminals.  The only possible solution for this circuit with that constraint (V+ = V-) is to have V+ = V-  = 0, which is not oscillatilng.

If you substitute the ideal op-amp with limited gain and set the voltages sources to something reasonable, and set an initial condition on the capacitor, you can see the output start to move, but the model will hit a singularity and terminate. Proving that that must be the case would make a nice exercise.

What you really want to use is a comparator rather than an op-amp.  I modeled one by using a VCVS driving a controlled commutating switch, with one pole connected to ground and the other to a positive supply.  The common terminal is the output.  That does oscillate.

Do you want the symbols (or names) from a particular expression, or all expressions in the worksheet?

The command for extracting symbols or names (or other types) from an expression is indets.  Check out its help page, it takes an optional second argument that specifies the type. 

Collecting names from the worksheet as a whole is a bit trickier. The commands of use are anames and unames.

Use the normal integrator and divide the result by the time. That will give an average power that is continuously updated.  You may need to avoid dividing by zero at t=0, that can be done in a few ways.

Another possibility is to make the time period a parameter and then use it to compute the average as well as set the period of the driving sources (assuming that there is a driving source that sets the period).

Are the z2, z3, etc, supposed to be unevaluated functions?  Or are the parentheses implicit multiplications that have gone bad?

Insert a break command in the else clause:

for D5d_counter from 1 to 1000 do
  increment := 0.1:
  D5d_incr := initial_D5d + increment:
  D5d_decr := initial_D5d - increment:
  energy_D5d_init := energy1d(initial_D5d);
  energy_D5d_incr:= energy1d(D5d_incr);
  energy_D5d_decr := energy1d(D5d_decr);
  #evalM(cat("plot(",convert(P[1],string), ",",convert(P[2],string), ", '+')"))
  #pointplot({[energy_D5d_init, initial_D5d]});
  if energy_D5d_incr > energy_D5d_init and energy_D5d_decr < energy_D5d_init then 
    initial_D5d := D5d_decr;
  elif  energy_D5d_incr < energy_D5d_init and energy_D5d_decr > energy_D5d_init then 
    initial_D5d := D5d_incr;
  else
    print("minima found");
    D5d_counter := 1000;
    break;  # early exit of loop
  fi;
  print(initial_D5d);
  D5d_counter;
end do;

Hmm. Now I see what you are doing.  The break command is better, but your method should work.  Are you sure the else clause is being executed?  Doe the "minima found" message print?

As Alec suggests, using member is the best approach for a one-off answer.  However, if you need to find the order of many entries, you might consider creating a table from the list:

L := [1,3,5,8,9]:
OrderL := table(L =~ [seq(1..nops(L))]):
A := Vector([2, 10, 5, 7]);
A[[1,3,4]];

You can automate this with


A[subsop(2=NULL,[seq(1..4)])];

It worked for me:
 

with(Logic):
expr := (...): # your expression, with &or; --> &or, &and; --> &and
Equivalent(expr, BooleanSimplify(expr));
                                        true

 

Are you using the correct inert and/or symbols?  Logic uses &and and &or, however, your code includes the trailing semicolons, i.e., special html/mathml characters.

Increase Digits:

restart;
LF := (1/1658880)*(1-p)^12*p^6*lambda^20/((exp(lambda))^6*(1-1/exp(lambda))^6):
Digits := 20:
Optimization:-Maximize(LF, p = .1 .. .9, lambda = 1 .. 5, maximize);
        [.47572216053128925615e-9, [p = .33333333140756364298, lambda = 3.1970590827878406950]]

The most likely cause is that the file is not located in the directory in which Maple is running. Use the currentdir command to find out from where it reads a file.

Use parse or sscanf to parse the string.

The pick procedure can be improved by inlining it:

pick := proc()
option inline;
    rnd(6, 52, 6) + 1;
end proc:

Rather than explicity tracking the cards that were picked, you could use the following technique, which maps the first valid card (1..4) to card 1, then looks for values 2..4, etc.

fouraces4 := proc(n)
local cnt,card,num;
    cnt := 0;
    to n do
        num := 0;
        do
            card := pick();
            if card > 4 then
                break;
            elif card <= num then
                next;
            elif num = 3 then
                cnt := cnt+1;
                break;
            else
                num := num+1;
            end if;
        end do;
    end do;
    return cnt;
end proc:
First 80 81 82 83 84 85 86 Last Page 82 of 114