vv

12453 Reputation

19 Badges

9 years, 285 days

MaplePrimes Activity


These are answers submitted by vv

I think I found the location where the random behavior resides.
It is the indices(T) where T is a table containing local variables in indices.
That's all we can do because indices is builtin.

p:=proc()
local lambda,T;
T[lambda-1]:=1; T[lambda-2]:=1; T[lambda-3]:=1;
indices(T);
end:


p();


At each execution, the order changes.
Note that for a nonlocal lambda, everything is OK.

foldr and foldl are simply executing a loop. Why not doing it yourself:

p:=1:
for x in X do p:=mods(mods(x,m)*p, m) od;

 

Maybe mods(x,m)  could be eliminated and replaced by x;  this depends on the magnitude of your numbers.

For sin(t)<0  e.g. t in =-Pi .. 0 you have a simple ODE x' = - B*x
for which an initial condition is not provided.

For x in 0 .. Pi it results an integro-differential equation in x(t), but probably Maple can't solve it (numerically or symbolically) and some special approximation method will be needed.

This  solution could maybe used as a starting approx.

restart;
Digits:=100;
EQ1 := -3.000000000*10^(-8)+3.815358072*sin(3.141592654*10^7*x)+9.534375000*10^(-30)*(diff(w(x), x, x, x, x))-2.383593750*10^(-60)*(diff(w(x), x, x, x, x, x, x))-5.085000000*10^(-13)*(diff(w(x), x))*(diff(u(x), x, x))-7.627500000*10^(-13)*(diff(w(x), x))^2*(diff(w(x), x, x))-5.085000000*10^(-13)*(diff(w(x), x, x))*(diff(u(x), x))+0.2410290000e-5*(diff(w(x), x, x));
EQ2 := 5.650000000*10^(-20)*(diff(u(x), x, x, x, x))-226000000000*(diff(u(x), x, x))-226000000000*(diff(w(x), x))*(diff(w(x), x, x));
bc:= {u(0) = 0, u(L) = 0, w(0) = 0, w(L) = 0, (D(u))(0) = 0, (D(u))(L) = 0, ((D@@2)(w))(0) = 0, ((D@@2)(w))(L) = 0, ((D@@4)(w))(0) = 0, ((D@@4)(w))(L) = 0};
Order:=8;
s:=dsolve( {EQ1,EQ2}, {u(x),w(x)}, 'type=series'):
s:=evalf(convert(s,polynom));
s1:=eval(s,bc);
#indets(%,function);
substs:=[(D(w))(0)=w0, ((D@@2)(u))(0)=u2, ((D@@3)(u))(0)=u3, ((D@@3)(w))(0)=w3, ((D@@5)(w))(0)=w5];
s2:=eval(s1,substs);
uf:=unapply( eval(u(x),s2), x);
wf:=unapply( eval(w(x),s2), x);
subs([u=uf,w=wf],bc);
sys:=eval(%) minus {0.=0};
#nops(sys);
L := 100.*10^(-9);
ok:=solve(sys);
solux:=eval(uf(x),ok[1]);
solwx:=eval(wf(x),ok[1]);
plot(solux,x=0..1);
plot(solwx,x=0..1);

The graph of u:

 

For x = 0 .. L it is:

 

You cannot, Maple does not know about it.

But usually it is straightforward (except pathological examples) to express a Stieltjes integral as a Riemann one.
Note that Maple also knows improper Riemann integrals such as int(1/sqrt, 0..1).

A recursive version, simple and fast.
It returns a sequence of lists.

In my tests it was the fastest for (n,k) = (22,11).

rcomb:=proc(n,k,p:=[])
  if k=n then return [seq(1..n),op(p)] fi;
  if k=1 then return seq([i,op(p)],i=1..n) fi;
  rcomb(n-1,k,p),rcomb(n-1,k-1,[n,op(p)])
end;

 

nops([rcomb(20,5)])=binomial(20,5);
                         15504 = 15504

rcomb(5,3);
    [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4], [1, 2, 5], [1, 3, 5], [2, 3, 5], [1, 4, 5], [2, 4, 5], [3, 4, 5]

Edit. Corrected code. Unfortunately some speed was lost, but still decent.



 

 

The problem is nonlinear and nonconvex-nonconcave, so global min/max are not easy.
Your V must be a row rector, but I will use columns.


restart;
with(LinearAlgebra):
n:=2;
A:=RandomMatrix(n);
B:=RandomMatrix(n);
V:=Vector(n,symbol=v);
f := (V^+ . A^+ . A . V) / (V^+ . B^+ . B . V);
# dom := seq( v[i]=-1..1, i=1..n),location;
dom := location:
maximize(f, dom);
evalf(%);
minimize(f, dom);
evalf(%);

Note that for n>3 this will not work because the exact solutions will need the eigenvalues of a matrix of order n.

Mathematically this problem should be approached differently:
the objective function is the square of  Norm(A.V)/Norm(B.V)  and this
reduces to compute the norm of a matrix  T^(-1).A.T  where T is an orthogonal matrix deduced from B.

 

Edit. Minimize works but gives only approximate (float) results and the min/max could be only local.

n:=6;
dom1 := seq( v[i]<=1, i=1..n),  seq( v[i]>=-1, i=1..n):
A,B:='LinearAlgebra:-RandomMatrix(n)'$2;
V:=Vector(n,symbol=v):
f := (V^+ . A^+ . A . V) / (V^+ . B^+ . B . V):
Optimization[Minimize](f, {dom1});

 

 

It would be nice if you rename your variables; they say nothing to us and are distracting.
This can be done automatically (to x[1],x[2],...):

V:=[indets(u)[]];  #your expression is u
X:=[seq(x[i],i=1..nops(V))];
uu:=subs(V =~X,u);

Now uu is a decent expression.
Just an idea to "optimize" and see what subexpressions are repeating often, you could use e.g.

CodeGeneration:-Python(uu,optimize); 
# because Python has a similar syntax

==>

t1 = x[1] * x[5]
t2 = t1 * x[7]
t3 = x[0] * x[1]
t4 = x[4] ** 2
t5 = x[3] * t4
t7 = x[3] * x[4]
t9 = t3 * t7 * x[5]
t10 = x[0] * x[3]
t11 = x[4] * x[6]
t12 = t10 * t11
t15 = t10 * x[4] * x[7]
t17 = x[5] * x[6]
t18 = t10 * t17
t19 = x[5] * x[7]
t20 = t10 * t19
t21 = x[1] * x[4]
t24 = x[6] ** 2
t25 = x[6] * x[7]
t26 = 3 * t25
t27 = x[7] ** 2
t29 = t21 * x[6] + t21 * x[7] + t3 * t5 + 2 * t12 + 2 * t15 + t18 + t20 + t24 + t26 + 2 * t27 + t9
t31 = x[1] ** 2
t32 = x[0] * t31
t35 = x[5] ** 2
t42 = t3 * x[3]
t43 = x[4] * x[5]
t50 = x[3] * t35
t69 = 3 * t10 * t11 * x[7] + 3 * t10 * t17 * x[7] + t10 * x[4] * t24 + 2 * t10 * x[5] * t24 + 2 * t10 * x[4] * t27 + t3 * t5 * x[6] + t3 * t5 * x[7] + t3 * t50 * x[6] + t3 * t50 * x[7] + t32 * t7 * t35 + t32 * t5 * x[5] + 3 * t42 * t43 * x[6] + 3 * t42 * t43 * x[7]
t72 = t31 * x[4]
t93 = t10 * x[5] * t27 + t1 * t24 + 3 * t1 * t25 + 2 * t1 * t27 + t72 * t17 + t72 * t19 + 2 * t21 * t24 + 3 * t21 * t25 + t21 * t27 + 2 * t24 * x[6] + 7 * t24 * x[7] + 7 * x[6] * t27 + 2 * t27 * x[7]
t95 = 1 / (t69 + t93)
t107 = t1 * x[6] + t3 * t50 + t12 + t15 + 2 * t18 + t2 + 2 * t20 + 2 * t24 + t26 + t27 + t9
t112 = 2 * t2 * x[2] * t29 * t95 + 2 * (-x[6] - x[7]) * x[2] + 2 * x[6] * x[2] * t107 * t21 * t95

 

Edit.
Even better after a simplify(...,...):

t3 = x[6] ** 2
t5 = 2 * t3 * x[6]
t6 = 7 * x[7]
t10 = (x[4] + 2 * x[5]) * x[0] * x[3]
t11 = x[1] * x[5]
t14 = x[7] ** 2
t15 = 7 * t14
t16 = x[4] + x[5]
t17 = x[0] * x[3]
t23 = x[1] * x[0]
t35 = x[1] * x[4]
t41 = 2 * t14 + x[7] * (2 * (x[4] + x[5] / 2) * x[0] * x[3] + t35) + t16 * x[4] * x[3] * t23
t53 = x[4] ** 2
t56 = x[5] ** 2
t72 = -2 / (t5 + t3 * (t6 + t10 + (2 * x[4] + x[5]) * x[1]) + x[6] * (t15 + 3 * x[7] * (t17 + x[1]) * t16 + x[1] * (x[3] * (3 * x[4] * x[5] + t53 + t56) * x[0] + x[5] * t35)) + t41 * (t11 + x[7])) * (t5 + t3 * (t6 + t10 + t11) + x[6] * (t15 + 2 * x[7] * (0.3e1 / 0.2e1 * t17 + x[1]) * t16 + t16 * x[5] * x[3] * t23) + t41 * x[7]) * x[2] * (x[6] + x[7])

 

 

You have a path integral, not a line integral (in Maple terminology).

VectorCalculus:-PathInt( 3*y-x, [x,y] = Line(<2,1>, <3,-1>) );


(I'd recommend to compute it by hand too).

Use two pairs of quotes.

evalf(Int(''g(x)'',x=1..2));
evalf(Int(''h(g(x))'',x=1..2));

For the last one you may use:

evalf(Int(h@g, 1..2))

Use a duplicate parameter. Example:

f:=piecewise(a=0, aa*x^2+b, a*x^2+b):
Explore(plot(f,x=-1..1, view=[-1..1,-1.0..4]),
        initialvalues=[a=0, b= 0.0],
        parameters=[ [a, controller=textarea],  #set a=0 to use the slider
                     [aa=1.0 .. 3.0],
                     [b=-1.0 .. 1.0]
                   ]);



combine (or combine/power) does not work for products with symbolic limits.

But if you specify n (e.g. n=10), combine(%, power) gives the desired form.

Use any of the following:

eval(x,ans[2]);
                  
rhs(ans[2][]);
                  
op([2,1,2],ans);

 

With the default method and precision, Maple approximates wrongly some of the integrals (or does not approximate at all).
To get the correct results, change for example  A[a]:=...

to

A[a] := int(f(x)*g(x,a),x=-infinity..a-1,numeric,digits=20,epsilon=10^(-10));

 

I think that there are good alternatives.

- For collected terms in an expression see ?LargeExpressions

- The results in your worksheet are easier to read if we use:

alias(alpha=RootOf(_Z^2+5));
alias(beta=RootOf(9*_Z^6-48*_Z^5+30*_Z^3+25));

[this way we have full control on abbreviations]

First 92 93 94 95 96 97 98 Last Page 94 of 111