Question

for each a your 4 many terms the do you need to achieve a relative error smaller truncated than 10-8? +15. a Specifically, should implement exp for r +1,+10, function x) Your function er. lim compute built-in to n with in sum Matlab function innite function the r, how of Problem Write version Compare Are the results for 0 different from those for r 0? If so, what is a likely cause for this difference?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

matlab script:

prompt='please enter n value: ';
n=input(prompt);
prompt='please enter x value: ';
x=input(prompt);
sum=0;
for i= 0:n
    sum=sum+x^i/factorial(i);
end
fprintf('value of e^x from series :');
disp(sum);
fprintf('value of e^x from build in function :');
disp(exp(x));

comparision output for given cases:

output:-
>> 10^-8

ans =

1.0000e-008

following differences are nearor to above 10^-8 value


for x=+1 minimun n is 6, for x=-1 minimum n is 7, following is the result
please enter n value: 10
please enter x value: 1
value of e^x from series :    2.7183

value of e^x from build in function :    2.7183

please enter n value: 10
please enter x value: -1
value of e^x from series :    0.3679

value of e^x from build in function :    0.3679

please enter n value: 5
please enter x value: 1
value of e^x from series :    2.7167

value of e^x from build in function :    2.7183

please enter n value: 7
please enter x value: 1
value of e^x from series :    2.7183

value of e^x from build in function :    2.7183

please enter n value: 6
please enter x value: -1
value of e^x from series :    0.3681

value of e^x from build in function :    0.3679

please enter n value: 7
please enter x value: -1
value of e^x from series :    0.3679

value of e^x from build in function :    0.3679


for x=+10 minimun n is 10, for x=-10 minimum n is 35, following is the result
please enter n value: 15
please enter x value: 10
value of e^x from series : 2.0953e+004

value of e^x from build in function : 2.2026e+004

please enter n value: 10
please enter x value: 10
value of e^x from series : 1.2842e+004

value of e^x from build in function : 2.2026e+004

please enter n value: 7
please enter x value: 10
value of e^x from series : 4.8507e+003

value of e^x from build in function : 2.2026e+004

please enter n value: 9
please enter x value: 10
value of e^x from series : 1.0087e+004

value of e^x from build in function : 2.2026e+004

please enter n value: 33
please enter x value: -10
value of e^x from series : 1.9092e-005

value of e^x from build in function : 4.5400e-005

please enter n value: 35
please enter x value: -10
value of e^x from series : 4.3286e-005

value of e^x from build in function : 4.5400e-005

please enter n value: 34
please enter x value: -10
value of e^x from series : 5.2964e-005

value of e^x from build in function : 4.5400e-005


for x=+15 minimun n is 17, for x=-15 minimum n is 52, following is the result
please enter n value: 25
please enter x value: 15
value of e^x from series : 3.2488e+006

value of e^x from build in function : 3.2690e+006

please enter n value: 20
please enter x value: 15
value of e^x from series : 2.9978e+006

value of e^x from build in function : 3.2690e+006

please enter n value: 15
please enter x value: 15
value of e^x from series : 1.8571e+006

value of e^x from build in function : 3.2690e+006

please enter n value: 17
please enter x value: 15
value of e^x from series : 2.4480e+006

value of e^x from build in function : 3.2690e+006

please enter n value: 16
please enter x value: 15
value of e^x from series : 2.1710e+006

value of e^x from build in function : 3.2690e+006

please enter n value: 55
please enter x value: -15
value of e^x from series : 3.0510e-007

value of e^x from build in function : 3.0590e-007

please enter n value: 53
please enter x value: -15
value of e^x from series : 2.9493e-007

value of e^x from build in function : 3.0590e-007

please enter n value: 52
please enter x value: -15
value of e^x from series : 3.4527e-007

value of e^x from build in function : 3.0590e-007

please enter n value: 51
please enter x value: -15
value of e^x from series : 1.6740e-007

value of e^x from build in function : 3.0590e-007

the diferences are vary for the +ve numbers and -ve numbers because in -ve numbers alternative numbers having -ve sign causes substraction insted of summation

Add a comment
Know the answer?
Add Answer to:
Write a function in Matlab to compute e^x. Your function should implement a truncated version of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and...

    Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and outputs the nth Taylor polynomial of the sine function. Compute the absolute and error for n = 1: 10 at x = 1, obtained by comparing the output of your function to that of Matlab's built in sine function. Type on the Matlab console format long, then compute the previous error. Repeat the operation by typing format short. Comment on the result (quantify the...

  • Implement the following problems in MATLAB and document your work using the report guidelines on ...

    Implement the following problems in MATLAB and document your work using the report guidelines on the next page. 1. Use the subplot function to place the relevant graphical results in a single figure. Generate a sequence of 1000 pairs of independent zero-mean Gaussian random variables, where X has variance 2 and N has variance 1, Let Y = X + N be the equation for a noisy signal. Plot X, N, and Y in a 3D scatter plot using Y...

  • Implement MATLAB code that calculates sin(x) using the following formula, and measure the absolute error from...

    Implement MATLAB code that calculates sin(x) using the following formula, and measure the absolute error from the MATLAB provided function. The Taylor's formula is given as follows: sin(x) = 0+12 + 0x² + 5123 + 0.x4 + ... 23 25 27 -3! + 5- 7 + ... Plot both (1) the approximated value, and (2) absolute error. The following example uses x = 3 * pi, and k = 50. You may choose your own x, and k values. Approximation:...

  • Write a matlab program to implement the secant root finding method in matlab. The function name...

    Write a matlab program to implement the secant root finding method in matlab. The function name should be Secant and it should take the equation as input whoes root has to be found and the two initial values of a and b and maximum tolerable error. Consider the following example: Your code should generate the following: >> secantAssg5(@(x)(x^4+x^2+x+10),2,3,0.0001)    Xn-1      f(Xn-1)      Xn      f(Xn)      Xn+1      f(Xn+1) 2.0000   32.0000    3.0000 103.0000    1.5493   19.7111 ….. ….. ….. Root is x = 0.13952 ans...

  • Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2...

    Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7 Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method. Your program should output the following lines: • Bisection Method: Method converged to root X after Y iterations with a relative error of Z.

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial() B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees...

  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

  • in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A,...

    in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A, a column vector, b, an initial guess xo), an error tolerance e, and a maximum number of iterations, and output an approximate solution obtained using the Gauss-Seidel method, the error and the number of iterations. The header should look like (x, err, N] = gauss_seidel (A, b, x0, tol, Nmax). Use the method to find approximate solutions to the linear system -2 1 0...

  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT