acer

12950 Reputation

29 Badges

11 years, 148 days

On google groups. (comp.soft-sys.math.maple and sci.math.symbolic)

On stackoverflow.

On math.stackexchange.com.

MaplePrimes Activity


These are answers submitted by acer

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

Are you saying that you want to know how you could convert an ascii text string into a number?

 

restart;

with(StringTools):

s := "  This is my string  !!&*# *%))%)  @_   1234567890":

s;

"  This is my string  !!&*# *%))%)  @_   1234567890"

map(convert,convert(s,bytes),string);

["32", "32", "84", "104", "105", "115", "32", "105", "115", "32", "109", "121", "32", "115", "116", "114", "105", "110", "103", "32", "32", "33", "33", "38", "42", "35", "32", "42", "37", "41", "41", "37", "41", "32", "32", "64", "95", "32", "32", "32", "49", "50", "51", "52", "53", "54", "55", "56", "57", "48"]

new := cat(op(map(SubstituteAll,map(PadLeft,%,3)," ","0")));

"032032084104105115032105115032109121032115116114105110103032032033033038042035032042037041041037041032032064095032032032049050051052053054055056057048"

convert(map(parse,[LengthSplit(new,3)]),bytes);

"  This is my string  !!&*# *%))%)  @_   1234567890"

# Note that string `new` has a leading 0. (It could have
# two of them.) You'll need to deal with that possibility,
# when trying to convert back from `num` the integer
# obtained by parsing `new`.
#

num := parse(new);

32032084104105115032105115032109121032115116114105110103032032033033038042035032042037041041037041032032064095032032032049050051052053054055056057048

cand := convert(num,string);

"32032084104105115032105115032109121032115116114105110103032032033033038042035032042037041041037041032032064095032032032049050051052053054055056057048"

length(cand); # not a multiple of three, as we'll see...
r := irem(length(cand),3);

149

2

cat(seq("0",i=1..`if`(r=0,0,3-r)));

"0"

cat(seq("0",i=1..`if`(r=0,0,3-r)), cand);

"032032084104105115032105115032109121032115116114105110103032032033033038042035032042037041041037041032032064095032032032049050051052053054055056057048"

convert(map(parse,[LengthSplit(new,3)]),bytes);

"  This is my string  !!&*# *%))%)  @_   1234567890"

kernelopts(version);

`Maple 17.02, X86 64 LINUX, Sep 5 2013, Build ID 872941`

 


 

Download textnum.mw

I might reach for the Spline or ArrayInterpolation commands from the CurveFitting package, before I'd go for BSplineCurve.

You should give serious consideration to how accurate you expect the result to be. Striving for unreasonable accuracy will likely cause problems (if only in efficiency, if evalf/Int slows down).

The use of ArrayInterpolation that I include in the attached sheet is not optimized for speed. And I'm deliberately trying to poke at my contrived example, to see how accurate I can get without making evalf/Int stall or fail.

You can adjust the degree of the piecewise interpolation (spline, or otherwise).

Note that some examples can induce roundoff error while computing the interpolant. Increasing working precision is possible, but will affect performance.

Perhaps you don't desire more than just a few "correct" digits?

spline_int2.mw

If you are using Maple 2016 then you could try the undocumented
command Worksheet:-WorksheetToMapleText .

It will accept a file name as its argument (as a string). For example,

Worksheet:-WorksheetToMapleText( filenm );

where filenm is a quoted string such as, say, "C:\\\\TEMP\\foo.txt" on MS-Windows, etc.

It appears to return a string containing plaintext 1-D Maple Notation versions of input commands in the original. You could programmatically export such a string to a plaintext file using the FileTools:-Text package.

It appears to support both 1-D and 2-D input, as well as both Execution Groups in .mw format Worksheets and Document Blocks in .mw format Documents. It also seems to handle comments beginning with #. It also seems to support code in the .mw file's StartUp Region.

It does not seem to currently handle GUI Tables whose cells themseleves contain Execution Groups, except by placing such inputs into # comments, and in doing do it does not respect the Table property of execution-by-row versus execution-by-column.

docexample.mw

WToMapleT.mw

If you really want line numbers and the style of output that `showstat` produces then you could try using the procedure `p` in the attached worksheet instead. It seems to do what you want in my Maple 2015.2 and Maple 2016.0. (I've only tried it on 64bit Windows 7...)

showstat_writeto.mw

If you don't really need the line numbers, but you do want `printf` style output, then you could try the following instead, to get the body of procedure (assigned to `F`) into the file:

interface('prettyprint'=1):
interface('verboseproc'=3):
writeto(whateveryourtargetlocation)
print(F);
writeto('terminal'):
1 2 3 4 5 6 7 Last Page 1 of 135