WarpPI/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java

74 lines
1.8 KiB
Java
Raw Normal View History

package org.warp.picalculator.math.functions.equations;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionDynamic;
2016-10-02 16:01:41 +02:00
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Number;
public class EquationsSystem extends FunctionDynamic {
static final int spacing = 2;
2017-01-17 22:32:40 +01:00
public EquationsSystem(MathContext root) {
2017-01-17 22:32:40 +01:00
super(root);
}
public EquationsSystem(MathContext root, Function value) {
super(root, new Function[] { value });
}
public EquationsSystem(MathContext root, Function[] value) {
2017-01-17 22:32:40 +01:00
super(root, value);
}
@Override
2016-10-02 16:01:41 +02:00
protected boolean isSolvable() {
if (functions.length >= 1) {
2016-10-02 16:01:41 +02:00
return true;
}
return false;
}
2016-10-02 16:01:41 +02:00
@Override
public ObjectArrayList<Function> solve() throws Error {
final ObjectArrayList<Function> ret = new ObjectArrayList<>();
if (functions.length == 1) {
if (functions[0].isSimplified()) {
ret.add(functions[0]);
2016-10-02 16:01:41 +02:00
return ret;
} else {
final List<Function> l = functions[0].simplify();
for (final Function f : l) {
2016-10-02 16:01:41 +02:00
if (f instanceof Number) {
ret.add(f);
} else {
ret.add(new Expression(root, new Function[] { f }));
2016-10-02 16:01:41 +02:00
}
}
return ret;
}
} else {
for (final Function f : functions) {
if (f.isSimplified() == false) {
final List<Function> partial = f.simplify();
for (final Function fnc : partial) {
ret.add(new Expression(root, new Function[] { fnc }));
2016-10-02 16:01:41 +02:00
}
}
}
return ret;
}
}
@Override
public EquationsSystem clone() {
return new EquationsSystem(root, functions);
}
}