Hey
I was discusing Maple and Matlab with one of my friend.
He said that in Matlab he can do
a:=1:12
b:=sin(a)
plot(a,b)
that's easy in matlab to do so
i use
> ptlist:=NULL:
> for n to 12 do
> ptlist:=ptlist,[n,sin(n)]:
> od:
> plot([ptlist]);
do to so
is there any easy way to do that in maple?
like creat a sequence from 1 to 12? ( besides seq(n,n=1..12))
thanks
Using seq, after all
Try the following:
PS: It does use
seq, which you seem to exclude, but it is shorter and faster than yourfor-loop construction.Keeping it Linear
While probably not of immediate interest to the original poster, the reason the loop can be much slower is not so much because it is an external loop, but rather because it is being used to build up a sequence term by term. Each intermediate term is stored in Maple's simplification table, so, after n loops, it looks like
This is an O(n2) process. By inserting the terms into a table in the loop, and then converting to a list at the end, this becomes O(n). Conceptually,
Of course, if one can generate the list with one call to seq, that is usually better, however, sometimes it is more convenient to use the imperative style and write a loop.
Another way
I too would favour the solution using seq, but you could also do something like this:
> plots[listplot](map(sin, [$1..12]));
the obvious solution
Actually, what we would really do is simply
which is shorter and nicer than what is required in Matlab. No use plotting vectors/lists if you can use Maple's adapative plotting capability. Just because Matlab is restricted to plotting vectors doesn't mean that that is the best way to go.
Intention
But is that what the author was asking for? Your suggestion produces, of course, a smooth plot, while his produces a piecewise linear plot.
i think all of you got a
i think all of you got a nice idea of doing it
however
i think may be what my friend what to do with maple is :
suppose he has got several set of data
a:=set of data
b:=sin(set of data)
c:=cos(set of data)
3d plot
is there any simple way to do so?
not like smooth plot liek plot( sin,1..12), thanks anyway
======================
For Maple on MAC
how do i open classical worksheet if it is not on the desktop?
An attempt
I would do something like
s := {seq}(i,i = 1..5000): plots[pointplot3d](map(x -> [x,sin(x),cos(x)],s));which produces the following plot:
yep thanks "map" is always
yep
thanks
"map" is always very handy though i didnt use it very often. I will try to use that more often
=============
For Maple on MAC
how do i open classical worksheet if it is not on the desktop?
Mac
There is no Classic interface for the Mac. You can, of course, open a Classic worksheet (.mws file) with the Standard interface.
tweaks
Hi John. A minor "improvement" is to use the one-argument form of seq:
s := {seq(1..5000)};It is unfortunate that Maple does not have a builtin identity function (I've lobbied for `()`, as it is analagous to `[]` and `{}`). If it did you could do
This can be done with the user-defined one-argument identity
but I prefer the look of an argumentless operator. By the way, here is the first assignment using `{}`:
s := `{}`(seq)(1..5000);I somehow expected it :-)
I was working in Maple 9.5, where
s := {seq(1..5000)};is not possible, and I did not bother to fire up Maple 11, to ascertain the shorter syntax, so I just decided to write it using the old syntax even though I knew that it probably would be commented on. I apologize for that inconvenience.
I like your idea, by itself, of using
()as the identity map, but also because I like the simplicity of your expressionAnother approach
I agree that it is not always appropriate to try to use the same approach to a problem in different software systems. Each system has its own strengths and these need to be taken into account. The different approaches suggested for this problem are all reasonable.
But, nobody has yet presented what is the most appropriate way to approach this problem.
Note that Maple makes a distinction between a set and a list. In most cases like this, a list (with order) is what users want. Sets (without order) do have their uses, but you have to be careful to select the right data structure for the right problem.
To close, I would note that I would create this specific plot without explicitly constructing the data:
I hope this is helpful,
Doug
$ and seq
This particular procedure, pointplot3d, can take either a set or a list. While it doesn't matter here, because all points are distinct, it is conceivable that a set could be an advantage because it would eliminate redundant points. However, I suspect pointplot3d converts to a set anyway.
While the $ operator is more compact, the seq function is generally preferred. It is more efficient (doesn't matter here). Actually, there isn't any reason to use the $ in your example, since you already call seq (see below). The reason, I assume, that John proposed a separate call to seq was to explicitly assign/show the generation of the domain.
Correctly assumed
With regard to the separate call to
seq, you assumed correctly. I was not overly concerned with making the code as short as possible, more with making it transparent.