DuncanA

703 Reputation

8 Badges

18 years, 226 days

MaplePrimes Activity


These are replies submitted by DuncanA

@Axel Vogt by my estimate there are three 'unfair' cases

(1) a<>0, n=0. Maple automatically reduces this to t:=1

t:=5^(-0)*2^0;
     t := 1

(2) a=0, n=0. Maple automatically reduces this to t:=1

t:=0^(-0)*2^0;
     t := 1

(3) a=0, n indeterminate. This can be handled by introducing another rule to be applied before the generic rule

t:=0^(-n)*2^n;
      (-n) n
 t := 0   2 
 
applyrule([0^(-n)*b::integer^n=0^(-n)*b^n, a::integer^(-n)*b::integer^(n)=(b/a)^(n)], t);
      (-n) n
      0   2 

@Axel Vogt by my estimate there are three 'unfair' cases

(1) a<>0, n=0. Maple automatically reduces this to t:=1

t:=5^(-0)*2^0;
     t := 1

(2) a=0, n=0. Maple automatically reduces this to t:=1

t:=0^(-0)*2^0;
     t := 1

(3) a=0, n indeterminate. This can be handled by introducing another rule to be applied before the generic rule

t:=0^(-n)*2^n;
      (-n) n
 t := 0   2 
 
applyrule([0^(-n)*b::integer^n=0^(-n)*b^n, a::integer^(-n)*b::integer^(n)=(b/a)^(n)], t);
      (-n) n
      0   2 

@Alec Mihailovs The quick solution to this problem, if someone chooses to use minpol, is to trap the error case and replace the line

mul(x-L[i], i = 1 .. nops([L]))

with the following if statement:

if nops([L])=1 then
    x-L
else
    mul(x-L[i], i = 1 .. nops([L]))
end if;

@Alec Mihailovs The quick solution to this problem, if someone chooses to use minpol, is to trap the error case and replace the line

mul(x-L[i], i = 1 .. nops([L]))

with the following if statement:

if nops([L])=1 then
    x-L
else
    mul(x-L[i], i = 1 .. nops([L]))
end if;

@kelvinlee The problem is the use of alias inside the minpol procedure. The help for alias  ?alias states that: "Aliases defined inside a procedure or other compound statement are not effective for resolving input matches in the body of that statement.  This is the case because the current statement is parsed in its entirety before the alias command is evaluated."

The alias only becomes effective after the first call to minpol.

Two options are

(1) Replace alias(alpha = RootOf(f(x))); with alpha := RootOf(f(x)); inside minpol. The output from minpol will then be correct, but confusing because it will contain several RootOf statements in the output. Although it will still simplify correctly. For example,

minpol(3);
/ 3 2\ / 3
| / 4 \ / 4 \ | | / 4 \
\x - RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1/ / \x - RootOf\_Z + _Z + 1/

2 \ /
/ 4 \ / 4 \ | |
- RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1/ - 1/ \x

3 \ / 3\
/ 4 \ / 4 \| | / 4 \ |
- RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1// \x - RootOf\_Z + _Z + 1/ /
Expand(%) mod 2;
4 3 2
x + x + x + x + 1

 

(2) Move f := x -> x^4+x+1; and alias(alpha = RootOf(f(x))); out of minpol to give

restart;
f := x -> x^4+x+1:
alias(alpha = RootOf(f(x))):
minpol := proc (n)
local m, beta, L, d, t;
m := degree(f(x));
beta := alpha^n;
beta := `mod`(Rem(beta, f(x), x), 2);
L := NULL;
for d to 2^m do
d;
t := `mod`(Powmod(beta, 2^d, f(x), x), 2);
L := L, t;
if t = beta then
break
end if;
end do;
mul(x-L[i], i = 1 .. nops([L]))
end proc:
minpol(3);
/ 3 2\ / 3 2 \ / 3 \ /
\x - alpha - alpha / \x - alpha - alpha - alpha - 1/ \x - alpha - alpha/ \x

3\
- alpha /
Expand(%) mod 2;
4 3 2
x + x + x + x + 1

 

@kelvinlee The problem is the use of alias inside the minpol procedure. The help for alias  ?alias states that: "Aliases defined inside a procedure or other compound statement are not effective for resolving input matches in the body of that statement.  This is the case because the current statement is parsed in its entirety before the alias command is evaluated."

The alias only becomes effective after the first call to minpol.

Two options are

(1) Replace alias(alpha = RootOf(f(x))); with alpha := RootOf(f(x)); inside minpol. The output from minpol will then be correct, but confusing because it will contain several RootOf statements in the output. Although it will still simplify correctly. For example,

minpol(3);
/ 3 2\ / 3
| / 4 \ / 4 \ | | / 4 \
\x - RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1/ / \x - RootOf\_Z + _Z + 1/

2 \ /
/ 4 \ / 4 \ | |
- RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1/ - 1/ \x

3 \ / 3\
/ 4 \ / 4 \| | / 4 \ |
- RootOf\_Z + _Z + 1/ - RootOf\_Z + _Z + 1// \x - RootOf\_Z + _Z + 1/ /
Expand(%) mod 2;
4 3 2
x + x + x + x + 1

 

(2) Move f := x -> x^4+x+1; and alias(alpha = RootOf(f(x))); out of minpol to give

restart;
f := x -> x^4+x+1:
alias(alpha = RootOf(f(x))):
minpol := proc (n)
local m, beta, L, d, t;
m := degree(f(x));
beta := alpha^n;
beta := `mod`(Rem(beta, f(x), x), 2);
L := NULL;
for d to 2^m do
d;
t := `mod`(Powmod(beta, 2^d, f(x), x), 2);
L := L, t;
if t = beta then
break
end if;
end do;
mul(x-L[i], i = 1 .. nops([L]))
end proc:
minpol(3);
/ 3 2\ / 3 2 \ / 3 \ /
\x - alpha - alpha / \x - alpha - alpha - alpha - 1/ \x - alpha - alpha/ \x

3\
- alpha /
Expand(%) mod 2;
4 3 2
x + x + x + x + 1

 

 longrob is correct. When y(x) replaces y, dsolve gives the correct answer. The problem in visko's second attempt may be something to do with using 2D math.

 

ode := 4*x^2*(diff(y(x), x, x))+4*x*(diff(y(x), x))-y(x)=0;
2 / d / d \\ / d \
4 x |--- |--- y(x)|| + 4 x |--- y(x)| - y(x) = 0
\ dx \ dx // \ dx /
ics := y(4)=2, D(y)(4)=-2;
y(4) = 2, D(y)(4) = -2
dsolve({ode, ics});
7 (1/2) 18
y(x) = - - x + ------
2 (1/2)
x

 

 

---

Duncan

 longrob is correct. When y(x) replaces y, dsolve gives the correct answer. The problem in visko's second attempt may be something to do with using 2D math.

 

ode := 4*x^2*(diff(y(x), x, x))+4*x*(diff(y(x), x))-y(x)=0;
2 / d / d \\ / d \
4 x |--- |--- y(x)|| + 4 x |--- y(x)| - y(x) = 0
\ dx \ dx // \ dx /
ics := y(4)=2, D(y)(4)=-2;
y(4) = 2, D(y)(4) = -2
dsolve({ode, ics});
7 (1/2) 18
y(x) = - - x + ------
2 (1/2)
x

 

 

---

Duncan

The website www.oanda.com has been redesigned and historical rates can be downloaded from the revised url

http://www.oanda.com/currency/historical-rates-classic?date_fmt=us&date=05/23/11&date1=05/17/11&exch=GBP&exch2=GBP&
expr=EUR&expr2=EUR&margin_fixed=0&format=CSV&redirected=1

I've attached a revised version of the original Forex.mw that works in Maple 12.

I've noticed that in a Code Edit Region in Maple 12, "\n" is replaced with "\134n" when the worksheet is saved. See Hello World.mw.

Forex_revised.mw

Hello_World.mw

---

Duncan

@zhkhan There may be a more elegant way to do this, but

 

restart:

with(plots):

F:=((g*(-rho2+rho1)*S+rho2*g*L+PV-PL)/((-1+R)*S+L))/((PV-PL)/L+g*rho2);

(1)

p1:=plot([subs(rho1=958,L=1,PV=101,PL=70,g=0,rho2=0.597,mu1=277.53,mu2=12.55,R=22,F),subs(rho1=958,L=1,PV=101,PL=70,g=9.8,rho2=0.597,mu1=277.53,mu2=12.55,R=22,F),subs(rho1=958,L=1,PV=101,PL=70,R=22,g=-9.8,rho2=0.597,R=22,F)],S=0..1,color=[black,red,green]):

display(p1);

 

Q1:=[op([1,1..-2], p1)]:

nops(Q1[1]);

(2)

nops(Q1[1,1]);

(3)

fd := fopen("implotdata.txt", WRITE);
for i from 1 to nops(Q1[1]) do
     fprintf(fd, "%f %f\n", Q1[1, i, 1], Q1[1, i, 2]);
end do:
fclose(fd);

(4)

 

 

Download aaa.mw

 

@zhkhan There may be a more elegant way to do this, but

 

restart:

with(plots):

F:=((g*(-rho2+rho1)*S+rho2*g*L+PV-PL)/((-1+R)*S+L))/((PV-PL)/L+g*rho2);

(1)

p1:=plot([subs(rho1=958,L=1,PV=101,PL=70,g=0,rho2=0.597,mu1=277.53,mu2=12.55,R=22,F),subs(rho1=958,L=1,PV=101,PL=70,g=9.8,rho2=0.597,mu1=277.53,mu2=12.55,R=22,F),subs(rho1=958,L=1,PV=101,PL=70,R=22,g=-9.8,rho2=0.597,R=22,F)],S=0..1,color=[black,red,green]):

display(p1);

 

Q1:=[op([1,1..-2], p1)]:

nops(Q1[1]);

(2)

nops(Q1[1,1]);

(3)

fd := fopen("implotdata.txt", WRITE);
for i from 1 to nops(Q1[1]) do
     fprintf(fd, "%f %f\n", Q1[1, i, 1], Q1[1, i, 2]);
end do:
fclose(fd);

(4)

 

 

Download aaa.mw

 

Users of Unix-based operating systems (Linux/OS X) can use the 'sleep' system call to achieve the same effect, but with minimal CPU load. 

 

TimesUp := proc (m)  # Enter time in seconds for your maple session before message pop up
uses Maplets:-Elements;
local maplet, time1:
maplet:=Maplet( [[ Label( "Stop working now\ntime to start shutting down" ) ]] ):
ssystem(cat("sleep ", m), m + 1);
Maplets[Display](maplet);
end proc:

 

The Windows API does have a Sleep() system call, but I don't know if this is available from the command-line. One alternative for Windows users, instead of the 'sleep' system call, may be to ping the localhost, e.g., ping -n 6 127.0.0.1 > nul. Ping waits 1 second between attempts so '-n 6' produces a 5 second delay.

---

Duncan

zip doesn't give the same answer as ListTools:-Interleave because the lists L and M2 are of different length. zip's result is [L[1], M2[1], L[2], M2[2]] whereas the ListTools:-Interleave result is [L[1], M2[1], L[2], M2[2], L[3]]. If for some reason you must use zip, then zip's fourth argument can be used to introduce empty lists to the output which can then be removed.

ListTools:-Interleave(L, M2);
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1]]
zip((x,y)->(x,y), L, M2); # Using three arguments to zip
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0]] # L[3] does not appear in the output from zip
zip((x,y)->(x,y), L, M2, []); # Using an optional fourth argument to zip
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1], []]
remove(x->x=[], %);
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1]]
 

 

---

Duncan

zip doesn't give the same answer as ListTools:-Interleave because the lists L and M2 are of different length. zip's result is [L[1], M2[1], L[2], M2[2]] whereas the ListTools:-Interleave result is [L[1], M2[1], L[2], M2[2], L[3]]. If for some reason you must use zip, then zip's fourth argument can be used to introduce empty lists to the output which can then be removed.

ListTools:-Interleave(L, M2);
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1]]
zip((x,y)->(x,y), L, M2); # Using three arguments to zip
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0]] # L[3] does not appear in the output from zip
zip((x,y)->(x,y), L, M2, []); # Using an optional fourth argument to zip
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1], []]
remove(x->x=[], %);
[[1, 1, 1, 1, 1], [0], [1, 1, 1, 1, 1], [0], [1, 1]]
 

 

---

Duncan

@gtavictor From the limited information you have provided, it's impossible for me to know exactly why Maple doesn't give the answer you expect, but my guess is that you may need to use unapply more than once to get the answer you expect.  In the example you gave, if x is also a function then you will need to define it as such, e.g., 

x := y -> 3*y;

If you post your longer equations I may be able to be more helpful.

1 2 3 4 Page 1 of 4