acer

32333 Reputation

29 Badges

19 years, 323 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@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]);

@C_R This approach happens to work for this example, but in general it is faulty because it does not account for the possibility that mixed units are present, eg. millimeters and meters, possibly in different elements of say a list. For such examples this approach can produce a wrong result.

edit. In general it is better to first change to common units for the given dimensions, to avoid such mismatches in scale. Some ways to accomplish that preliminary step involve utilizing combine(...,'units') or simplify.

@tomleslie Your code has,

  title=typeset( "Opt x= %1, r=%2, Area = %2", x, r, A(x,r))

but perhaps you intended,

  title=typeset( "Opt x= %1, r=%2, Area = %3", x, r, A(x,r))

using %3.

I had trouble searching by author.

Additionally, when the mouse goes over a tile it goes all blue. I don't find that useful or appealing. It also prevents me from right-click-opening the link to the author's name.

First 119 120 121 122 123 124 125 Last Page 121 of 591