Carl Love

Carl Love

28095 Reputation

25 Badges

13 years, 101 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

I think that you are saying that you want the various orderings of the compositions to be considered as one for the purpose of random selection. Then you want to use partition instead of composition, like this:

RandomPartitions:= proc(n::posint, k::posint)
local
     C,
     Partitions:= [seq(C-~1, C= select(p-> nops(p)=k, combinat:-partition(n+k,n+1)))],
     Rand:= rand(1..nops(Partitions))
;
     ()-> Partitions[Rand()]
end proc:

R:= RandomPartitions(8,6):
n:= 1000:
map(lhs=rhs/n, Statistics:-Tally(['R()[]' $ n]));

Unfortunately, "approximate using n digits precision" means that the subcomputations are done to n digits, not that the overall computation is accurate to n digits. It is the responsibility of the user to increase the precision of the subcomputations if that is needed.

Your code is selecting the second point of the two returned by solve. Apparently, you want the first point. So, you need a criterion with which to select between the two points returned by solve. Would the point which is closest to the origin be an appropriate criterion? Then you can use this procedure.

Closest:= proc(
     Sol::list(list(name=numeric)),
     {To::list(numeric):= [0,0],
      XY::list(name):= ['x', 'y']
})
local
     Min:= infinity, ptMin, pt, d,
     dist:= proc(Pt1,Pt2)
     option inline;
          evalf(sqrt(`+`(((Pt1 -~ Pt2)^~2)[])))
     end proc
;
     for pt in Sol do
          d:= dist(eval(XY, pt), To);
          if d < Min then
               Min:= d;
               ptMin:= pt
          end if
     end do;
     
     ptMin
end proc: 

Pt:= Closest(Sol);

Point2:= plottools:-disk(eval([x,y], Pt), 0.2e-1, color = red):

How about this?

n:= 10:
map(lhs=rhs/n, Tally(['R()[]' $ n]));

seq(coeff(eq,v), v= vars);

Using ex as your original expression,

subsop(1= factor(op(1, ex)), ex);

convert(expand(u^3+u^2-1), exp);

There are numerous problems in your code. First, the inverse tangent function is arctan, not atan. Second, you cannot make an assignment inside a return statement (or any other statement). Unlike C, in Maple an assignment is not an expression that can be part of another expression. Third, what's the point of having a loop if you're always going to return on the first iteration?

Correct these and then maybe we can discuss the rest.

I was able to get a result by substantially reducing the requested accuracy. I had to increase abserr, but not relerr. So, I'm a bit skeptical about this result. I changed your theta to T to save typing.

restart:
ODE:=
     (1+T(x))*diff(T(x),x) + x*diff(T(x),x)^2 +
     x*(1+T(x))*diff(T(x),x$2) - T(x)^3-diff(T(x), x)
     = 0
;

BCs:= T(1)=1, D(T)(0) = 0:

Sol:= dsolve(
     {ODE, BCs}, numeric, method= bvp[middefer],
     maxmesh= 2^15, abserr= .58e-1
):
plots:-odeplot(Sol, [x,T(x)], x= 0..1);

subs is a low-level command that can only be used to substitute for subexpressions that appear as nodes on the tree that represents the expression. So using subs requires some (small) amount of knowledge of how expressions are stored. For example, in the expression x+y+z, the nodes are x+y+z, x, y, and z; x+y is not a node. You can see the tree representing an expression by using ToInert(expression). Unfortunately, the representation is not graphical.

algsubs is a high-level command that can be used to substitute for more-complicated subexpressions. The syntax is the same as subs. In your case, that would be

algsubs(cosh(k*h)/sinh(k*h)= 1/tanh(k*h), td);

If tangent lines are perpendicular, then their corresponding radii are perpendicular.  Given three points A, B, C, then AB is perpendicular to BC iff (A[2]-B[2])*(C[2]-B[2]) = (B[1]-A[1])*(C[1]-B[1]).

I also vastly simplified the rest of your code, mostly by using isolve to get the integer points on the circle.

restart:

with(geometry):

(Mx,My):= (-1,-5):  R:= 5:

point(M,Mx,My):

eqS:= (x-Mx)^2 + (y-My)^2 = R^2:

 

Find the points with integer coordinates on the circle and remove any with either coordinate the same as the center.

L:= remove(pt-> pt[1]=Mx or pt[2]=My, map2(eval, [x,y], [isolve({eqS})]));

[[-5, -8], [-5, -2], [-4, -9], [-4, -1], [2, -9], [2, -1], [3, -8], [3, -2]]

For each such point, get the equation of the tangent line.

circle(S, eqS, [x,y]):

k:= [seq](sort(Equation(TangentLine(P, S, point(A, pt[])), [x,y])), pt in L):

 

Pair each line with its point of tangency.

Lk:= zip(`[]`, L, k);

[[[-5, -8], -4*x-3*y-44 = 0], [[-5, -2], -4*x+3*y-14 = 0], [[-4, -9], -3*x-4*y-48 = 0], [[-4, -1], -3*x+4*y-8 = 0], [[2, -9], 3*x-4*y-42 = 0], [[2, -1], 3*x+4*y-2 = 0], [[3, -8], 4*x-3*y-36 = 0], [[3, -2], 4*x+3*y-6 = 0]]

 

Form all pairs of the tangent lines, and remove any pair where the lines are perpendicular. If tangent lines are perpendicular, then theircorresponding radii are perpendicular.  Given three points A, B, C, then AB is perpendicular to BC iff (A[2]-B[2])*(C[2]-B[2]) = (B[1]-A[1])*(C[1]-B[1]).

PLk:= remove(
     #Perpendicularity criterion:
     P-> (P[1,1,2]-My)*(P[2,1,2]-My) = (Mx-P[1,1,1])*(P[2,1,1]-Mx),
     combinat:-choose(Lk,2)
);

 

[[[[-5, -8], -4*x-3*y-44 = 0], [[-5, -2], -4*x+3*y-14 = 0]], [[[-5, -8], -4*x-3*y-44 = 0], [[-4, -9], -3*x-4*y-48 = 0]], [[[-5, -8], -4*x-3*y-44 = 0], [[2, -1], 3*x+4*y-2 = 0]], [[[-5, -8], -4*x-3*y-44 = 0], [[3, -8], 4*x-3*y-36 = 0]], [[[-5, -8], -4*x-3*y-44 = 0], [[3, -2], 4*x+3*y-6 = 0]], [[[-5, -2], -4*x+3*y-14 = 0], [[-4, -1], -3*x+4*y-8 = 0]], [[[-5, -2], -4*x+3*y-14 = 0], [[2, -9], 3*x-4*y-42 = 0]], [[[-5, -2], -4*x+3*y-14 = 0], [[3, -8], 4*x-3*y-36 = 0]], [[[-5, -2], -4*x+3*y-14 = 0], [[3, -2], 4*x+3*y-6 = 0]], [[[-4, -9], -3*x-4*y-48 = 0], [[-4, -1], -3*x+4*y-8 = 0]], [[[-4, -9], -3*x-4*y-48 = 0], [[2, -9], 3*x-4*y-42 = 0]], [[[-4, -9], -3*x-4*y-48 = 0], [[2, -1], 3*x+4*y-2 = 0]], [[[-4, -9], -3*x-4*y-48 = 0], [[3, -2], 4*x+3*y-6 = 0]], [[[-4, -1], -3*x+4*y-8 = 0], [[2, -9], 3*x-4*y-42 = 0]], [[[-4, -1], -3*x+4*y-8 = 0], [[2, -1], 3*x+4*y-2 = 0]], [[[-4, -1], -3*x+4*y-8 = 0], [[3, -8], 4*x-3*y-36 = 0]], [[[2, -9], 3*x-4*y-42 = 0], [[2, -1], 3*x+4*y-2 = 0]], [[[2, -9], 3*x-4*y-42 = 0], [[3, -8], 4*x-3*y-36 = 0]], [[[2, -1], 3*x+4*y-2 = 0], [[3, -2], 4*x+3*y-6 = 0]], [[[3, -8], 4*x-3*y-36 = 0], [[3, -2], 4*x+3*y-6 = 0]]]

 

For each such pair of lines, find the point of intersection.

map(P-> [P[1,2], P[2,2], solve([P[1,2],P[2,2]], [x,y])[]], PLk);

[[-4*x-3*y-44 = 0, -4*x+3*y-14 = 0, [x = -29/4, y = -5]], [-4*x-3*y-44 = 0, -3*x-4*y-48 = 0, [x = -32/7, y = -60/7]], [-4*x-3*y-44 = 0, 3*x+4*y-2 = 0, [x = -26, y = 20]], [-4*x-3*y-44 = 0, 4*x-3*y-36 = 0, [x = -1, y = -40/3]], [-4*x-3*y-44 = 0, 4*x+3*y-6 = 0], [-4*x+3*y-14 = 0, -3*x+4*y-8 = 0, [x = -32/7, y = -10/7]], [-4*x+3*y-14 = 0, 3*x-4*y-42 = 0, [x = -26, y = -30]], [-4*x+3*y-14 = 0, 4*x-3*y-36 = 0], [-4*x+3*y-14 = 0, 4*x+3*y-6 = 0, [x = -1, y = 10/3]], [-3*x-4*y-48 = 0, -3*x+4*y-8 = 0, [x = -28/3, y = -5]], [-3*x-4*y-48 = 0, 3*x-4*y-42 = 0, [x = -1, y = -45/4]], [-3*x-4*y-48 = 0, 3*x+4*y-2 = 0], [-3*x-4*y-48 = 0, 4*x+3*y-6 = 0, [x = 24, y = -30]], [-3*x+4*y-8 = 0, 3*x-4*y-42 = 0], [-3*x+4*y-8 = 0, 3*x+4*y-2 = 0, [x = -1, y = 5/4]], [-3*x+4*y-8 = 0, 4*x-3*y-36 = 0, [x = 24, y = 20]], [3*x-4*y-42 = 0, 3*x+4*y-2 = 0, [x = 22/3, y = -5]], [3*x-4*y-42 = 0, 4*x-3*y-36 = 0, [x = 18/7, y = -60/7]], [3*x+4*y-2 = 0, 4*x+3*y-6 = 0, [x = 18/7, y = -10/7]], [4*x-3*y-36 = 0, 4*x+3*y-6 = 0, [x = 21/4, y = -5]]]


Download Nonperpendicular.mw

Let the expression be expr. Then do

op(indets(expr, specfunc(anything, RootOf))[1]);

Yes, it is easy with plotsetup(window). See help pages ?plot,device and ?plotsetup .

Your question is barely readable. In the future, enter your matrix into Maple and then cut-and-paste the matrix into your post.

I hope that you can draw your conclusions from the following worksheet. If not, ask for more help.


restart:

A:= < k+3, 2, k-4, 3;
      0,   2,  -9, 5;
      0,   0, k^2+k-2, k-1 >;  

A := Matrix(3, 4, {(1, 1) = k+3, (1, 2) = 2, (1, 3) = k-4, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = k^2+k-2, (3, 4) = k-1})

(1)

eval(A, k=1);

Matrix(3, 4, {(1, 1) = 4, (1, 2) = 2, (1, 3) = -3, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0})

(2)

solve(A[3,3] = 0, {k});

{k = 1}, {k = -2}

(3)

eval(A, k= -2);

Matrix(3, 4, {(1, 1) = 1, (1, 2) = 2, (1, 3) = -6, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = -3})

(4)

 


Download Parametric_linear_system.mw

 

 


restart:

Notice the use of  `*` instead of implied multiplication

Sys:=
     4*x1 + 2*x2 - 7*x3 - 11*x4 = 5,

     2*x1 + 1*x2 - 2*x3 - 4*x4 = 2,

     4*x1 + 2*x2 - 10*x3 - 14*x4 = 6
:

X:= [x||(1..4)]:

A:= LinearAlgebra:-GenerateMatrix([Sys], X, augmented);

A := Matrix(3, 5, {(1, 1) = 4, (1, 2) = 2, (1, 3) = -7, (1, 4) = -11, (1, 5) = 5, (2, 1) = 2, (2, 2) = 1, (2, 3) = -2, (2, 4) = -4, (2, 5) = 2, (3, 1) = 4, (3, 2) = 2, (3, 3) = -10, (3, 4) = -14, (3, 5) = 6})

(1)

R:= LinearAlgebra:-ReducedRowEchelonForm(A);

R := Matrix(3, 5, {(1, 1) = 1, (1, 2) = 1/2, (1, 3) = 0, (1, 4) = -1, (1, 5) = 2/3, (2, 1) = 0, (2, 2) = 0, (2, 3) = 1, (2, 4) = 1, (2, 5) = -1/3, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = 0})

(2)

Sol:= LinearAlgebra:-LinearSolve(A, free= t);

Sol := Vector(4, {(1) = t[1], (2) = -2*t[1]+4/3+2*t[4], (3) = -1/3-t[4], (4) = t[4]})

(3)

The solution space is two-dimensional. Verify the solution by plugging into the original system of equations.

eval(Sys, X =~ convert(Sol, list));

5 = 5, 2 = 2, 6 = 6

(4)

 


Download Linear_system.mw

First 295 296 297 298 299 300 301 Last Page 297 of 395