acer

26362 Reputation

29 Badges

16 years, 319 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Spirithaunter What is the point of stating that the location of a local declaration causes an issue in your own version of Maple without telling us what version it is?!

The code I posted can be adjusted easily to declare locals at the start of the procedures, if that was an issue for your version. That issue can be removed simply by changing the line,
   Basenwechsel:=proc(Dividend, m);
to instead be,
   Basenwechsel:=proc(Dividend, m)
since older versions (like, say, Maple 16) would reject the local declaration after the first statement terminator.
   Basenwechsel_ac2.mw

The code I posted already showed an alternate mechanism for a recursive call (procname).

There is no point in saying that you "corrected" my code without supplying what you did. How can I tell whether or not you made the same fundamental mistake as origianlly?! (You can use the green up-arrow in the Mapleprimes editor to upload and attach a worksheet. Please do so.)

I stand by my claim that your original code is confused by using the procedure's own name as an implicit local within itself as well as in a recursive call to itself.

I disagree that you should add explicit local declarations only when all else is finished and working properly. The code is already a heaving morass of print statements and obfuscated programming. Start (not finish) by correcting its structure and process.

Also, it's quite unclear how your code is supposed to work. It's entirely possible that there are other problems and coding mistakes remaining.

@janhardo I disagree with the idea the tasks in the exercises are "often" made more clear through the use of arrays.

There are lots of good programming exercises for which arrays can be an important part. But the majority of the exercises in the book are something else.

These considerations are not about memory demands or restrictions.

So, are you asking for a simple way to do only what is required by the textbook question, and to do it specifically in the Array & loop approach the authors prefer?

If not the you could use the RiemannSum command from the Student:-Calculus1 package, which can produce computational sums as well as plots of the various approximations, etc.

As with your previous Questions, I'm not sure that I see the point of your book's exercises. It doesn't seem to show the calculus details clearly or directly, as it's muffled by the longwinded programming approach. And it wasn't very effective or good Maple technique even in 2002.

Here is a relevant quote from the preface of the book you've been using (emphasis and italics by authors):

   It is appropriate to stress here that this book is NOT for learning
   how to use Maple, but rather for learning how to write and construct
   computer programs.
We expect that the general programming principles
   learned in this book will greatly help students in their programming
   courses (eg. in C, Pascal, FORTRAN) particularly in their ability to
   analyze and write complex algorithms.

Why not show us exactly what you tried.

You can upload and attach a Document or Worksheet.

Upload and attach the Document in which this occurs.

Posting an image of a Document is much less useful than posting the Document itself.

@mmcdara I am unable to download your attachment, possibly due to the choice of file name.

I have a few different and reasonably efficient ways to shade a 2D region (with a pretty smooth gradient).

But the OP did not explain what manner of shading he wanted. He mentioned a 1D domain, and I just happened to give three shadings of curves based on that domain, as well as one shaded 2D region. But we cannot as yet know what he wanted.

The problem occurs if the overloaded export procedure does not have a fallback procedure that lacks option overload.

LinearAlgebra:-Multiply and LinearAlgebra:-Add have such a procedure in their overload definition, and do not exhibit the problem.

LinearAlgebra:-CompanionMatrix and LinearAlgebra:-MatrixInverse lack such a procedure in their overload definition, and both exhibit the problem.

I haven't seen a non-overloaded procedure with the problem (so far).

Since the problem occurs even when there is a procedure that matches the argument type then I think that this is a kernel bug related to overload. If it's deemed necessary or desirable kernel behavior then I think that Library routines like MatrixInverse should be adjusted to accomodate it.

restart;

M:=module() option package;
  export e,f,g,h;
  e := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::negative) option overload; x; end proc ]);
  f := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::negative) x; end proc ]);
  g := overload([
         proc(x::positive) option overload; x^2; end proc ]);
  h := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::odd) option overload; x^3; end proc,
         proc(x::negative) x; end proc ]);
end module:

with(M):

proc() uses M; e(3); end proc();
proc() uses M; e(-3); end proc();

e(3)

e(-3)

proc() uses M; f(3); end proc();
proc() uses M; f(-3); end proc();

9

-3

proc() uses M; g(3); end proc();
proc() uses M; g(-3); end proc();

g(3)

g(-3)

proc() uses M; h(3); end proc();
proc() uses M; h(-3); end proc();
proc() uses M; h(-4); end proc();

9

-27

-4

 

Download overload_fun2.mw

Please don't post a duplicate of this for your specific textbook example. Put the example in this Question thread, instead.

You should either read the relevant documentation and Help pages, or provide us with the full details of your example.

What have you tried, so far?

@radaar If the Hessian has both positive and negative eigenvalues then the point is a saddle point.

If the Hessian's eigenvalues are all positive then the point is a local minimum. If the Hessian's eigenvalues are all negative then the point is a local maximum.

If the Hessian is positive-semidefinite or negative-semidefinite then the test is inconclusive.

@Adam Ledger You wrote, "...MTInterface has no arguments." That is incorrect terminology. What you may have intended to convey was that the procedure is defined with no parameters.

Lots of Maple procedures are defined with no parameters. And when they get called with arguments then those arguments can be accessed by the procedure in a few ways.

For example,

f := proc()
  print( nargs );
  print( seq( args[i], i=1..nargs) );
  print( _npassed );
  print( _passed );
end proc:

f( a, 4, b, 7.2 );

                       4
  
                  a, 4, b, 7.2

                       4

                  a, 4, b, 7.2

See the Help pages under Topic procedure for details.

The procedure about which you were asking used the _passed facility to reference the passed arguments.  See the line that contains procname(_passed) .

I think that you'll need to understand the basics before trying to understand advanced examples. Also, not every internal procedure is implemented in the Library in interpreted code.

@panke To address your dsolve followup question, look at my Answer's third example (as I suggested above).

restart

RMP := proc (sl, t1, A1, t2, tau) local y; if not type(tau, numeric) then return ('procname')(args) end if; if t1 < tau and tau <= t2 then y := A1 end if; return y end proc:

ode := diff(x(t), t) = RMP(2, 3, 3.7, 5, t);

diff(x(t), t) = RMP(2, 3, 3.7, 5, t)

sol := dsolve([ode, x(0) = 0], numeric, range = 0 .. 6, known = [RMP]):

plots:-odeplot(sol);

 

Download plotproc_dsolve_ac.mw

I assume that this is merely a simple example of the concept, and that you may have some additional example in which the known procedure is more involved (and careful in how it handles all possible cases). Otherwise you could have used another, simpler mechanism for the piecewise effect.

@panke You haven't explained how you wish to use it, in detail, so you leave it up to us to guess.

I am guessing that you want to use it like a known function, in a call to dsolve(...,numeric) and that you could try the last of the ways I showed. I mean the example where RPM2 returns 'procname'(args) if tau is not of type numeric. Of course you can rename the procedure, or not.

I assume that this is merely a simple example of the concept, and that you may have some additional example in which the known procedure is more involved (and careful in how it handles all possible cases). Otherwise you could have used another, simpler mechanism for the piecewise effect.

As usual, you have left out the important details of your question.

Is your interest in univariate of multivariate functions?

Are you looking for exact results, or numeric approximations?

Are you looking for all solutions, or just a finite number (eg, one)?

Do you have a candidate example that has some special difficulty?

@naili You are treating your F as if it were a procedure/operator, but you defined it as an expression in x and y but not as a procedure/operator.

This would work, defining F as an operator.

restart;
F := (x,y) -> (sin(sqrt(x^2+y^2)))/(sqrt(x^2+y^2));
h := F(x, -1.8);
ListeHy := [seq(h, x = -10..10, 1.0)]:
ListeHx := [seq(x, x = -10..10, 1)]:
HxHy := zip(`[]`,ListeHx,ListeHy);
polyInterHxHy := CurveFitting:-PolynomialInterpolation(HxHy, x):
plotHxHy := plot(polyInterHxHy, x = -10..10, size=[400,400]);

And this would also work, with F just as you had it, ie. an expression in x and y.

restart;
F := (sin(sqrt(x^2+y^2)))/(sqrt(x^2+y^2));
h := eval(F, [y=-1.8]);
ListeHy := [seq(h, x = -10..10, 1.0)]:
ListeHx := [seq(x, x = -10..10, 1)]:
HxHy := zip(`[]`,ListeHx,ListeHy);
polyInterHxHy := CurveFitting:-PolynomialInterpolation(HxHy, x):
plotHxHy := plot(polyInterHxHy, x = -10..10, size=[400,400]);

Notice that h is the same in both versions, and so is all that follows the definition of h. It's just the first two lines that are different. Run both, and look carefully at the input and the output of the first two lines.

An operator is just a special, simplie kind of procedure that prints and can be defind with an arrow.

First 70 71 72 73 74 75 76 Last Page 72 of 489