acer

32343 Reputation

29 Badges

19 years, 327 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@vs140580 You can specify the used symbol, and its symbolsize, and its color. (If you look at the linked Help page I gave before you would see all these options described.)

F2d:=Statistics:-LinearFit(a*x, pts[..,[1,2]], x):
plots:-display(
  plot(pts[..,[1,2]],
       style=point, color=red,
       symbol=solidbox, symbolsize=15),
  plot(F2d,
       x=min(pts[..,1])..max(pts[..,1])),
  labels=[x,y], axes=box);

I don't understand what you mean by having a legend for such points. What would it show!?

For fun, as an alternative to regression in 3D is to interpolate. (The fitted curve from the previous regression doesn't pass through the points exactly, although the plane surface is optimized to reduce the error. The following interpolated curve passes through the data points.)

Ip := Interpolation:-RadialBasisFunctionInterpolation(pts[..,1..2],pts[..,3]):
plots:-display(
  plots:-pointplot3d(pts,color=red,symbol=solidsphere,symbolsize=12),
  plot3d(Ip(x,y),
       x=min(pts[..,1])..max(pts[..,1]),
       y=min(pts[..,2])..max(pts[..,2]),
       color=gray),
  tickmarks=[4,4,3], size=[600,600],
  labels=[x,y,""], lightmodel=none, axes=box);

regr_3d2d_2.mw

@vs140580 You can adjust the overall plot size using the size option, and one way to adjust the tickmarks is to use the tickmarks option.

For example, using that data in pts,

plots:-display(
  plots:-pointplot3d(pts,color=red,symbol=solidsphere,symbolsize=12),
  plot3d(F3d,
       x=min(pts[..,1])..max(pts[..,1]),
       y=min(pts[..,2])..max(pts[..,2]),
       color=gray,style=surface,transparency=0.1),
  tickmarks=[4,4,3],
  labels=[x,y,""], lightmodel=none, axes=box, size=[600,600]);

And using your latest Reply's data, that same command produces this:

I believe that you could figure this out after reading the Help pages on the links I included.

Below I asked you whether you are trying to perform regression on this data. Are you?

Please don't post that as a separate Question thread. Duplicates get flagged as such and may be deleted.

@vs140580 Your goals are unclear. Is there a reason why you cannot state exactly what you are trying to accomplish!?

pts:= Matrix([[19.8,12, 1.62],[24.7,14, 1.2],
                   [26, 16, 1.25],[35.1,20, 0.84],
                   [37.8,20.83,0.74],[10.8,9, 3.98],
                   [16.1,12, 2.46],[38.3,18, 0.52],
                   [24.5,16, 1.42],[15.8,11, 2.35],
                   [28.2,17.8, 1.19],[56.8,27, 0.37],
                   [25.4,17, 1.34],[29.3,18.1,1.12]]):

I don't see how the formula f that you gave relates to the given data points. Are you trying to plot them together?

f := 72.7*x-24.5*y:
plots:-display(
  plot(pts[..,[1,2]],style=point),
  plot([solve(f,y)],
       x=min(pts[..,1])..max(pts[..,1])),
  labels=[x,y], axes=box);

Was your formula for f just an example? Are you trying to do (linear) regression/curvefitting of the x-y points in your data, ie. regression using the first two columns?

F:=Statistics:-LinearFit(a*x, pts[..,[1,2]], x);

plots:-display(
  plot(pts[..,[1,2]],style=point),
  plot(F,
       x=min(pts[..,1])..max(pts[..,1])),
  labels=[x,y], axes=box);

@mmcdara I suspect that the line with,

    if dnew < 5 then  return i 

is there to find the (first, if any) existing point that is within sqrt(5) distance from the clicked point.That would contrast with your approach to accept always the closest existing point, regardless.

And since a table is a mutable data structure you can add/remove from it with less garbage production. Augmenting a list (or subsop'ing with NULL) creates a new list each time, and the old list becomes collectible garbage. Just my guess, as to motive. As you suggest, with a very small number of points such considerations might have small impact. (...and a collectible/transient structure might be needed for sending to the plot command, anyway.)

@vs140580 Do you mean something like these?

restart;

f := 72.7*x-24.5*y;

plots:-implicitplot(f, x=-2..2, y=-5..5,
                    rangeasview, labels=[x,y], axes=box);

plot([solve(f,y)], x=-2..2,
     view=-5..5, labels=[x,y], axes=box);

@Idontcare I really think that you should not use the approach of entering 3 or more expressions separated by =, in 2D Input mode.

The 2D Parser turns something that looks like this,

   -a*b + a*c = -a*b + a*c = a*(c - b)

into the following (Maple plaintext code),

   -a*b + a*c = -a*b + a*c and -a*b + a*c = a*(c - b)

That lowercase and makes Maple test each of those equations in the same way that evalb works, including this second one,

   -a*b + a*c = a*(c - b)

and that returns false because the lhs and rhs are not numeric and also not the identically same symbolic expression. They are the same mathematically, but not structurally. That's why evalb is not the appropriate mechanism for you. See my examples above in my original Answer.

I think that entering such conjoined multiple `=` statements in 2D Input mode is a very poor approach. I think that you would be much, much better off using the approach of assigning single equations (two expressions on either side of an = sign) to various new variables, and then testing them in one of the successful ways that I showed above in my original Answer.

In the long run, you will be much better off learning commands, and learning Maple as a plaintext programming language. I also suggest you consider using 1D Maple (plaintext) notation inside Execution Groups of a Worksheet instead of the (default, sigh) 2D Input mode in a Document.

@mmcdara You're welcome.

Here is a slight revision in which the radio-buttons both set a value of a module local, which denotes the adding/removing mode's status (ie. a boolean). One advantage of this approach is that it makes it easier to test the action code separately from any button/plot clicking. In some advanced applications that can sometimes be convenient.

sketch_ac2.mw

Let us know if you plan on creating a procedure that build/inserts this whole assembly, using DocumentTools:-Layout/Components. In that case there are a few tricks that make it possible to embed multiple instances of the application (on the fly in the same worksheet) which each utilize the same Bez module runtime but whose buttons/plots act independently of each other.

ps. I didn't mention that a full sort is higher computational complexity than necessary for determination of the position in the point-list of the closest match. I'm sure you know that already, and only wanted a short snip of code that made the example work. The embedded component programming is the question here.

@tomleslie You wrote, "Unfortunately the 'size' option is not available for 3D plots:-("

But support for the size option for 3D plots was introduced in Maple 2020. The plot3d and plots:-display command now accept it.

 

@Idontcare I can't say for sure because you still haven't shown us your explicit example  so I don't know what exact commands you're using and how.

You can upload and attach a worksheet here using the green up-arrow in the Mapleprimes editor.

In a closely related followup Question of yours (appearing a day or so after this Question) you mentioned that you were substituting initial conditions into a candidate ode solution using the subs command.

A plain subs call is generally an ill-advised way to do that, and generally inferior to using the eval command. Unevaluated syntactic/structural substituion is not the same as mathematical evaluation at a point. (Now, there may be some examples for which limit is a better choice for doing that substitution. But that's another story.)

Consider the following example, using something akin to your followup example.

restart;

proc() local tmp_1, f;
  f:=1 = 5/4*exp(a)+1/4*piecewise(a <= 1,-1,1 < a,exp(b));
  tmp_1:=subs([a=0,b=-2],f);
  lprint(tmp_1);

  is(tmp_1),
  is(simplify(tmp_1)),
  is((rhs-lhs)(tmp_1)=0),
  is(simplify((rhs-lhs)(tmp_1)=0)),
  evalb(simplify((rhs-lhs)(tmp_1)=0)),
  is(expand(tmp_1));
end proc();

1 = 5/4*exp(0)+1/4*piecewise(0 <= 1,-1,1 < 0,exp(-2))

              FAIL, FAIL, FAIL, FAIL, false, true

It should not come as a surprise to you that subs does not evaluate, following the substitution. (There are a few other advantages to using eval rather than subs here, but evaluation is the main one.) It should also not come as a surprise to you that assigned locals get only 1-level evaluation inside a procedure body. I know that you've seen both of those things before, in the many years you've been asking questions on this forum.

restart;

proc() local tmp_1, f;
  f:=1 = 5/4*exp(a)+1/4*piecewise(a <= 1,-1,1 < a,exp(b));
  tmp_1:=eval(f,[a=0,b=-2]);
  lprint(tmp_1);

  is(tmp_1),
  is(simplify(tmp_1)),
  is((rhs-lhs)(tmp_1)=0),
  is(simplify((rhs-lhs)(tmp_1)=0)),
  evalb(simplify((rhs-lhs)(tmp_1)=0)),
  is(expand(tmp_1));
end proc();

1 = 1

               true, true, true, true, true, true

You suppressed the output of the assignment to tmp_1 in your standalone top-level example, by terminating the statement with a full colon. That's not prudent here. If you hadn't then you might have noticed that it wasn't actually testing the identical expression that you saw in the debugger.

restart;

tmp_1 := 1 = 5/4*exp(0)+1/4*piecewise(0 <= 1,-1,1 < 0,exp(-2));

                      tmp_1 := 1 = 1

is(tmp_1),
is(simplify(tmp_1)),
is((rhs-lhs)(tmp_1)=0),
is(simplify((rhs-lhs)(tmp_1)=0)),
evalb(simplify((rhs-lhs)(tmp_1)=0)),
is(expand(tmp_1));

           true, true, true, true, true, true

@nitins Sorry, I do not have time to answer this. Someone else might.

Please don't post it as a separate Question thread, which may be flagged as a Duplicate and deleted.

@luthfiirsyad26 I see, thanks. So it seems as if my guess lambda=0.01..0.1, a=0.1 ..2.1 for the ranges was not way out.

@luthfiirsyad26 You didn't answer: what are known ranges for parameters `lambda` and `a`? 

Please put your followup expositions here, instead of as separate threads with repetitive variations.

First 130 131 132 133 134 135 136 Last Page 132 of 592