Preben Alsholm

11649 Reputation

22 Badges

15 years, 222 days

MaplePrimes Activity


These are answers submitted by Preben Alsholm

You can rather easily get a larger image by using the following code, where the appropriate size depends on your monitor's screensize:

DGR:=DrawGraph(GH, stylesheet = "legacy"):
plots:-display(DGR,scaling=unconstrained,size=[1800,default]);

You can also replace 'default' by an appropriate number (e.g. 800).

You should certainly also look into the many options for DrawGraph.

The following copy has luckily been shrunk by MaplePrimes:

You can do like this:

restart;
Digits:=15:
sigma := 1 + x^2/2;
k := 0.1;
Q := 0.5516;
### Use unapply:
lambda1 := unapply(-3*(7*k^3*sigma^3 + 32*Q*k^2*sigma^2 - 11*k^2*sigma^3 + 54*Q^2*k*sigma - 44*Q*k*sigma^2 + 11*k*sigma^3 + 36*Q^3 - 54*Q^2*sigma + 32*Q*sigma^2 - 7*sigma^3)/(20*sigma^4),x);
###
N:=6/10/10^(-6);
M := Matrix(N + 1, 2, datatype = float[8]);
###
for i from 1 to N+1 do x:=0.6*(i-1)/N; M[i]:= <lambda1(x)| x > end do:
M;
M[-1]; # the last row

But this is much faster:
 

restart;
Digits:=15:
sigma := 1 + x^2/2;
k := 0.1;
Q := 0.5516;
lambda1 := unapply(-3*(7*k^3*sigma^3 + 32*Q*k^2*sigma^2 - 11*k^2*sigma^3 + 54*Q^2*k*sigma - 44*Q*k*sigma^2 + 11*k*sigma^3 + 36*Q^3 - 54*Q^2*sigma + 32*Q*sigma^2 - 7*sigma^3)/(20*sigma^4),x);
N:=6/10/10^(-6);
V:=Vector(N+1,i-> (i-1)*0.6/N,datatype=float[8]);
W:=evalhf(map(lambda1,V));
M:=<W|V>;

 

The following is simpler and works in Maple 12 too:
 

p:=piecewise(`&vartheta;`(tau)>=ϑl,1,0);
eq := diff(`&vartheta;`(tau), tau, tau)+6.666666666*sin(`&vartheta;`(tau))+66.66666666*cos(`&vartheta;`(tau))^2*p*(`&vartheta;`(tau)-.7227342478)+66.66666666*sin(`&vartheta;`(tau))^2*p*(`&vartheta;`(tau)-.7227342478);
`&vartheta;l` := .7227342478;
ic := `&vartheta;`(0) = 0, (D(`&vartheta;`))(0) = 8;
ld := dsolve([eq, ic], numeric, range = 0 .. 5);
odeplot(ld,[tau,p],refine=1,thickness=2, color=blue);

Assuming that the answer to my question about gln is that that is the vector given, then you can just eliminate the sine function.

Using solve and the abbreviations f and s for phi and sin we get:
 

restart;
sys:={f-3/2*s=0,-f^2+3/2*sqrt(1-s^2)=0};
sol:=solve(sys,[f,s]);
Sol:=allvalues(sol);
events:=[[Sol[1,1,1],halt],[Sol[2,1,1],halt]];
eval(sys,events[1,1]);
solve(%,s);
eval(sys,events[2,1]);
solve(%,s);

The events are then

events := [[f = 1/2*sqrt(2*sqrt(10) - 2), halt], [f = -1/2*sqrt(2*sqrt(10) - 2), halt]]

and as shown if either of these events occur then both of the equations in sys are satisfied and vice versa.

I agree that this should have been handled better by odetest.

Looking at the code for `tools/map` gave me the idea of using assumptions.
The following returns 0 in a very short time:

odetest(sol,ode) assuming real;

Another observation:

sol1:=dsolve(ode);
simplify(rhs(sol1)-rhs(sol)) assuming real;
eval(%,_C1 = C[1]);   # 0.

You could do this:
 

restart;
ode2 := diff(varphi(t), t, t) + omega^2*sin(varphi(t));
p0 := evalf(10/180*Pi);
te:=6:
event2 := [[diff(varphi(t), t), T(t)=t]];
ld2 := dsolve([eval(ode2, omega = 2*Pi), varphi(0) = p0, D(varphi)(0) = 0,T(0)=0], numeric,discrete_variables=[T(t)::float], range = 0 .. te, output = listprocedure, events = event2,abserr=1e-12,relerr=1e-9);
plots:-odeplot(ld2,[t,T(t)],0..te,style=point); p:=%:
M:=plottools:-getdata(p)[3];
fnormal(convert(M[..,2],set));

Answer: {0., 0.5009535941, 1.001907188, 1.502860782, 2.003814376, 2.504767970, 3.005721564, 3.506675159, 4.007628753, 4.508582347, 5.009535941, 5.510489535}
##################
PS. I now notice that you are using Maple 13 where maybe getdata doesn't exist (it doesn't in Maple 12, but it does in Maple 15).

You can replace the last two lines above by these two:
 

M:=op([1,1],p);
fnormal(convert(M[..,2],set));

 

This came with Maple 2019. My guess is that the intention was that ColorString, although an export of ColorTools, should not have come up when doing with(ColorTools), i.e. the name ColorString should not have been assigned to ColorTools:-ColorString.
Take a look at this code:
 

restart;
exports(ColorTools);
showstat(ColorTools:-_pexports);          # Here e.g. ColorToAnsi is seen to be removed
S1:=convert(ColorTools:-_pexports(),set); # ColorToAnsi removed
### S1 is the set as the output from this:
S2:=convert(with(ColorTools),set);
S1 subset S2 and S2 subset S1; # true

The conversion of the lists to sets is done because the ordering in the two lists are different.

Notice that ColorToAnsi is not assigned to ColorTools:-ColorToAnsi after with(ColorTools):
 

showstat(ColorTools:-ColorToAnsi);
showstat(ColorToAnsi); # error

My point really just is that ColorString probably wasn't meant for the general user. Therefore no help page.

I will submit an SCR.

There is this note in the help page for seq:

Note: The index variable i is NOT private to the seq invocation.  It is recommended that you always explicitly declare the index variable to be local inside procedures.

RETURN is very old and is now replaced by return (see the help for that)..

They are only needed if what is to be returned is not the last thing computed.
RETURN() means that NULL is returned, i.e. nothing. Thus your procedure doesn't return anything, but writes to the argument result.
Today you would in this situation just write return NULL (or if you are at the end of the procedure just plain NULL) if you don't want the procedure to return anything.
A much simpler version of your procedure, which doesn't assign to the global variable result is:

binom:=proc(a,b,n) local k,s;
    s:=0;
    for k from 0 to n do
        s:=s+(n!/(k!*(n-k)!))*a^(n-k)*b^k;
    end do          
  end proc:
####
## k and s are declared local explicitly here.
## test:
binom(a,b,2);

For clarity in the above procedure I would add one line:
 

 binom:=proc(a,b,n) local k,s;
    s:=0;
    for k from 0 to n do
        s:=s+(n!/(k!*(n-k)!))*a^(n-k)*b^k;
    end do;
    s          
  end proc:

It does the same as the first version, but has the advantage that is evident what is going to be returned.

I tried changing the order of sum and Int. That gave me a result right away:

F := evalf(sum(Int((B[1] - B[2])*exp(-omega*(u - y)), y = 0 .. u), k = 1 .. infinity));

F := 0.7246342704

I also tried only replacing sum by the inert Sum:
 

F := evalf(Int(Sum((B[1] - B[2])*exp(-omega*(u - y)), k = 1 .. infinity), y = 0 .. u));

That gave the very same result.

Everytime r1 is called a new value (most likely) comes up. Thus your piecewise code doesn't work.
Try calling r1 only once in each call to randir:
 

restart; 
r1 := rand(0. .. 100.0);
randir2 := proc() local r:=r1();
  piecewise(0 <= r and r < 50, 1, 50 <= r and r < 100, 2)
end proc;

Here r will be the same in all 4 cases inside randir2.
Now try:
 

for i to 1000 do  if randir2() = 0 then print(fail[i]) end if end do:

No fails.

The reason you got 0 a lot of times is because piecewise returns 0 by design if none of the conditions are satisfied and they almost surely aren't satisfied in your original code.

I haven't noticed any difference.

But I checked under Tools/Options/Interface/Default zoom and in my case it was set at 125%. The same as in Maple 2019.2 and inherited from there when installed.

In Maple 15 i see that I have default zoom = 100%, which I just changed to 125%. Better for me.

Your input is a listlist, not an rtable.

restart;
A:=[[0, 4], [1, 3], [2, 2], [3, 1], [4, 0], [0, 3], [1, 2], [2, 1], [3, 0], [0, 2], [1, 1], [2, 0], [0, 1], [1, 0], [0, 0]];
ArrayTools:-Reverse(A); # The error
interface(rtablesize=15);
A1:=Matrix(A); # A Matrix so an rtable 
ArrayTools:-Reverse(A1);

 

Either use 1D-input (Maple input), where the warning doesn't come up at all or start the worksheet with a local declaration:
restart;
local e;

In the case with 8 unknowns Maple couldn't find any solution and issues a warning.

In the case with 6 unknowns you have 8 equations and only 6 unknowns. solve responds with NULL, which means no solutions.

So no reason for being surprised (if you are).

It has nothing to do with linalg although that package is very much outdated as Kitonum points out.

### Correction: It is not sys that is solved in the first solve command but a set of 6 equations (not being subject to the substitution used in defining sys), which is indeed linear in the chosen 6 variables. The coefficient matrix A, however, has rank only 5 while the augmented matrix <A|b> has rank 6, thus that linear system has no solution:
 

sys6:=[S__Fx = 0, S__Fz = 0, S__Myl = 0, S__Mys = 0, S__Mysi = 0, S__Mzle = 0];
nops(sys6); # 6
vars:=[R__xl, R__xs, R__xsi, R__zl, R__zs, R__zsi];
A,b:=LinearAlgebra:-GenerateMatrix(sys6,vars);
LinearAlgebra:-Rank(A); #5
LinearAlgebra:-Rank(<A|b>); #6

 

1 2 3 4 5 6 7 Last Page 1 of 147