Write a C Program and algorithm
Posted: Sat Feb 19, 2022 3:20 pm
Write a C Program and algorithm
Topic 2 Write a program that uses the Taylor series to solve the In(x) function using the formula below. Next, use the In(x) function that was created to determine log100), In(), and custom log() for positive real numbers of x. Output the solution as a step-by-step output to the screen. 1x106 2k+1 In(x) = 2 X zk+16+ 1 467) k=0 The formula will calculate In(x) for any real number x > 0. The program must fulfil these requirements: • All real numbers used must be double variable type. • The maximum number of iteration for the formula is set at 1e6. • Calculation must stop when the result is within 1e-7 of the actual value. • Functions log100) and log() in math.h ARE NOT allowed to be used! Examples: Choose [1] log10(x), [2] in(x), [3] custom log(x): 1 Enter value of x: 342042 log10( 342042.000000) log10( 100000.000000 ) + log10( 3.420420 ) = 4.998213 + 0.534079 = 5.532293 Choose [1] log10(x), [2] in(x), [3] custom log(x): 2 Enter value of x: 217 in( 217.000000) in( 100.000000 ) + In( 2. 170000) 4.605166 + 0.774727 = 5.379893 Choose [1] log10(x), [2] in(x), [3] custom log(x): 3 Enter value of x: 7895 Enter custom log base: 7 log7( 7895.000000 ) log 7( 1000.000000 ) + log7 7.895000) = 3.549861 + 1.061832 = 4.611693
Topic 2 Write a program that uses the Taylor series to solve the In(x) function using the formula below. Next, use the In(x) function that was created to determine log100), In(), and custom log() for positive real numbers of x. Output the solution as a step-by-step output to the screen. 1x106 2k+1 In(x) = 2 X zk+16+ 1 467) k=0 The formula will calculate In(x) for any real number x > 0. The program must fulfil these requirements: • All real numbers used must be double variable type. • The maximum number of iteration for the formula is set at 1e6. • Calculation must stop when the result is within 1e-7 of the actual value. • Functions log100) and log() in math.h ARE NOT allowed to be used! Examples: Choose [1] log10(x), [2] in(x), [3] custom log(x): 1 Enter value of x: 342042 log10( 342042.000000) log10( 100000.000000 ) + log10( 3.420420 ) = 4.998213 + 0.534079 = 5.532293 Choose [1] log10(x), [2] in(x), [3] custom log(x): 2 Enter value of x: 217 in( 217.000000) in( 100.000000 ) + In( 2. 170000) 4.605166 + 0.774727 = 5.379893 Choose [1] log10(x), [2] in(x), [3] custom log(x): 3 Enter value of x: 7895 Enter custom log base: 7 log7( 7895.000000 ) log 7( 1000.000000 ) + log7 7.895000) = 3.549861 + 1.061832 = 4.611693