Post Reply 
Program for finding roots and selecting one
03-10-2016, 04:57 AM
Post: #5
RE: Program for finding roots and selecting one
(03-09-2016 08:38 AM)Didier Lachieze Wrote:  
(03-09-2016 04:26 AM)Eugenio Wrote:  I was thinking to use the CAS.function('expression') to find the roots instead of programming a cubic root finder. My real problem is which command should I use in the programm so that when the CAS.function gives the 3 roots, the programm choses the only real root out of the 3 roots ( 2 complex and 1 real.) and then define that real root as the valua of "Z" so it follows its calculations.

This should work for you:
Code:
EXPORT RealRoot(poly)
BEGIN
  LOCAL s;
  s:=CAS.proot(poly);
  EXECON("IFTE(TYPE(&1),0,Z:=&1)",mat2list(s));
  RETURN Z;
END;
For example for $$2*x^3+x^2-2$$ RealRoot([2,1,0,-2]) returns 0.858094329497

Thank you so much for your help, it has been really helpfull. It works and suits perfectly
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Program for finding roots and selecting one - Eugenio - 03-10-2016 04:57 AM



User(s) browsing this thread: 1 Guest(s)