# commons-user mailing list archives

##### Site index · List index
Message view
Top
From "Ted Dunning" <ted.dunn...@gmail.com>
Subject Re: [math] help writing a solver for equation
Date Wed, 17 Sep 2008 17:48:06 GMT
Seems to me that a little bit of math would go a long way here.

z &= \sum_{a = 1}^n \left[ e^{y - x(a)}/ e^{x(a)} \right] \\
z &= \sum_{a = 1}^n \left[ e^{y - 2 x(a)} \right] \\
z &= \sum_{a = 1}^n \left[ e^y e^{ - 2 x(a)} \right]  \\
z &= e^y \sum_{a = 1}^n e^{ - 2 x(a) } \\
y &= \log \left[ z  { \sum_{a = 1}^n  e^{2 x(a) } } \right]

Perhaps you lost something in translation somewhere?  Surely, you problem
isn't this easy.

Also, in your code, it looks like your original equation is different from
what you said in your problem statement.  Still easy to solve, but very
different.

Finally, I don't see anyplace in your code that you connected your equation
to solve with the solver.

On Wed, Sep 17, 2008 at 2:30 AM, <mickeydog@taosnet.com> wrote:

> I have an equation like so:
> z = Sum of a = 1 to n [ e**(y - x(a))/ e**(x(a)]
> I want to solve for y.
> I have z and x(a).
>
> I have created a class EquationSolver which has these methods and inner
> class:
>
> private EstimatedParameter xa;
>
> public VintageQualityFitter() {
>
>  xa = new EstimatedParameter("xa", 0.0);
>
>  // provide the parameters to the base class which
>  // implements the getAllParameters and getUnboundParameters methods
> }
>
> public double theoreticalValue(double z) {
>  double summand = ( Math.exp(y * xa.getEstimate()) /
> Math.exp(xa.getEstimate());
>  return summand;
> }
>
> public void addPoint(double xa) {
>  addMeasurement(new LocalMeasurement(xa, 1.0)); // all weights same
> }
>
> public double getXa() {
>  return xa.getEstimate();
> }
>
> private class LocalMeasurement extends WeightedMeasurement {
>
>  private final double z;
>
>  // constructor
>  public LocalMeasurement(double xa, double weight) {
>     super(xa, weight);
>     this.z = xa;
>  }
>
>  public double getTheoreticalValue() {
>    // the value is provided by the model for the local xa
>    return theoreticalValue(z);
>  }
>
> // don't need this i think
>  public double getPartial(EstimatedParameter parameter) {
>    return 0.0;
>  }
> }
>
> I use this like so:
>
> EquationFitter equationFitter = new EquationFitter();
>
> for (int a = 0; a <= numberOfAs; a++) {
>  double xa = <get x(a)>
>  }
>
> try {
>    // solve the problem, using a Levenberg-Marquardt algorithm with
> default settings
>        LevenbergMarquardtEstimator estimator = new
> LevenbergMarquardtEstimator();
>    estimator.estimate(equationFitter);
> } catch (EstimationException e) {
>        e.printStackTrace();
> }
>
> // fitter.theoreticalValue() is alpha
> <get some z>
> y = equationFitter.theoreticalValue(z);
>
> but something in all this isn't right, especially with theoreticalValue(),
> i think.
> Can anyone help?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

--
ted


Mime
• Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message