A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

I need help with a MATLAB problem. Write a MATLAB function to compute the exponential function directly from the Taylor series: e^x=1+x+X^2/2!+x^3/3!.... The series should end when the last term is less than 10^-6. Test your function against the built in function exp, but be careful not to make x too large-this could cause rounding error. Can anyone help me??

  • This Question is Open
  1. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If we notice that the terms of the Taylor's series are such that the nth term is the previous term multiplied by x/n, considering the initial "1" as the zeroth term. This means that instead of calculating each term from scratch, we only need to multiply the previous term by x/n to get the present term. 1 (term zero) x (term zero * x /1 ) x^2/2! = x* (x/2) x^3/3! = x^2/2! * (x/3) ... the running sum calculated will be the various approximation for exp(x). A check should be incorporated to stop calculations when the term is less than 10^(-6)

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I kind of understand what you are saying but I'm confused on how to write the actual code.

  3. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hint: Pseudocode: Function Exp(x) initialize term, sum, n while (term>10^(-6)) term=term*(x/n) sum=sum+term n=n+1 end while return sum Give it a try with Matlab and post your code if you need help.

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    OK thanks I will post my code if I need more help

  5. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You're welcome! :)

  6. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I am still having issues with this code. Can someone help me correct it so that I can run right. Thanks

    1 Attachment
  7. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is where defining variables (in English) is important when programming so that we do not confuse the values. In your code, y is used to return the value of the function, which is the sum of the series. That's ok. In the lines while y>10^-6 y=y*(x/n); y represents the value of each term of the series, which is not the sum of the series. Also, y must assume a value before we can do the recursive statement y=y*(x/n) This initial value must be defined before entering the while loop. Similarly, n and sum must be initialized to appropriate values before entering the loop. (n=1, sum=0), Finally, y=sum (because y is the return value equal to sum) must be placed at the end. Try to make corrections and post if you can.

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.