acer

23885 Reputation

29 Badges

16 years, 67 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@tomleslie Unfortunately the OP has omitted the context in which his piece of code made better sense. What a shame.

I suspect that the context was such that the upright roman characters were desirable, and in which the goal was to prevent reformatting (in another notation) of the floating-point value by the interface. Perhaps it was connected to text appearing in a plot.

@mmcdara In your followup's second example the term sin(X(t)) appears in the result, whereas in your followup's first example k*X(t) does not appear in the result. Hence you see the psi in the second, but not phi in the first.

If you don't want psi to appear then you could remove the alias. (I'm not sure I understand when you do or do not want the effect of the alias in output, given both your original question and your followup.)

restart;

alias(X = X(t)):
alias(Phi=Phi(X(t))):
alias(psi=k*X(t)):

value(eval((Diff(Phi, t, t), Phi=psi)));

k*(diff(diff(X, t), t))

restart;

alias(X = X(t)):
alias(Phi=Phi(X(t))):
alias(psi=sin(X(t))):

expr := value(eval(Diff(Phi, t, t), Phi=psi));

(diff(diff(X, t), t))*cos(X)-(diff(X, t))^2*psi

alias(psi=psi):

expr;

(diff(diff(X, t), t))*cos(X)-(diff(X, t))^2*sin(X)

Download alias_ex2.mw

You wrote, "I want each element in the array to be an empty list, so I can later add to it."

That is inefficient, and not sensible, since a list is not really a mutable data structure.

@janhardo 

restart;

 

SumList:= proc(L::list)
  local S, i;
  S := 0;
  for i from 1 to nops(L) do
    S:= S + L[i];
  end do;
  return S;
end proc:

 

SumList( [13, 4, 26, -3] );

40

SumList:= proc(L::list)
local S, i;
  S := 0;
  for i from 1 to nops(L) do
    print(sprintf("adding element L[%a]=%a, to %a", i, L[i], S));
    S:= S + L[i];
    print(sprintf("sum so far is %a", S));
  end do;
  return S;
end proc:

 

SumList( [13, 4, 26, -3] );

"adding element L[1]=13, to 0"

"sum so far is 13"

"adding element L[2]=4, to 13"

"sum so far is 17"

"adding element L[3]=26, to 17"

"sum so far is 43"

"adding element L[4]=-3, to 43"

"sum so far is 40"

40

Download SumList.mw

@vv Sure, and the given Wind procedure can only handle vertical and horizontal lines (which the starting values for the red vertices happen to incur). It might be extended to check for the blue point being on (or close enough) to any of the line segments no matter the slope.

If we allow only  the blue test point to be mouse-dragged, then it can be done with discretized values.  explore_wind_ac2.mw

@vv That is fun.

Attached is a variant in which the red and blue points can be dragged around with the mouse. (I used Maple 2021.1)

explore_wind_ac.mw

@Jean-Baptiste R I'm glad that you're able to make progress.

But note that the alteration sought here is not really a "factorization".

If I do a google search for "efficient polynomial evaluation" then the second hit is to Horner's Method.

Here's another approach, which sometimes turns up something useful,

expr := a*x+6*x^2-10;

a*x+6*x^2-10

codegen['optimize'](unapply(expr,x),'tryhard')(x);

-10+(a+6*x)*x

Download code_opt_fun.mw

Please don't start an entirely new thread on the same question.

@Ronan You speak of a "package", and use the word "export". But in the context of packages the word "export" has a very special meaning for procedures. Apparently you don't intend that meaning.

Your followup Reply indicates that you want to be able to provide the procedure's as source code. Thank you.

It's not clear what you mean here by "export".

What value did you obtain using Matlab?

How accurate do you think it is?

@janhardo I'll add another reason, which is perhaps the most important:

Many important packages in Maple use Vector/Matrix/Array. Most if not all of the few packages (eg. linalg) which use vector and matrix are themselves deprecated, as are those structures.

For linear algebra you might also look at an example worksheet on migrating from linalg to LinearAlgebra, which is also directly accessible in your Maple's Help system.

If you have additional problematic examples then feel free to ask about them.

@tomleslie The OP had previously expliciyly mentioned the PointInPolygon command, and also the fact that it isn't present in his Maple 2018.

@animeplot It's possible to implement an algorithm for it, as a procedure.

If I recall correctly, the (new, as of Maple 2020) PointInPolygon command of the ComputationalGeometry package implements the Winding Number algorithm (a.k.a. Nonzero-rule). It might even be an implemention of this variant.

It might be fun to try also the Ray-casting algorithm. Maple's variable precision floating-point arithmetic might even be used to make that more numerically robust.

@Carl Love Using your IsInInterior approach, this incorrect result is returned,

PS:= PolyhedralSets:
PS:-IsInInterior(
    PS:-PolyhedralSet([[300,300]]), #point being tested
    PS:-PolyhedralSet(
        [[0,0],[200,0],[200,300],[250,400],
        [500,300],[500,500],[0,500]
    ])
);

               true

plots:-display(
plots:-pointplot([[300,300]],color=red,symbol=solidcircle,symbolsize=15),
plots:-display(plottools:-polygon([[0,0],[200,0],[200,300],[250,400],
        [500,300],[500,500],[0,500]]), color=yellow), size=[350,350]);

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