Wronskian - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Wronskian (/thread-3179.html) |
Wronskian - salvomic - 02-22-2015 11:10 PM hi, I made a (CAS) program to calculate Wronskian of a list of functions (it gives both fundamental matrix and wronskian = det|mat|) Code:
Why the code Code:
Definitely the program sees "flist" always as a list with input [x, x^2], {x, x^2}, (x, x^2)... With a vector the program (correctly) gives a matrix, with list it gives a vector with 2 elements, a list and a vector, like [{x, x^2}[1, 2*x]], not correct as format, and I would like to avoid that. Salvo RE: Wronskian - salvomic - 02-23-2015 06:57 PM This code Code:
is a bit "dirty": I would control *every* part of an input like [x, x^2, 1-x, ...] not only the first two, to be NOT a string. I thought to use something like Code:
And that IF Code:
Any help is much appreciated! Salvo RE: Wronskian - salvomic - 02-23-2015 07:21 PM A little better version: Code:
It is not so elegant (it's perhaps "folkloristic", but with Code:
RE: Wronskian - Han - 02-23-2015 07:29 PM Why not just convert it for the user? The code below assumes CAS-programming. In CAS view, SIZE() (note the upper case) will return a real number for a list delimited by [ ] and a CAS list (in the form [ row col ]) for a matrix. Code: IF TYPE(flist)==4 THEN EDIT: it appears we don't even really need to convert; a list is a list in CAS regardless of the actual delimiters displayed. RE: Wronskian - salvomic - 02-23-2015 09:46 PM (02-23-2015 07:29 PM)Han Wrote: Why not just convert it for the user? The code below assumes CAS-programming. In CAS view, SIZE() (note the upper case) will return a real number for a list delimited by [ ] and a CAS list (in the form [ row col ]) for a matrix. thank you for your effort, Han. I'm trying applying that to my program, but for now I'm not able to do it, willing also to save the other controls for type, number arguments... Also the calculations should be changed; i.e. I create a mat with make mat(0, s, s), put in it flist, then (in two cycles) differentiate and add rows with mat[j,k]:=d Now, having already a matrix... I'm a bit confused, sorry. Salvo RE: Wronskian - Han - 02-23-2015 10:24 PM Try this: Code: #cas Usage: wronskm([f1,f2,...,fn]) returns the matrix; wronsk([f1,f2,...,fn]) returns the determinant of the matrix The error message regarding single-variable functions can occur when: 1) the "variable" already exists and contains a value of some sort (e.g. exported from a non-CAS program, defined by user, or exists in the CAS view); OR 2) the functions in the vector of functions are multivariate (or are all constants) RE: Wronskian - salvomic - 02-23-2015 10:51 PM (02-23-2015 10:24 PM)Han Wrote: Try this: thanks a lot! this works well, and finally the controls are what I would have to get! Please, can you tell me the use of the $ sign in diff() function? Another think: wronsk(f) take also the IF in the other function, as I can see, is it right? IF TYPE(s) THEN ... after the control of s==0 and <>6: controls it if there is another value for s? You prefer two CAS function and it's ok also for me; another idea is to have only a command and a Choose routine, as in the my previous version... Ad libitum Salvo EDIT: variables r, c: shouldn't they be in local? RE: Wronskian - Han - 02-23-2015 10:53 PM (02-23-2015 10:51 PM)salvomic Wrote: Please, can you tell me the use of the $ sign in diff() function? Example: x$2 means differentiate with respect to x twice. RE: Wronskian - salvomic - 02-23-2015 11:02 PM (02-23-2015 10:53 PM)Han Wrote: Example: x$2 means differentiate with respect to x twice. very interesting! I didn't know that, than you... please, see again my post above: I edited it while are writing... RE: Wronskian - Han - 02-24-2015 12:49 AM (02-23-2015 10:51 PM)salvomic Wrote: Another think: wronsk(f) take also the IF in the other function, as I can see, is it right? If I understand your question correctly, then the answer is no. Only one scenario is allowed: when the input f consists of a list. In CAS-view, the SIZE() command returns a real number if f is a list (whether of the form f1,f2,…,fn or [f1,f2,…,fn] or {f1,f2,…,fn} or any non-matrix type). Otherwise, SIZE() returns a list if f is a matrix. That is, if f is an m x n matrix, then SIZE(f) returns [m n]. So the first IF statement checks to see that an input was actually specified and that it necessarily a list. A symbolic matrix is just a list of lists (or, one can also think of it as a matrix). So after the first IF statement, the only possible scenario is that f is a list, or it is a list of lists. To determine which, we check the TYPE() of the SIZE() result. If the SIZE() command returned a real number, then we have a simple list (or we can think of it as a vector). Otherwise, if SIZE() is not a real number, then it could not be a simple list (likely a list of list, for example) and so we throw an error message. Quote:EDIT: variables r, c: shouldn't they be in local? No, they are automatically local, and local to the function (r,c)->diff(f(c), v$(r-1)) because they are simply placeholders (dummy variables). RE: Wronskian - salvomic - 02-24-2015 06:32 AM (02-24-2015 12:49 AM)Han Wrote: If I understand your question correctly, then the answer is no. ... perfect! thank you, now it is more clear for me. Your code is also more compact than mine! |