acer

32333 Reputation

29 Badges

19 years, 319 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You can refer to the global names as :-J and :-F, in order to avoid collision with the locals of the same names.

You can furthermore quote those global name references with uneval quotes, so as to protect against the case of their having been assigned values.

restart;

foo:=proc(A::Matrix)
local J,Q;
J,Q:=LinearAlgebra:-JordanForm(A,output=[':-J',':-Q']);
end proc:

A:=Matrix([[1,2],[3,4]]);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

foo(A);

Matrix(2, 2, {(1, 1) = 5/2-(1/2)*sqrt(33), (1, 2) = 0, (2, 1) = 0, (2, 2) = 5/2+(1/2)*sqrt(33)}), Matrix(2, 2, {(1, 1) = 1/2+(1/22)*sqrt(33), (1, 2) = (1/66)*(-3+sqrt(33))*sqrt(33), (2, 1) = -(1/11)*sqrt(33), (2, 2) = (1/11)*sqrt(33)})

 

Download JordanForm_proc.mw

ps. You could sensibly quote the keyword option 'output' as well, on similar grounds.

It's not your fault; there is a bug in the case of filledregions, a specified non-default number of contours, and the new legend mechanism.

I am supposing that you want the specified number of contours (20) as in the first plot below, but the visual look of the thicker color bars in the second plot below.

(I may be able to figure out a hot fix for the procedure, a bit later today...)

restart;

ee:=16.70196911*2^(1/2)*((x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)))^(1/2)
    /(4.373839156*(x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)) + 1)^(1/2),
    x = 0.001 .. 1, y = 0.001 .. 1:

opts:=thickness = 0, coloring = ["blue", "yellow"]:

plots:-display(
   plots:-contourplot(ee, contours = 20, opts, legend),
   plots:-contourplot(ee, contours = 20, opts, filledregions),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

plots:-display(
   plots:-contourplot(ee, opts, filledregions, legend),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

 

Download filled_cont_legend_bug.mw

You are getting bitten by premature evaluation of the call f(x).

The error would occur even if you tried just to compute this,

    f(x);

Either use the functional calling sequence of the plot command, or pass 'f(x)' quoted so as to delay evaluation, or edit procedure f so that it returns unevaluated for nonnumeric x (I haven't done that last one).

restart;

sine :=   plot(sin(x), x=0..4*Pi, color=black,thickness=3):
s    :=   plot(sin(x), x=0..4*Pi, color=red, filled=true):
cosine := plot(cos(x), x=0..4*Pi, color=black,thickness=3):
c      := plot(cos(x), x=0..4*Pi, color=red, filled=true):

f := x -> if cos(x)>0 and sin(x)>0 then
              min(cos(x),sin(x))
          elif cos(x)<0 and sin(x)<0 then
              max(cos(x),sin(x))
          else 0
          end if:

b := plot(f, 0..4*Pi, filled=true, color=green):

plots:-display([sine, cosine, b, s, c]);

 

Download Heck_15.5.mw

If you click on the magenta error message as displayed in the Maple GUI (and if Maple is set to find your web-browser) then it should take you to this related Error Guide page.

[edit] On page 426 of the Heck text (as found by Google) I see the example in question as computing the problematic plot using the functional form, ie.
   b := plot(f, 0..4*Pi, filled=true, color=white):
in the 3rd edition (2003). That happens to coincide with the first way I gave above. It seems as if you have made a mistake, while editing his example.

Change

   Pi(d/2)

to,

   Pi*(d/2)

The former is a functional application of the name Pi to the argument d/2. Presumably you want the multiplication. instead.

In 2D Input you could also use a space before the bracket, to denote so-called implicit multiplication. I find that hard to distinguish, visually.

You can insert the explicit multiplication sign whether in 1D or 2D input mode, and I think doing so is a good idea.
 

restart;

V := (4*Pi(d/2)^3)/3;

(4/3)*Pi((1/2)*d)^3

eval(V, d = 6.35*mm);

(4/3)*Pi(3.175000000*mm)^3

lprint(indets(%,function));

{Pi(3.175000000*mm)}

V := (4*Pi*(d/2)^3)/3;

(1/6)*Pi*d^3

eval(V, d = 6.35*mm);

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

 

Download multiplication_syntax.mw

It is documented in the Help page with topic coloncolon .

The description from your instructor uses an expression for f. Your attempt calls Newton with an operator for f. Both methodologies can work, but unfortunately your attempt mixed up the two concepts.

Below I show both with modifications of your code, for f as operator or expression.

By the way, you only have to differentiate once. You don't have to repeat that part of the computation, for each iteration of the loop.

You might find these revisions to your code of some use. I corrected the differentiation and evaluation of the derivative, at a point. I also moved the conditional test into the loop so that it would return (possibly earlier) as soon as any iterate satisfied the criterion.

Download rf.mw

restart;
Newton_proc:=proc(f, a)
  local df,n,x1;
  df:=D(f);
  x1:=a;
  if abs(f(x1))<=10^(-8) then
    return x1;
  end if;
  for n to 9 do
    x1:=x1-f(x1)/df(x1);
    if abs(f(x1))<=10^(-8) then
      return x1;
    end if;
  end do;
  return FAIL;
end proc:

Newton_proc( x->x^3-3*x^2+2*exp(x)+5, -1.2 );
         -1.162515305

Newton_proc( x->arctan(x), 1.5 );
              FAIL

restart;
Newton_expr:=proc(f, a)
  local df,n,x,x1;
  x := indets(f,And(name,Not(constant),
                    satisfies(u->depends(f,u))));
  if nops(x)<>1 then
    error "expecting an expression depending on one name";
  else
    x := x[1];
  end if;
  df:=diff(f,x);
  x1:=a;
  if abs(eval(f,x=x1))<=10^(-8) then
    return x1;
  end if;
  for n to 9 do
    x1:=x1-eval(f,x=x1)/eval(df,x=x1);
    if abs(eval(f,x=x1))<=10^(-8) then
      return x1;
    end if;
  end do;
  return FAIL;
end proc:

Newton_expr( x^3-3*x^2+2*exp(x)+5, -1.2 );
          -1.162515305

Newton_expr( arctan(x), 1.5 );
              FAIL

You could simplify the system of equations by the constraint equations, prior to calling solve. (I did this a few hours ago. You can compare with vv's suggestion.)

Download Example_ac.mw

What properties do you know about the variables?

restart;

Given_eq_3_37 := M = k_ * sqrt(L__1 * L__2);

M = k_*(L__1*L__2)^(1/2)

Given_eq_3_30 := k_ = sqrt((L__m)^2 / (L__1 * L__2p));

k_ = (L__m^2/(L__1*L__2p))^(1/2)

combine(eval(Given_eq_3_37,Given_eq_3_30))
  assuming L__1*L__2>0;

M = (L__2*L__m^2/L__2p)^(1/2)

combine(eval(Given_eq_3_37,Given_eq_3_30))
  assuming L__m^2/(L__1*L__2p)>0;

M = (L__2*L__m^2/L__2p)^(1/2)

Download Q20201001_ac.mw

If I understand your goal properly, then one way is to first select all the terms which satisfy
the second condition, and then to select from that those terms which have the least degree.

restart;

F := proc(P)
  local temp, mindeg;
  temp := select(term->member(degree(term,[x])-degree(term,[y]),
                              [0,-1]), [op(P)]);
  mindeg := min(map(degree,temp,[x,y]));
  select(term->degree(term,[x,y])=mindeg, temp);
end proc:

F( 100*x^2*y^2 + 35*y*x + 45*x );

[35*y*x]

F( 13*x^2*y^2 + x*y^2 + 2*y*x^2 );

[x*y^2]

 

Download poly_deg_query.mw

A 3-D simplicial facet is a facet of a 3-D simplex, ie. a triangle.

restart:

A := ArrayTools:-RandomArray(35, 3):

xyz := convert(A,listlist):

ch := ComputationalGeometry:-ConvexHull(xyz);

[[1, 14, 7], [14, 5, 7], [5, 32, 7], [32, 5, 14], [31, 24, 11], [31, 16, 24], [4, 31, 11], [4, 6, 14], [35, 32, 14], [6, 35, 14], [35, 6, 4], [32, 34, 7], [1, 2, 14], [2, 4, 14], [24, 21, 11], [21, 4, 11], [21, 35, 4], [31, 3, 16], [3, 17, 16], [2, 3, 31], [17, 3, 1], [3, 2, 1], [17, 26, 16], [26, 34, 32], [16, 26, 24], [35, 27, 32], [27, 26, 32], [26, 27, 24], [27, 21, 24], [21, 27, 35], [4, 33, 31], [33, 2, 31], [2, 33, 4], [15, 26, 17], [15, 1, 7], [15, 17, 1], [34, 15, 7], [26, 15, 34]]

# Pick off the 7th element of xyz;
xyz[7];

[HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]

# select all members of ch which contain the ordinal
# reference 7
T7 := select(c->member(7,c), ch);

[[1, 14, 7], [14, 5, 7], [5, 32, 7], [32, 34, 7], [15, 1, 7], [34, 15, 7]]

# Notice that xyz[7] is present in each of these
# lists of three 3-dimensional points. Each represents
# a 3-dimensional simplicial facet (ie. a triangle).
map(pt->print(xyz[pt]),T7):

[[HFloat(0.16564872949978093), HFloat(0.25750825412373646), HFloat(0.09713178123584754)], [HFloat(0.05395011866660715), HFloat(0.9597439585160811), HFloat(0.035711678574189554)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

[[HFloat(0.05395011866660715), HFloat(0.9597439585160811), HFloat(0.035711678574189554)], [HFloat(0.16218230819324275), HFloat(0.9592914252054443), HFloat(0.7060460880196088)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

[[HFloat(0.16218230819324275), HFloat(0.9592914252054443), HFloat(0.7060460880196088)], [HFloat(0.2435249687249893), HFloat(0.9502220488383549), HFloat(0.9133758561390194)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

[[HFloat(0.2435249687249893), HFloat(0.9502220488383549), HFloat(0.9133758561390194)], [HFloat(0.25428217897153105), HFloat(0.694828622975817), HFloat(0.9057919370756192)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

[[HFloat(0.07585428956306361), HFloat(0.49836405198214295), HFloat(0.6557406991565868)], [HFloat(0.16564872949978093), HFloat(0.25750825412373646), HFloat(0.09713178123584754)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

[[HFloat(0.25428217897153105), HFloat(0.694828622975817), HFloat(0.9057919370756192)], [HFloat(0.07585428956306361), HFloat(0.49836405198214295), HFloat(0.6557406991565868)], [HFloat(0.011902069501241397), HFloat(0.699076722656686), HFloat(0.6554778901775566)]]

# Instead of just extracting them, form polygon plotting
# structures from them instead. Again, notice that xyz[7]
# is a vertex of each of these triangles.
map(pt->plottools:-polygon(xyz[pt],transparency=0.5),T7);

[POLYGONS(Matrix(3, 3, {(1, 1) = .16564872949978093, (1, 2) = .25750825412373646, (1, 3) = 0.9713178123584754e-1, (2, 1) = 0.5395011866660715e-1, (2, 2) = .9597439585160811, (2, 3) = 0.35711678574189554e-1, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5)), POLYGONS(Matrix(3, 3, {(1, 1) = 0.5395011866660715e-1, (1, 2) = .9597439585160811, (1, 3) = 0.35711678574189554e-1, (2, 1) = .16218230819324275, (2, 2) = .9592914252054443, (2, 3) = .7060460880196088, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5)), POLYGONS(Matrix(3, 3, {(1, 1) = .16218230819324275, (1, 2) = .9592914252054443, (1, 3) = .7060460880196088, (2, 1) = .2435249687249893, (2, 2) = .9502220488383549, (2, 3) = .9133758561390194, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5)), POLYGONS(Matrix(3, 3, {(1, 1) = .2435249687249893, (1, 2) = .9502220488383549, (1, 3) = .9133758561390194, (2, 1) = .25428217897153105, (2, 2) = .694828622975817, (2, 3) = .9057919370756192, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5)), POLYGONS(Matrix(3, 3, {(1, 1) = 0.7585428956306361e-1, (1, 2) = .49836405198214295, (1, 3) = .6557406991565868, (2, 1) = .16564872949978093, (2, 2) = .25750825412373646, (2, 3) = 0.9713178123584754e-1, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5)), POLYGONS(Matrix(3, 3, {(1, 1) = .25428217897153105, (1, 2) = .694828622975817, (1, 3) = .9057919370756192, (2, 1) = 0.7585428956306361e-1, (2, 2) = .49836405198214295, (2, 3) = .6557406991565868, (3, 1) = 0.11902069501241397e-1, (3, 2) = .699076722656686, (3, 3) = .6554778901775566}), TRANSPARENCY(.5))]

# plot the xyz[7] point, and all the
# triangles that have it as a vertex.
plots:-display(
  plots:-pointplot3d(xyz[7],color=red,symbolsize=20,symbol=solidsphere),
  map(x->plottools:-polygon(xyz[x],transparency=0.5),T7),
  labels=[x,y,z], view=[0..1,0..1,0..1]
);

# plot all the points, and all the triangles (which
# make up the convex hull.
plots:-display(
  plots:-pointplot3d(xyz,color=red,symbolsize=20,symbol=solidsphere),
  plots:-display(map(pt->plottools:-polygon(xyz[pt],transparency=0.5),ch)),
  labels=[x,y,z], view=[0..1,0..1,0..1]
);

 

 

Download hull3D.mw

I suppose that you have already searched the FAQs.

You could contact Maplesoft Technical Support.

Be sure to let them know your Maple version, Operating System and version, and whether you are using any Maple "language packs".

Using concatenated names (which are always global) within procedures is poor programming practice, in my opinion.

Having said that,

restart

x := 3

A || 1 := 3

P := proc () local x; global y, z; x := 'x'; y := fsolve([x+5 = -2], {x}); A || 1 := cat(A, 1); z := fsolve([A || 1+5 = -2], {A || 1}) end proc

P()

{A1 = -7.}

A || 1

A1

 

Download Concatenate_Question_ac.mw

You could also use  cat(':-A',1)  for additional safety.

You can pick off those introduced (free) parameters, evaluate expressions (C, Q, other...) at arbitrary values for them, and so on.

Forcing the stem of the parameter name with the free option makes it easier to pick them off programmtically in the more general case.

Another choice is to use LeastSquares instead of LinearSolve, which will produce a single instance of the solution rather than a parametrized solution.

(I changed the first two entries of B, to make the LeastSquares result more interesting than the zero-Vector.)

restart

A := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 3, (1, 3) = 4.5, (1, 4) = 7, (2, 1) = 0, (2, 2) = 2, (2, 3) = 5, (2, 4) = 9, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0}); B := Vector(4, {(1) = 1, (2) = 2, (3) = 0, (4) = 0}); C := LinearAlgebra:-LinearSolve(A, B, free = F)

Vector[column](%id = 18446883819568535062)

params := [indets(C, 'specindex(posint, F)')[]]

[F[1], F[2]]

W1 := C[1]; W2 := C[2]; W3 := C[3]; W4 := C[4]; Q := W1*x^4+W2*x^3+W3*x^2+W1

(-HFloat(2.0)+HFloat(3.0)*F[2]+HFloat(6.5)*F[1])*x^4+(HFloat(1.0)-HFloat(2.5)*F[2]-HFloat(4.5)*F[1])*x^3+F[2]*x^2-HFloat(2.0)+HFloat(3.0)*F[2]+HFloat(6.5)*F[1]

map(`=`, params, 1)

[F[1] = 1, F[2] = 1]

eval(C, map(`=`, params, 1))

Vector[column](%id = 18446883819568524694)

eval(Q, map(`=`, params, 1))

HFloat(7.5)*x^4-HFloat(6.0)*x^3+x^2+HFloat(7.5)

A.C, B

Vector[column](%id = 18446883819568519038), Vector[column](%id = 18446883819672872470)

Alt := LinearAlgebra:-LeastSquares(A, B, method = SVD)

Vector[column](%id = 18446883819568516262)

A.Alt, B

Vector[column](%id = 18446883819568509646), Vector[column](%id = 18446883819672872470)

NULL

Download MultipleTCoefficients_ac.mw

restart;

local gamma: local phi:

sinc:=unapply(piecewise(x=0, 1, (sin(Pi*x))/(Pi*x)),x):
S:=unapply(sinc((x-k*h)/h),k,h,x):

a := -3: b := 4:
f:=unapply(x^2*t^3,x,t);

proc (x, t) options operator, arrow; x^2*t^3 end proc

phi:=unapply(log((x-a)/(b-x)),x):
gamma:=unapply(log(t),t):

teta:=2: Omega:=1:

w:=unapply(simplify(1/(D(phi)(x))^((teta-1)/2)),x):
v:=unapply(simplify((D(gamma)(t))^(Omega/2)),t):

k:=2: l:=1:
#hx:=1.282549830:
ht:=hx:

G:=Int((Int(f(x,t)*S(k,hx,phi(x))*S(l,ht,gamma(t))*w(x)*v(t),x=a..b),t=0..infinity)):

GG:=Int(t^3*S(l,ht,gamma(t))*v(t),t=0..infinity)*Int(x^2*S(k,hx,phi(x))*w(x),x=a..b):

combine(G-GG);

0

op(2,GG);
evalf(eval(%,hx=1.282549830));

Int(x^2*piecewise((-2*hx+ln((x+3)/(4-x)))/hx = 0, 1, sin(Pi*(-2*hx+ln((x+3)/(4-x)))/hx)*hx/(Pi*(-2*hx+ln((x+3)/(4-x)))))*sqrt(7)/(7*sqrt(-1/((x+3)*(-4+x)))), x = -3 .. 4)

5.148697506

#Int(t^3*sin(Pi*(-hx+ln(t))/hx)/Pi/(-hx+ln(t))*hx*(1/t)^(1/2),t = 0 .. infinity);
op(1,GG);
simplify(value(%)) assuming hx::real;

Int(t^3*piecewise((-hx+ln(t))/hx = 0, 1, sin(Pi*(-hx+ln(t))/hx)*hx/(Pi*(-hx+ln(t))))*sqrt(1/t), t = 0 .. infinity)

undefined

 

Download doubleint1.mw

If I understand your goal correctly, the coordinates of the cells are present in the plot structure computed by the VoronoiDiagram command.

They are Matrices, but you could convert them to listlist.

Let us know if you have difficulty converting or manipulating them into some other form. Please be specific in details, though. If you want them merged, without repeats, into one big flat list of points then that could be done -- though if there are very many original data points it computed be computed more efficiently in a more direct manner (via Delaunay triangulation, say), without going through production of the full diagram/plot.

Here is an example, separating then according to the color.

restart;

with(ComputationalGeometry):

m:=LinearAlgebra:-RandomMatrix(7,2,generator=0.0..1.0):

P:=VoronoiDiagram(m,symbol=solidcircle,symbolsize=7,size=[300,300],axes=boxed):
P;

V:=[op(indets(P,specfunc(anything,POLYGONS)))]:

T:=ListTools:-Classify(u->op(2,u),V):

Tinds:=indices(T,nolist);

COLOUR(RGB, .47058824, 0., 0.54901961e-1), COLOUR(RGB, .29019608, .47058824, 0.), COLOUR(RGB, 0., 0.54901961e-1, .47058824)

ColorTools:-Color(Tinds[1]), map[2](op,1,T[Tinds[1]]);

"<RGB : 0.471 0 0.0549>,{[[[0.674755640087579,0.528416189867507],[0.774429137959799,0.760000722399843],[0.565091023500541,1.70390300233302],[0.278700624534252,0.573844297940794]]],[[[0.781700218780773,0.381772909439530],[4.66209503332205,0.337974064337378],[3.70924190390966,-0.608387011801836],[0.716780642385679,0.176311320824582]]]}"

ColorTools:-Color(Tinds[2]), map[2](op,1,T[Tinds[2]]);

"<RGB : 0.29 0.471 0>,{[[[0.278700624534252,0.573844297940794],[-2.20505390543617,-0.708421311778174],[-3.70554867069412,0.505458130569214],[0.564102931719082,4.77510973298241],[0.593861093166918,4.73834981392173],[0.565091023500541,1.70390300233302]]],[[[0.716780642385679,0.176311320824582],[-0.359151757230016,-2.62884825842281],[0.564102931719082,-3.76574686098490],[3.70924190390966,-0.608387011801836]]],[[[0.674755640087579,0.528416189867507],[0.781700218780773,0.381772909439530],[4.66209503332205,0.337974064337378],[4.85550306716113,0.505458130569214],[4.39299635377559,0.933178173190759],[0.774429137959799,0.760000722399843]]]}"

ColorTools:-Color(Tinds[3]), map[2](op,1,T[Tinds[3]]);

"<RGB : 0 0.0549 0.471>,{[[[0.674755640087579,0.528416189867507],[0.781700218780773,0.381772909439530],[0.716780642385679,0.176311320824582],[-0.359151757230016,-2.62884825842281],[-2.20505390543617,-0.708421311778174],[0.278700624534252,0.573844297940794]]],[[[0.774429137959799,0.760000722399843],[4.39299635377559,0.933178173190759],[0.593861093166918,4.73834981392173],[0.565091023500541,1.70390300233302]]]}"

 

Download Voronoi_cells.mw

First 107 108 109 110 111 112 113 Last Page 109 of 336