acer

32343 Reputation

29 Badges

19 years, 328 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Feel free to add to the original Question, by editing it or posting a Comment/Reply. Don't delete the full body of the original question. Here it is below:

1. Consider this code line: > a := b; b := c; c := matrix([[1, 2, 3], [3, 4, 5]]);
    • if you ask Maple to return the values assigned to a, b and c, which values will be printed?
    • Are these values the ones you would expect? Why? Which kind of evaluation rule is utilized by Maple to return these values?
   • Show the single steps of the evaluation process and briefly explain the outcome of each evaluation step (hint: use eval (a, 1/2/3), to return each evaluation step).
   • How can you “force” Maple to return the “expected” values for a, b and c? • Extract the first row of the matrix in such a way to have [1, 2, 3] as output. Hint: use the command row/Row and its right syntax (it needs two arguments: the name of the matrix and the number of the row to extract). Be careful to load the linalg/LinearAlgebra package before using the command. Instruction: apply the row/Row command to a, b and c.
  • Can you explain what Maple does in the previous step? Can you explain, in other words, why you get the expected outcome? Hint: remember which are the “drivers” of the evaluation process in Maple (position of the assignment/level of evaluation; type of object / data-structure / datacontainer / procedures / local versus global variables / use of built-in commands, etc.).

Duplicate postings of this in other Question threads will be flagged as such and may be deleted.

How far have you gotten so far with this coursework task?

Have you succeeded in "writing a utility procedure called CoeffList that converts a Maple polynomial into a list of its coefficients"?

@Carl Love In my Answer I used a nontrivial example instead, in which there is a possibility of optimization in computing the entry values. For a Matrix return (in the Maple language) the optimize option does not act, but it does for a listlist. And for both kinds of Maple structure the Matlab return structure is of the same kind. And so there can indeed be merit to passing the option.

@tomleslie Your comment is also about a situation related to need of local declaration, but a different situation, that is quite different from that of the OP which is primarily about the status of procedure parameters.

I just happened to make an aside, in my Answer, about an unused local and which of nm's two procs was "better". But IMO that really wasn't the central topic of the Question. (Joe's Answer also is about unused locals which -- while checking for such relates to the latter, lesser part of the Question in a roundabout causal way -- otherwise doesnt explain the primary Question asked, IMO.)

You can put your other examples in a Comment or Reply or addendum to the original Question.

Don't delete the original!

@mmcdara Equation labels can appear on output of "executable 2D Math". I believe that the OP knows this, and has instead asked for convenient labeling of non-executable (inlined) 2D Math. So, I don't see how your comment relates to the request.

It might suffice (as far as the OP is concerned) to output expressions protected against values being assigned to any unknowns, and also with input suppressed. That's possible, but awkward to explain.

@chelchax It was clear upon first read that the code you posted was muddled about the roles of h and N (with initial point a and target end-point b also supplied).

Those four quantities are related mathematically. You cannot (logically) force your own choice for all four of them at once. At least one of them needs to depend formulaically upon the others.

You subsequently added a followup Comment/Reply stating that you intended to force values for h the stepsize. That's quite natural, IMO, and a common way to code this task. Hence I revised the procedure RK4 so that -- given a supplied stepsize h and end points a,b -- it would compute an N that fit closest to target b without going past. It doesn't matter whether N is computed in the body of RK4, or in the call to it. What matters is here is that N depends on h,a, and b. It also doesn't matter much to this aspect of the argument whether you take the floor gettting almost up to b, or take the ceil to get just past b.

The image of the code that you now show does it the other way. It computes the stepsize h depending on a,b and N. That's not wrong, though IMO it looks a little awkward. It's a trivial adjustment to the code and you ought to be able to accomplish it. But you should realize that you would subsequently utilize the ensuing procedure by forcing (supplying, passing) a value for N rather than for h (since it really doesn't seem useful to have the end-point b be dependent and not specified by you). That contradicts your earlier stated requirement of intending to specify h the stepsize.

Does all that make sense?

Which do you prefer?

You could even have code that did it either way (dependent h, or dependent N), according to some option passed to the procedure. But you can't logically specify forced values for all of a,b,h, and N together.

@Trebron Here is one way to get to your new goal:

T:=table([.6, 1.2, 2.0, 3.3, 4.1, 5.0, 5.5, 5.8]):

plot([seq([i, T[i+1]], i=0..nops([entries(T)])-1)]);
plot([seq([i, T[i+1]], i=0..nops([entries(T)])-1)], style=point);

(I don't understand why you did not provide all additional information when you first asked the Question.)

[edit] The code above is, in my opinion, quite straightforward and should be understandable to a beginner in Maple. There are many other ways to accomplish the given task, including some with very fancy/slick functional programming -- which I don't think is best for a beginner in Maple.

@chelchax Please don't repost duplicates of this. Duplicates will be flagged as such, and may be deleted.

Followup details are useful, and can be placed here (as Comment/Reply on the Question or one of its Answers).

You may need to have a little patience.

What progress have you made so far, on this?

If it's really a table then it has indices as well as entries. What are they?

If it's not actually a table (ie. a list or something else) then please show the details. You can upload a worksheet here using the green up-arrow in the Mapleprimes editor.

Please make sure to explain what kind of plot you want to produce.

@Kitonum I did consider whether to present exact values. I chose on purpose to compute with floating-point values.

I also chose deliberately to show several more steps than necessary.

It's often difficult to gauge what some particular Asker will find more useful and instructive, based only on a few lines of a Question.

 

@raj2018 Please don't repost this in other Question threads.

@dglevitt

This is a link.

First 148 149 150 151 152 153 154 Last Page 150 of 592