Suggestion for EXECON.
|
12-17-2014, 12:51 PM
(This post was last modified: 12-17-2014 01:06 PM by Snorre.)
Post: #21
|
|||
|
|||
RE: Sugdestion for EXECON.
(12-17-2014 06:54 AM)parisse Wrote: Yes, EXECON is more versatile. zip and apply work for 2 or 1 arg function. Otherwise just write a loop yourself if you need it in the CAS. Hey, that sounds like a nice challenge. My first purely(?) functional solution is (indentation+linebreaks for readability): Code: napply(fn, lsts):= Usage: a:={a1,a2,a3,a4}, b:={b1,b2,b3}, c:={c1,c2,c3,c4,c5} abc:={a,b,c} g(x,y,z):=x+y+z napply(g,abc) returns the sequence a1+b1+c1, a2+b2+c2, a3+b3+c3 which could be made into a vector by putting brackets or a list by putting braces around it, e.g. {napply(g,abc)}. |
|||
12-17-2014, 06:05 PM
Post: #22
|
|||
|
|||
RE: Sugdestion for EXECON.
(12-17-2014 12:51 PM)Snorre Wrote:(12-17-2014 06:54 AM)parisse Wrote: Yes, EXECON is more versatile. zip and apply work for 2 or 1 arg function. Otherwise just write a loop yourself if you need it in the CAS. Hello, Yes it is. On the weekend I will write program to evaluate any function with any number of variables any number of times. For the example I was giving in this thread if you do something only one or two times on the command line in CAS or in HOME you do not need "EXECON" or "apply" etc. You can use the period "." to indicate element by element operation and you done. For ex. (l1.+l2)./((l3.-l2).^2) and pronto you have what you wanted, but to do that in prgm. in CAS it would be more complicated and I will do that on the weekend. Cheers |
|||
12-17-2014, 07:14 PM
Post: #23
|
|||
|
|||
RE: Sugdestion for EXECON.
(12-17-2014 12:51 PM)Snorre Wrote: Hey, that sounds like a nice challenge.Very nice program! I did not expect that: I wanted to mean "write a loop for your particular problem", not "write a generic program", because I find myself functional style difficult to write (and even more difficult to read). But now that it is written, everyone can use it! |
|||
12-19-2014, 10:47 PM
Post: #24
|
|||
|
|||
RE: Suggestion for EXECON.
Hello,
Here is my very crude prgm. CASEXECON that works in CAS and with symbolics. The expression must be a string and the second argument must be a list. It works with lists entered as list of lists or as a list of store variables that contain lists. EXPORT CASEXECON(str_expr,lst) //Argument "str_expr" must be a strings and //all lists must be in curly brackets. //example: CASEXECON("(&2-&1*&2)",{{1,2},{3,4}} //or CASEXECON("(&2-&1*&2)",{l1,l2}). BEGIN local out; out:=EXECON("CAS("""+str_expr+""")",lst); IF size(out)==1 THEN out:=out(1); END; return(out); END; Cheers |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)