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 2 of 2

Thread: Taylor series for e^x

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Taylor series for e^x

    Hi I was bussy making some exercises for my exams and had to write a program to calculate Taylor series for e^x.
    Our prof lecturer gave us the solution but don't understand why he does it like this

    import java.util.Locale;
    import java.util.Scanner;

    public class TaylorReeks{
    // versie van het berekenen van een Tailorreeks waarbij de grootte van decimale getallen onder controle wordt gehouden.
    public static void main(String[] args){

    Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
    System.out.println("Geef een getal x in : ");

    double x = scanner.nextDouble();
    double threshold = 0.1;

    int teller = 1;
    double component = x;

    double exponentVorig = 1.0;
    double exponentHuidig = 1 + x;

    while (Math.abs(exponentHuidig - exponentVorig) > threshold){
    teller = teller + 1;
    component = component * x / teller;
    exponentVorig = exponentHuidig;
    exponentHuidig = exponentVorig + component;

    }

    System.out.println("De waarde berekend met Math.E is: " + Math.pow(Math.E, x));
    System.out.println("De waarde berekend door het algoritme is: " + exponentHuidig + ".");
    System.out.println("Het aantal iteraties is:" + teller + ".");
    }
    }

  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: Taylor series for e^x

    why he does it like this
    Please ask some specific java programming questions about the lines of code you are having problems with.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with a Summing Series please? :)
    By kelOB in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2013, 04:41 AM
  2. Fibonacci Series
    By 13cmwest in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 15th, 2013, 04:39 AM
  3. Fibonacci series
    By seanman in forum Algorithms & Recursion
    Replies: 4
    Last Post: September 11th, 2011, 12:32 PM
  4. problem to get Fibonacci series- please help.
    By zoala001 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 3rd, 2011, 01:10 AM

Tags for this Thread