ex_estimator_yourlogin

ex_estimator_yourlogin - initialize current term series_sum...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [series_sum,n,exp_diff] = ex_estimator_yourlogin(x,desired_accuracy) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Programmer(s) and Purdue Email Address(es): % 1. % % Section #:ALL % % Assignment #: Homework 5 Problem 4 % % Academic Integrity Statement: % % I/We have not used source code obtained from % any other unauthorized source, either modified % or unmodified. Neither have I/we provided access % to my/our code to another. The project I/we am/are % submitting is my/our own original work. % % This function calculates the function e^x using a Taylor series approximation. % % INPUTS % x = the value of x used for the calculation e^x % desired_accuray = the desired accuracy of the approximation % % OUTPUTS % series_sum = sum of the taylor series approximation for e^x % exp_diff = tje difference between the actual calculation and approximation. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %---- INPUTS ---- % n = 0; % series counter current_term = 0;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % initialize current term series_sum = 0; % initialize taylor series summation s %---- Calculations ----% if desired_accuracy >0 i exp_diff = abs(exp(x)-series_sum); % calculate initial accuracy e while exp_diff >= desired_accuracy % use while loop to check if accuracy has been achieved current_term = x^n/factorial(n); % calculate current taylor series term series_sum = series_sum + current_term; % summation of all terms calculated exp_diff = abs(exp(x)- series_sum); % accuracy calculation n = n+1; % increment index end e %---- Outputs ----% fprintf('exp(%f)= %.5f \n',x,series_sum) f else fprintf('Your desired accuracy must be a positive value and greater than 0.') exp_approx = 0; end e % Enter x = 2 % Enter desired level of accuracy = 0.001 % exp(2.000000)= 7.38871 % % Enter x = -4 % Enter desired level of accuracy = 0.0001 % exp(-4.000000)= 0.01836 % % Enter x = 12.3 % Enter desired level of accuracy = 0.00005 % exp(12.300000)= 219695.98865 %...
View Full Document

Page1 / 2

ex_estimator_yourlogin - initialize current term series_sum...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online