acer

32400 Reputation

29 Badges

19 years, 344 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This is not the most efficient, but is simple to use.
 

NULL

c-s > (w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s);

(w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s) < c-s

(w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s) > c-s;

c-s < (w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s)

c-s > P[A]*P[B]*(p-s);

P[A]*P[B]*(p-s) < c-s

P[A]*P[B]*(p-s) > c-s;

c-s < P[A]*P[B]*(p-s)

F1 := (w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s)-c+s;

(w+u-s)*(-P[A]*P[B]+P[B])+P[A]*(p-s)-c+s

F2 := P[A]*P[B]*(p-s)-c+s;

P[A]*P[B]*(p-s)-c+s

c1 := solve(F1, P[A]);

(s*P[B]-u*P[B]-w*P[B]+c-s)/(s*P[B]-u*P[B]-w*P[B]+p-s)

c2 := solve(F2, P[A]);

(c-s)/(P[B]*(p-s))

wt := 4;

4

2

2

1

7

cc1 := eval(c1, {c = ct, p = pt, s = st, u = ut, w = wt});

(-5*P[B]+1)/(-5*P[B]+6)

cc2 := eval(c2, {c = ct, p = pt, s = st, u = ut, w = wt});

(1/6)/P[B]

CC1 := piecewise(cc1 <= P[B], cc1, undefined)

piecewise((-5*P[B]+1)/(-5*P[B]+6) <= P[B], (-5*P[B]+1)/(-5*P[B]+6), undefined)

CC2 := piecewise(cc2 <= P[B], cc2, undefined)

piecewise((1/6)/P[B] <= P[B], (1/6)/P[B], undefined)

plot({CC1, CC2, P[B]}, P[B] = 0 .. .50, P[A] = 0 .. .50)

NULL

``


 

Download equilibrium_alt.mw

(Thanks to vv for Body2).

I think that the comments and a few variants might help explain some things to the OP. (I have removed output, for upload here.)

Download rotate3d.mw

Bring the multiplication by `s` inside the `mod` call, in the loop in `Elgamal`.

Don't call `proc3` each time you enter the loop in Elgamal`. Instead compute it once at  the start of `Elgamal`, and assign to a local (which you'll use inside the loop). Combined with the above, that brings it down to about 2 seconds, on a fast machine.

Use &^ instead of ^ inside the `mod` in `Elgamal`. (I've told you this more than three times now, in various questions and duplicates of questions you've made recently.) Combined with the above, that brings it down to about 0.2 seconds on a fast machine.


 

restart;

Elgamal := proc (ciphy::list, hkt, p, a, b)
               local i, icdarray, s, p3, q, x;
                 #msolve(a ^ x = b, p);
                 #p3 := subsindets(eval(x, msolve(a ^ x = b, p)),name,0);
                 p3 := proc3(a, b, p);
                 icdarray := Array(1 .. nops(ciphy));
                   for i from 1 to nops(ciphy) do
                   s := ciphy[i];
                   q := `mod`(s / hkt &^ p3, p);
                   icdarray[i] := q;
                   end do;
                   return convert(convert(icdarray,list),bytes);
                  end proc:

proc3 := proc (alpha, beta, p)
                   local k, R, i, j, N, A, t;
               description "baby step giant step procedure";
                 N := floor(sqrt(p-1))+1;
                 A := Array(0 .. N);
                 for j from 0 to N do
                 A[j] := `mod`(alpha&^j, p);
                end do;
          for i from 0 to N do
             t := `mod`( ( beta * alpha &^ (-N*i) ), p);
            for k from 0 to N do
            if t = A[k]
           then return k+N*i;
         end if;
         end do;
           end do;
         end proc:

header := 9681348997:

ciphertext:= [12432485341, 2579085006, 13736574369, 4105371047, 9573017222,  7824534168, 10017411248, 13292180343, 2356887993,
 9573017222, 10017411248, 13765667419, 9795214235, 10017411248, 2801282019, 608404939, 4105371047, 13765667419, 11572790339,
 13765667419, 11765894302, 10017411248, 13765667419, 4549765073, 10017411248, 13736574369, 2579085006, 4549765073, 10017411248,
 4549765073, 13765667419, 2801282019, 830601952, 4105371047, 10017411248, 7824534168, 13765667419, 13736574369, 2801282019,
 7824534168, 10017411248, 830601952, 9573017222, 4327568060, 13765667419, 6076051114, 8268928194, 13292180343, 10017411248,
 7824534168, 386207926, 2801282019, 4105371047, 2579085006, 6076051114, 608404939, 13765667419, 6076051114, 830601952,
 13765667419, 4105371047, 11765894302, 10017411248, 13765667419, 13292180343, 13736574369, 10017411248, 608404939, 10017411248,
 7824534168, 2134690980, 13765667419, 4105371047, 11765894302, 2801282019, 4105371047, 13765667419, 2579085006, 608404939,
 13292180343, 11543697289, 2579085006, 7824534168, 10017411248, 4549765073, 13765667419, 4994159099, 5853854101, 6076051114,
 830601952, 4327568060, 6076051114, 5853854101, 10017411248, 7824534168, 13765667419, 4105371047, 6076051114, 13765667419,
 9573017222, 13292180343, 10017411248, 13765667419, 4105371047, 11765894302, 10017411248, 13765667419, 5853854101, 6076051114,
 7824534168, 4549765073, 13765667419, 11572790339, 13765667419, 4105371047, 11765894302, 2801282019, 4105371047, 13765667419,
 4105371047, 11765894302, 10017411248, 13765667419, 4327568060, 2801282019, 608404939, 4549765073, 13292180343, 13736574369,
 2801282019, 11543697289, 10017411248, 13765667419, 5853854101, 2801282019, 13292180343, 13765667419, 11765894302, 6076051114,
 7824534168, 7824534168, 2579085006, 8268928194, 4327568060, 2134690980, 13765667419, 11543697289, 7824534168, 10017411248,
 13736574369, 2579085006, 11543697289, 2579085006, 4105371047, 6076051114, 9573017222, 13292180343, 2385981043, 13765667419,
 3245676045, 9573017222, 2801282019, 2579085006, 608404939, 4105371047, 6105144164, 13765667419, 5853854101, 11765894302,
 10017411248, 608404939, 13765667419, 9573017222, 13292180343, 10017411248, 4549765073, 13765667419, 4105371047, 6076051114,
 13765667419, 4549765073, 10017411248, 13292180343, 13736574369, 7824534168, 2579085006, 8268928194, 10017411248, 13765667419,
 4105371047, 11765894302, 10017411248, 13765667419, 6076051114, 13736574369, 13736574369, 2801282019, 13292180343, 2579085006,
 6076051114, 608404939, 2801282019, 4327568060, 13765667419, 386207926, 2579085006, 4327568060, 4327568060, 2801282019,
 6298248127, 10017411248, 13765667419, 4105371047, 11765894302, 7824534168, 6076051114, 9573017222, 6298248127, 11765894302,
 13765667419, 5853854101, 11765894302, 2579085006, 13736574369, 11765894302, 13765667419, 4105371047, 11765894302, 10017411248,
 2134690980, 13765667419, 11543697289, 2801282019, 13292180343, 13292180343, 10017411248, 4549765073, 6105144164, 13765667419,
 9795214235, 10017411248, 2801282019, 608404939, 4105371047, 13765667419, 830601952, 10017411248, 386207926, 10017411248,
 7824534168, 11572790339, 7824534168, 2579085006, 4549765073, 4549765073, 10017411248, 608404939, 13765667419, 2801282019,
 608404939, 4549765073, 13765667419, 4105371047, 9573017222, 9795214235, 8268928194, 4327568060, 10017411248, 4549765073,
 6076051114, 5853854101, 608404939, 2385981043, 13765667419, 4994159099, 5853854101, 6076051114, 830601952, 4327568060,
 6076051114, 5853854101, 10017411248, 7824534168, 13765667419, 5853854101, 2801282019, 13292180343, 13765667419, 2801282019,
 13765667419, 4105371047, 6076051114, 9573017222, 7824534168, 2579085006, 13292180343, 4105371047, 6105144164, 13765667419,
 4105371047, 11765894302, 10017411248, 13765667419, 830601952, 2579085006, 7824534168, 13292180343, 4105371047, 13765667419,
 10017411248, 386207926, 10017411248, 7824534168, 13765667419, 13292180343, 10017411248, 10017411248, 608404939, 13765667419,
 6076051114, 608404939, 13765667419, 4105371047, 11765894302, 10017411248, 13765667419, 5438553125, 2579085006, 13292180343,
 13736574369, 5853854101, 6076051114, 7824534168, 4327568060, 4549765073, 2385981043, 13765667419, 4994159099, 6076051114,
 9573017222, 7824534168, 2579085006, 13292180343, 4105371047, 6105144164,13765667419, 8713322220, 2579085006, 608404939,
 13736574369, 10017411248, 5853854101, 2579085006, 608404939, 4549765073, 13765667419, 11765894302, 2801282019, 4549765073,
 13765667419, 4549765073, 10017411248, 13736574369, 2579085006, 4549765073, 10017411248, 4549765073, 6105144164, 13765667419,
 9795214235, 10017411248, 2801282019, 608404939, 4105371047, 13765667419, 8075824231, 2579085006, 4549765073, 2579085006,
 6076051114, 4105371047, 8075824231, 2385981043]:

 

Elgamal( ciphertext, header, 14654455471, 457454, 13954306945);

"Picturesque meant - he decided after careful observation of the scenery that inspired Twoflower to use the word - that the landscape was horribly precipitous. Quaint, when used to describe the occasional village through which they passed, meant fever-ridden and tumbledown. Twoflower was a tourist, the first ever seen on the Discworld. Tourist, Rincewind had decided, meant 'idiot'."

 


 

Download elgamal2.mw

Are you asking how you can make sure that you're always invoking the command that is not in the plots package? If so then just call it using the global name, ie.

:-changecoords

The name `s` appears in eqset. Is that not the same global name as you're trying to use for the do-loop?

When you call dsolve (numeric) you can pass it the additonal option output=listprocedure. If you assign the result to sol then the following allows you to extract the functions individually. Eg,

sF__A := eval(F__A(V), sol):
After which you can call,
sF__A(0.1e-4);
which should then return the single numeric value, say, HFloat(3.498873118476744e-6).
restart:

targ:=(sin(t)*sin(t/n)-cos(t)*cos(t/n)) /( sin(t)*cos(t/n)+cos(t)*sin(t/n));

                         sin(t) sin(t/n) - cos(t) cos(t/n)
                 targ := ---------------------------------
                         sin(t) cos(t/n) + cos(t) sin(t/n)

res:=(cos(t/n)*sin(t/n)-sin(t)*cos(t))/(cos(t/n)^2-cos(t)^2);

                         cos(t/n) sin(t/n) - sin(t) cos(t)
                  res := ---------------------------------
                                       2         2
                               cos(t/n)  - cos(t)

simplify(targ-res);                                                                 

                                        0

normal(expand(trigsubs(numer(combine(res)))[1]
              /trigsubs(denom(combine(res)))[1]));

                        sin(t) sin(t/n) - cos(t) cos(t/n)
                        ---------------------------------
                        sin(t) cos(t/n) + cos(t) sin(t/n)

% - targ;

                                       0

alt:=convert(trigsubs(numer(combine(res)))[1]
             /trigsubs(denom(combine(res)))[1],cot);

                                     t (n + 1)
                         alt := -cot(---------)
                                         n

simplify(targ-alt);

                                       0


 

restart;

with(plots):
with(plottools):

L:=[cos(0.25*t)+0.2*sin(0.25*t),
    sin(0.25*t)-0.2*cos(0.25*t),
    0.0];

ff1:=unapply('display'(['line'([0, 0, 0],L,colour=red,
                               thickness=4)]),
             t):

animate(ff1,[t],t=0..5,frames=100);

animate(display@line,
        [[0,0,0],L,colour=red,thickness=4],
        t=0..5,frames=100);

animate(display,
        ['line'([0,0,0],L,colour=red,thickness=4)],
        t=0..5,frames=100);

ffp:=unapply('display'('point'(L,colour=red,
                               symbolsize=50,
                               symbol=solidsphere)),
             t):

animate(ffp,[t],t=0..5,frames=100);

animate(display@point,
        [L,colour=red,symbolsize=50,
         symbol=solidsphere],
        t=0..5,frames=100);

animate(display,
        ['point'(L,colour=red,symbolsize=50,
                 symbol=solidsphere)],
        t=0..5,frames=100);

 


 

Download delayedevaluation.mw

I suppose that you might be required to use a loop, or not use a system command like `msolve` for this task.


 

restart;

# With a loop and a table.

F:=proc(p::posint)
     local x,T;
     T:=table([]);
     for x from 0 to p-1 do
       if (x^2 = -1) mod p then
         T[x]:=x;
       end if;
     end do;
     return entries(T,':-nolist');
   end proc:

F(113);

15, 98

# Using `seq` and `if` instead

G:=proc(p::posint)
     seq(`if`(modp(x^2=-1,p),x,NULL),x=0..p-1);
   end proc:

G(113);

15, 98

gen:=proc(i::posint, f)
       local res;
       res:=[f(i)];
       if res=[] then
         return NULL;
       else
         return [i,res];
       end if;
     end proc:

seq(gen(i, F), i=1..20);

[1, [0]], [2, [1]], [5, [2, 3]], [10, [3, 7]], [13, [5, 8]], [17, [4, 13]]

seq(gen(i, G), i=1..20);

[1, [0]], [2, [1]], [5, [2, 3]], [10, [3, 7]], [13, [5, 8]], [17, [4, 13]]

 


 

Download modp.mw

For this example, I got this:

restart;

a:=21*arccos(RootOf(448*_Z^7+192*_Z^6-784*_Z^5-288*_Z^4
                    +392*_Z^3+108*_Z^2-49*_Z-6, index = 2))/Pi:

b:=-(21*I)*ln(RootOf(7*_Z^14+6*_Z^13+6*_Z+7, index = 2))/Pi:

evala(convert(convert(a-b,RootOf),arccos));
                                      0
Or, as it happens,
simplify(convert(convert(a-b,RootOf),arccos));
                               0

Is your problem that any rows of the data Array which have not yet been filled with data wil make the plots (pointplot, or plot of the fitted curve) get extended down to (at the point [0,0])?

Here's a rough idea. If you want [0,0] to actually be a valid datum then enter the values as say 0.0 instead of exact 0 (the default).

augment.mw

There are other ways to go about it. Eg, perhaps using an empty string as the default fill.

 

I'm not entirely sure what you are trying to do, so this is a guess.

A DataTable component has the name of some rtable (Matrix, say) as one of it's properties. Whenever you edit the entries in the DataTable component the associated Matrix gets the new values, automatically. So a Button's Action code could simply pass the data to the LinearFit command (using data from either the whole Matrix, or just the first N rows of it, etc).

@hitstudent If L is a list of inequalities (each with dimensions on the left that match those on the right), then you could try,

map(is,map2(map,convert,combine(L,':-units'),':-unit_free'));

For example,

Diameter[rør] := [273.05*Unit('mm'), 219.08*Unit('mm'),
 168.28*Unit('mm'), 114.3*Unit('mm'),
 273.05*Unit('mm'), 219.08*Unit('mm'),
 1066.8*Unit('mm'), 60.33*Unit('mm'),
 219.08*Unit('mm'), 168.28*Unit('mm'),
 168.28*Unit('mm'), 141.3*Unit('mm'),
 168.28*Unit('mm'), 114.3*Unit('mm'),
 114.3*Unit('mm'), 168.28*Unit('mm'),
 168.28*Unit('mm')]:

tm := 8.982892831*Unit('mm'),
4.189790007*Unit('mm'),.913902969*Unit('mm'),
3.620745836*Unit('mm'),4.482892831*Unit('mm'),
4.189790007*Unit('mm'),8.793627806*Unit('mm'),
3.327643012*Unit('mm'),4.189790007*Unit('mm'),
3.913902969*Unit('mm'),3.913902969*Unit('mm'),
3.767378711*Unit('mm'),3.913902969*Unit('mm'),
3.620745836*Unit('mm'),3.620745836*Unit('mm'),
3.913902969*Unit('mm'),3.913902969*Unit('mm'):

L:=[seq(tm[i] < (1/6)*Diameter[rør][i],
        i = 1 .. min(nops([tm]),nops(Diameter[rør])))]:

map(is,map2(map,convert,combine(L,':-units'),':-unit_free'));
                                                             
   [true, true, true, true, true, true, true, true, true,
    true, true, true, true, true, true, true, true]

Here's all that I could recover from one of them. The uploaded file ended in an invalid Output element. I deleted that, and then closed off (in this order) the outstanding opened Input, Group, Presentation-Block, Section, Section, and Worksheet elements.

Bygninger_energibehov.zip

[edited] And here is what I could recover from the other one. Only two sections now. If there was a third, then I could not see it. This one ended with what appeared to be a corrupted Input element (though very large...). I deleted that and it's parent Presentation-Block (then empty) and then closed off a few Sections and the Worksheet element.

Foringsveje_og_indeklina.zip

 

If you are using only Maple 17 (as indicated by your previous question) then you could use the numtheory[mlog] command.

restart;

kernelopts(version);

     Maple 17.02, X86 64 WINDOWS, Sep 5 2013, Build ID 872941

a := 3:
b := 64:
n := 137:

numtheory[mlog](b, a, n);

                            60

Do you specifically want the smallest solution, or all those less than n? Eg.

restart;
a := 5:
b := 64:
n := 1117:
numtheory[mlog](b, a, n);
                              166
raw := eval(x,msolve( a&^x = b, n ));
                         166 + 372 _Z1
cond := isolve( {raw <= n, raw >=0}, _dummy );
                {_Z1 = 0}, {_Z1 = 1}, {_Z1 = 2}
seq(eval(raw, c), c={cond});
                         166, 538, 910
First 200 201 202 203 204 205 206 Last Page 202 of 336