HP Forums

Full Version: Calling a CAS function in a program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I'm trying to write an HP program that numerically solves a system of nonlinear equations using the CAS function fsolve, with certain parameters depending on local variables (inputs). I get an "Error: Bad Argument Value" when trying to run the program, despite the same system getting solved just fine when I type it into CAS. The only thing I could find online was this post, where they discussed issues with using local variables in CAS functions, but nothing definitive was reached. Here's my code for reference:


EXPORT exponential_model()
  LOCAL V, R, Vr, Ir, n, Vt; // inputs
  LOCAL Is, Vd, Id; // outputs being solved for

  INPUT( {V, R, Vr, Ir, n, Vt},
    "Enter parameters", {},
    {"Voltage source", "Resistor", "Reference voltage", "Reference current", "Empirical constant", "Thermal voltage"} );
  RETURN CAS.fsolve({Ir=Is*(e^((Vr)/(n*Vt))-1),Id=(V-Vd)/R,Id=Is*(e^((Vd)/(n*Vt))-1)},{Vd,Id,Is});

I don't think you can use Home local variables as unknowns for fsolve. Make a CAS program and use CAS global variables (or CAS local variables and purge them).
Reference URL's