cas-function: locuscurve
02-20-2018, 10:34 AM (This post was last modified: 02-22-2018 02:54 PM by Arno K.)
Post: #1
 Arno K Senior Member Posts: 459 Joined: Mar 2015
cas-function: locuscurve
This small program provides on input of a set of function f(x,k) and an additional parameter p a list containing the equations (as strings to be easily usable in plots) of extreme points (p=1) or turning points (p=2). As I did not want to bother about used variables x and k must be used. f may also be an expression.
Code:
locuscurve(x*e^(-k*x^2),1)
provides the output:
Code:
{"y:=x^2/(abs(x)*e^(1/2))","y:=-x^2/(abs(x)*e^(1/2))"}
Here you must clearly see for yourself that the first part is for max-points and the second one is for mins, putting this together to only "y:=x*e^(-1/2)" would have caused a lot of different cases to be taken care of, so I omitted that.
Code:
// calculates the curve through locuspoints of a parametric function which must be dependent from x and k // p=1: extreme points, p=2: turning points // f can be function or symbolic  #cas locuscurve(f,p):= BEGIN LOCAL g,x,k,z; LOCAL l1,l2,j; purge(x); purge(k); IF type(f)≠DOM_FUNC THEN f(x,k):=f;//transform to function END; g:=diff(f(x,k),x,p); l1:=zeros(g);//x-vals l2:=apply(z→f(z,k),l1);//y-vals l1:=x.-l1; l1:=apply(z→solve(z=0,k),l1); FOR j FROM 1 TO size(l1) DO l1[j]:=l1[j]; l2[j]:="f"+j+"(x):="+simplify(subst(l2[j],k=l1[j]));//string for convenience END;   return convert(l2,23);// convert matrix to list END; #end
Arno
02-27-2018, 11:32 PM
Post: #2
 Arno K Senior Member Posts: 459 Joined: Mar 2015
RE: cas-function: locuscurve
Slight changes because it does not work on turning points when they are unique, i.e. independent from k. In the moment solve returns a vector containing 0 as first entry as I tried on some examples, so I made a quick and dirty fix for this. When someone encounters problems, pm me.
Another thing to be mentioned, CAS settings, Complex on and Use i on increase speed noticably.
Arno

Code:
 #cas locuscurve(f,p):= BEGIN LOCAL g,x,k,z; LOCAL l1,l2,j; purge(x); purge(k); IF type(f)≠DOM_FUNC THEN f(x,k):=f; END; g:=diff(f(x,k),x,p); l1:=zeros(g); IF l1==0 THEN l1:=tail(l1); END; l2:=apply(z→f(z,k),l1); l1:=x.-l1; l1:=apply(z→solve(z=0,k),l1); FOR j FROM 1 TO size(l1) DO l1[j]:=l1[j]; l2[j]:="f"+j+"(x):="+simplify(subst(l2[j],k=l1[j])); END;   return convert(l2,23); END; #end
 « Next Oldest | Next Newest »

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