vv

13877 Reputation

20 Badges

10 years, 0 days

MaplePrimes Activity


These are answers submitted by vv

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]

y(z) = F(z) + int(sqrt(z - sigma)*y(sigma), sigma = 0..z);
intsolve(%, y(z), method = Laplace);

ff:=proc(a)
local aa,sa:=convert(a,set),T,u;
aa:=zip(`[]`,a,[$1..nops(a)]);
for u in sa do T[u]:=NULL od;
for u in aa do T[u[1]]:=T[u[1]],u[2] od;
[seq([T[u]],u=sa)];
end:

ff([[x+y+z],[2*x+y+z],[x-y+z],[2*x+y+z]]);
           
            [[3], [1], [2, 4]]

Seems to be a little faster and easier to read.

It's difficult to understand what you are trying to do.

It seems that you want to use the implicit equation of the spiral r = theta  (given in polar coordinates) and to obtain the points of intersection with some line.

1. You forgot  the third equation:  r = sqrt(x^2 + y^2)

2. eq1 is wrong; LHS should be r  (not r^2) . But RHS is wrong too (see below).

The correct implicut equation of the spiral is

(F(x,y) =)     frem(sqrt(x^2 + y^2) - arctan(y,x), 2.*Pi) = 0

But you should not use it; with polar coordinates is much better. Note that e.g. implicitplot  is not able to draw correctly  F(x,y)=0.

If you want to intersect the spiral with a line (say a*x+b*y+c=0), just solve the system

{r = theta,  a*r*cos(theta) + b*r*sin(theta) + c = 0}

It will have an infinity of solutions; you can use solve followed by evalf(allvalues(%))  or RootFinding.

 

 

 

 

 

 

You must define the points first.

with(geometry):
point(F1,0,1), point(F2,4,1);
ellipse(e1,['foci'=[F1, F2], 'MajorAxis' = 8],[x,y]);

draw(e1);


First 101 102 103 104 105 106 107 Last Page 103 of 120