Well, I've finally gotten everything to work, but it hasn't been easy. As you can see, my dilemma was getting CAS and non-CAS stuff to work together harmoniously inside a program. I'm creating and solving a symbolic expression, which contains coefficients that are evaluated at runtime to be used in the construction of the expression. All of this would be so much easier if there were some sort of CAS switch that could be enabled inside a program at runtime, i.e. CASmode(On || Off). Anyways, here's the code I've written; note the complete absence of LOCAL variables:
Program Beam
//Eigenvalue solver for root based on guess "G"
//The guess should be a positive number slightly larger than the lowest non-trivial (zero)
//root. If it is too low, the result will be a very small number representing zero. Once the lowest
//root is determined, the program can be run again w/o entering the beam data again to
//determine additional higher roots if needed, which will be stored in the matrix variable M0.
//Note that the natural frequencies are proportional to the square of the eigenvalues.
EXPORT Beam_Solve(guess)
BEGIN
G:=guess;
CAS("M0:=nSolve(DET(m1)=0,x=G)");
RETURN M0;
END;
//This program solves for the natural frequencies of a beam with flexible end supports
EXPORT Beam_Main(k1,k2,k3,k4,EI,m,L,guess)
BEGIN
//Dimensionless coefficients
A:=k1*L^3/EI;
B:=k2*L/EI;
C:=k3*L^3/EI;
D:=k4*L/EI;
//Create CAS matrix elements
CAS("a11_:=x^3");
CAS("a12_:=-A");
CAS("a13_:=-x^3");
CAS("a14_:=-A");
CAS("a21_:=-B");
CAS("a22_:=-x");
CAS("a23_:=-B");
CAS("a24_:=x");
CAS("a31_:=-x^3*COS(x)-C*SIN(x)");
CAS("a32_:=x^3*SIN(x)-C*COS(x)");
CAS("a33_:=x^3*COSH(x)-C*SINH(x)");
CAS("a34_:=x^3*SINH(x)-C*COSH(x)");
CAS("a41_:=-x*SIN(x)+D*COS(x)");
CAS("a42_:=-x*COS(x)-D*SIN(x)");
CAS("a43_:=x*SINH(x)+D*COSH(x)");
CAS("a44_:=x*COSH(x)+D*SINH(x)");
//Create CAS eigenvalue matrix
CAS("m1:=[[a11_,a12_,a13_,a14_],[a21_,a22_,a23_,a24_],[a31_,a32_,a33_,a34_],[a41_,a42_,a43_,a44_]]");
//Solve for eigenvalue based on guess
Beam_Solve(guess);
//Calculate natural frequency in Hz
L0:=sqrt(EI/m)*(M0/L)^2/(2*pi);
//Print eigenvalue and natural frequency
RETURN {M0,L0};
END;
Edited: 13 Nov 2013, 3:51 p.m.