Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to solve user defined from apache commons math

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to solve user defined from apache commons math

    Hi People's,

    Could anyone make a working class out example of the Apache's sample code? (code from website is here below)

    UnivariateFunction function = // some user defined function object
    final double relativeAccuracy = 1.0e-12;
    final double absoluteAccuracy = 1.0e-8;
    final int maxOrder = 5;
    UnivariateSolver solver = new BracketingNthOrderBrentSolver(relativeAccuracy, absoluteAccuracy, maxOrder);
    double c = solver.solve(100, function, 1.0, 5.0, AllowedSolution.LEFT_SIDE);

    Cheers,


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to solve user defined from apache commons math

    What have you tried? What problems are you having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: How to solve user defined from apache commons math

    Do you not know what the sample code is asking?
    UnivariateFunction is an interface. That comment is telling you that you need to create some class which implements the UnivariateFunction interface and perform some sort of function operations (such as the Abs class, which I think just gets the absolute value of the sent value), and create a new instance of that class where the comment is.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to solve user defined from apache commons math

    This here beneath is what I have so far:

    There is an error on the last line of the code which gives no further indication:


    import org.apache.commons.math3.analysis.solvers.AllowedS olution;
    import org.apache.commons.math3.analysis.solvers.Bracketi ngNthOrderBrentSolver;
    import org.apache.commons.math3.analysis.solvers.BrentSol ver;
    import org.apache.commons.math3.analysis.solvers.PegasusS olver;
    import org.apache.commons.math3.analysis.solvers.Univaria teSolver;
    import org.apache.commons.math3.analysis.solvers.Univaria teSolverUtils;


    public class test {


    static class MyFunction implements UnivariateFunction {
    public double value(double x) {
    double y = hugeFormula(2);
    // if (somethingBadHappens) {
    // throw new LocalException(x);
    // }
    return y;
    }

    private double hugeFormula(double x) {
    // TODO Auto-generated method stub
    return x*x+2;
    }

    }

    public static void main(String [] Args){
    UnivariateFunction function= new MyFunction();
    final double relativeAccuracy = 1.0e-12;
    final double absoluteAccuracy = 1.0e-8;
    final int maxOrder = 5;
    UnivariateSolver solver = new BracketingNthOrderBrentSolver(relativeAccuracy, absoluteAccuracy, maxOrder);
    double c = solver.solve(100, function, 1.0, 5.0, AllowedSolution.LEFT_SIDE);
    }
    }

Similar Threads

  1. need help with 'org.apache.commons.net.ftp.FTPClient'
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 22nd, 2013, 07:02 PM
  2. Uploading File to server ( Apache.commons.net)
    By quirell in forum Java Networking
    Replies: 5
    Last Post: November 11th, 2012, 11:06 PM
  3. problem while sending email using org.apache.commons.mail.*
    By gurleen in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2012, 11:21 AM
  4. Replies: 3
    Last Post: March 7th, 2012, 05:54 AM
  5. OSGI - missing imported package=org.apache.commons.collections
    By rcbandit in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2012, 11:36 AM