1
package geogebra.kernel.statistics;
4
GeoGebra - Dynamic Mathematics for Everyone
5
http://www.geogebra.org
7
This file is part of GeoGebra.
9
This program is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation.
16
import geogebra.kernel.arithmetic.ExpressionNode;
17
import geogebra.kernel.arithmetic.ExpressionValue;
18
import geogebra.kernel.arithmetic.Function;
19
import geogebra.kernel.arithmetic.FunctionVariable;
20
import geogebra.kernel.arithmetic.MyDouble;
21
import geogebra.kernel.AlgoElement;
22
import geogebra.kernel.GeoList;
23
import geogebra.kernel.GeoFunction;
24
import geogebra.kernel.GeoElement;
25
import geogebra.kernel.Construction;
29
* Fits a+bln(x) to a list of points.
30
* Adapted from AlgoFitLine and AlgoPolynomialFromCoordinates
32
* @author Hans-Petter Ulven
35
public class AlgoFitLog extends AlgoElement{
37
private static final long serialVersionUID = 1L;
38
private GeoList geolist; //input
39
private GeoFunction geofunction; //output
42
public AlgoFitLog(Construction cons, String label, GeoList geolist) {
45
geofunction=new GeoFunction(cons);
48
geofunction.setLabel(label);
51
protected String getClassName() {return "AlgoFitLog";}
53
protected void setInputOutput(){
54
input=new GeoElement[1];
56
output=new GeoElement[1];
57
output[0]=geofunction;
61
public GeoFunction getFitLog() {return geofunction;}
63
protected final void compute() {
64
int size=geolist.size();
67
if(!geolist.isDefined() || (size<2) ) { //24.04.08: 2
68
geofunction.setUndefined();
71
RegressionMath regMath = kernel.getRegressionMath();
72
regok=regMath.doLog(geolist);
76
MyDouble A=new MyDouble(kernel,a);
77
MyDouble B=new MyDouble(kernel,b);
78
FunctionVariable X=new FunctionVariable(kernel);
79
ExpressionValue expr=new ExpressionNode(kernel,X,ExpressionNode.LOG,X);
80
expr=new ExpressionNode(kernel,B,ExpressionNode.MULTIPLY,expr);
81
ExpressionNode node=new ExpressionNode(kernel,A,ExpressionNode.PLUS,expr);
82
Function f=new Function(node,X);
83
geofunction.setFunction(f);
84
geofunction.setDefined(true);
86
geofunction.setUndefined();
88
}//if error in regression
89
}//if error in parameters
1
package geogebra.kernel.statistics;
4
GeoGebra - Dynamic Mathematics for Everyone
5
http://www.geogebra.org
7
This file is part of GeoGebra.
9
This program is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation.
16
import geogebra.kernel.AlgoElement;
17
import geogebra.kernel.Construction;
18
import geogebra.kernel.GeoElement;
19
import geogebra.kernel.GeoFunction;
20
import geogebra.kernel.GeoList;
21
import geogebra.kernel.arithmetic.ExpressionNode;
22
import geogebra.kernel.arithmetic.ExpressionValue;
23
import geogebra.kernel.arithmetic.Function;
24
import geogebra.kernel.arithmetic.FunctionVariable;
25
import geogebra.kernel.arithmetic.MyDouble;
29
* Fits a+bln(x) to a list of points.
30
* Adapted from AlgoFitLine and AlgoPolynomialFromCoordinates
32
* @author Hans-Petter Ulven
35
public class AlgoFitLog extends AlgoElement{
37
private static final long serialVersionUID = 1L;
38
private GeoList geolist; //input
39
private GeoFunction geofunction; //output
42
public AlgoFitLog(Construction cons, String label, GeoList geolist) {
44
geofunction.setLabel(label);
47
public AlgoFitLog(Construction cons, GeoList geolist) {
50
geofunction=new GeoFunction(cons);
55
public String getClassName() {return "AlgoFitLog";}
57
protected void setInputOutput(){
58
input=new GeoElement[1];
60
output=new GeoElement[1];
61
output[0]=geofunction;
65
public GeoFunction getFitLog() {return geofunction;}
67
protected final void compute() {
68
int size=geolist.size();
71
if(!geolist.isDefined() || (size<2) ) { //24.04.08: 2
72
geofunction.setUndefined();
75
RegressionMath regMath = kernel.getRegressionMath();
76
regok=regMath.doLog(geolist);
80
MyDouble A=new MyDouble(kernel,a);
81
MyDouble B=new MyDouble(kernel,b);
82
FunctionVariable X=new FunctionVariable(kernel);
83
ExpressionValue expr=new ExpressionNode(kernel,X,ExpressionNode.LOG,X);
84
expr=new ExpressionNode(kernel,B,ExpressionNode.MULTIPLY,expr);
85
ExpressionNode node=new ExpressionNode(kernel,A,ExpressionNode.PLUS,expr);
86
Function f=new Function(node,X);
87
geofunction.setFunction(f);
88
geofunction.setDefined(true);
90
geofunction.setUndefined();
92
}//if error in regression
93
}//if error in parameters
92
96
}// class AlgoFitLog
b'\\ No newline at end of file'