Exponential Problem

Exponential Problem - MsgBox"The calculated e^x value...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Jordan Cooper 36 Problem Statement : Design a way to determine e x and compare it to e(x) in a VBA function. Create two user defined functions, one for calculating e x , and the other for calculating factorial. Assumptions : The user enters an integer. The program runs correctly. Theory : e x = 1 + (x/1!) + (x 2 /2!) + … e x = Σ(x n /n!) Solution : e (2) = 1 + ((2)/1) + ((2) 2 /(2*1)) e (2) = 1 + 2 + (4/2) e (2) = 1 + 2 + 2 e (2) = 5 Option Explicit Sub Exponential_Problem() Dim x As Double, maxvalue As Double, exponent As Double, E As Single x = InputBox("Enter a value for x in calculating e^x") maxvalue = InputBox("enter a maximum value of the last term in the estimate suggested 10^-7") exponent = whole(maxvalue, x) E = Exp(x)
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MsgBox ("The calculated e^x value = " & exponent & " and e(x) = " & E) End Sub Function whole(ByVal maxvalue As Double, ByRef x As Double) As Single Dim i As Single, n As Single, a As Single i = 0 n = 0 whole = 1 Do n = n + 1 a = (x ^ n) / (fact(n)) If (Abs(a) <= maxvalue) Then Exit Do whole = whole + a i = i + 1 Loop End Function Function fact(ByVal n As Single) As Single Dim s As Integer fact = 1 For s = 1 To n fact = fact * s Next s End Function Discussion : For an x-value of 1, the e x function returns a value of 2.718 and the e(x) function returns the same value. Also, the e x function should return the same value as e(x) for any value x....
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern