~ubuntu-branches/debian/sid/geogebra/sid

« back to all changes in this revision

Viewing changes to geogebra/kernel/statistics/AlgoFitLog.java

  • Committer: Package Import Robot
  • Author(s): Giovanni Mascellani
  • Date: 2012-01-10 11:37:41 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120110113741-satwohsd4de4ite1
Tags: 4.0.19.0+dfsg1-1
* New upstream version (closes: #649893).
* Update dependency: icedtea-plugin -> icedtea-netx-common (LP: #893007).
* New thumbnailer configuration compatible with Gnome 3.
* Package building is now managed by javahelper instead of upstream
  build.xml.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package geogebra.kernel.statistics;
2
 
 
3
 
/* 
4
 
GeoGebra - Dynamic Mathematics for Everyone
5
 
http://www.geogebra.org
6
 
 
7
 
This file is part of GeoGebra.
8
 
 
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.
12
 
 
13
 
*/
14
 
 
15
 
 
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;
26
 
 
27
 
 
28
 
/** 
29
 
 * Fits a+bln(x)  to a list of points.
30
 
 * Adapted from AlgoFitLine and AlgoPolynomialFromCoordinates
31
 
 * (Borcherds)
32
 
 * @author Hans-Petter Ulven
33
 
 * @version 24.04.08
34
 
 */
35
 
public class AlgoFitLog extends AlgoElement{
36
 
 
37
 
    private static final long serialVersionUID  =   1L;
38
 
    private GeoList         geolist;                        //input
39
 
    private GeoFunction     geofunction;                    //output
40
 
 
41
 
    
42
 
    public AlgoFitLog(Construction cons, String label, GeoList geolist) {
43
 
        super(cons);
44
 
        this.geolist=geolist;
45
 
        geofunction=new GeoFunction(cons);
46
 
        setInputOutput();
47
 
        compute();
48
 
        geofunction.setLabel(label);
49
 
    }//Constructor
50
 
    
51
 
    protected String getClassName() {return "AlgoFitLog";}
52
 
        
53
 
    protected void setInputOutput(){
54
 
        input=new GeoElement[1];
55
 
        input[0]=geolist;
56
 
        output=new GeoElement[1];
57
 
        output[0]=geofunction;
58
 
        setDependencies();
59
 
    }//setInputOutput()
60
 
    
61
 
    public GeoFunction getFitLog() {return geofunction;}
62
 
    
63
 
    protected final void compute() {
64
 
        int size=geolist.size();
65
 
        boolean regok=true;
66
 
        double a,b;
67
 
        if(!geolist.isDefined() || (size<2) ) { //24.04.08: 2
68
 
            geofunction.setUndefined();
69
 
            return;
70
 
        }else{
71
 
                RegressionMath regMath = kernel.getRegressionMath();
72
 
            regok=regMath.doLog(geolist);
73
 
            if(regok){
74
 
                a=regMath.getP1();
75
 
                b=regMath.getP2();
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);
85
 
            }else{
86
 
                geofunction.setUndefined();
87
 
                return;  
88
 
            }//if error in regression   
89
 
        }//if error in parameters
90
 
    }//compute()
91
 
    
 
1
package geogebra.kernel.statistics;
 
2
 
 
3
/* 
 
4
GeoGebra - Dynamic Mathematics for Everyone
 
5
http://www.geogebra.org
 
6
 
 
7
This file is part of GeoGebra.
 
8
 
 
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.
 
12
 
 
13
*/
 
14
 
 
15
 
 
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;
 
26
 
 
27
 
 
28
/** 
 
29
 * Fits a+bln(x)  to a list of points.
 
30
 * Adapted from AlgoFitLine and AlgoPolynomialFromCoordinates
 
31
 * (Borcherds)
 
32
 * @author Hans-Petter Ulven
 
33
 * @version 24.04.08
 
34
 */
 
35
public class AlgoFitLog extends AlgoElement{
 
36
 
 
37
    private static final long serialVersionUID  =   1L;
 
38
    private GeoList         geolist;                        //input
 
39
    private GeoFunction     geofunction;                    //output
 
40
 
 
41
    
 
42
    public AlgoFitLog(Construction cons, String label, GeoList geolist) {
 
43
        this(cons, geolist);
 
44
        geofunction.setLabel(label);
 
45
    }//Constructor
 
46
    
 
47
    public AlgoFitLog(Construction cons, GeoList geolist) {
 
48
        super(cons);
 
49
        this.geolist=geolist;
 
50
        geofunction=new GeoFunction(cons);
 
51
        setInputOutput();
 
52
        compute();
 
53
    }//Constructor
 
54
    
 
55
    public String getClassName() {return "AlgoFitLog";}
 
56
        
 
57
    protected void setInputOutput(){
 
58
        input=new GeoElement[1];
 
59
        input[0]=geolist;
 
60
        output=new GeoElement[1];
 
61
        output[0]=geofunction;
 
62
        setDependencies();
 
63
    }//setInputOutput()
 
64
    
 
65
    public GeoFunction getFitLog() {return geofunction;}
 
66
    
 
67
    protected final void compute() {
 
68
        int size=geolist.size();
 
69
        boolean regok=true;
 
70
        double a,b;
 
71
        if(!geolist.isDefined() || (size<2) ) { //24.04.08: 2
 
72
            geofunction.setUndefined();
 
73
            return;
 
74
        }else{
 
75
                RegressionMath regMath = kernel.getRegressionMath();
 
76
            regok=regMath.doLog(geolist);
 
77
            if(regok){
 
78
                a=regMath.getP1();
 
79
                b=regMath.getP2();
 
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);
 
89
            }else{
 
90
                geofunction.setUndefined();
 
91
                return;  
 
92
            }//if error in regression   
 
93
        }//if error in parameters
 
94
    }//compute()
 
95
    
92
96
}// class AlgoFitLog
 
 
b'\\ No newline at end of file'