Question: 3. The following Matlab function function y mytanh (x) y (exp(x)-exp(-x))/(exp(x)+exp(-x)) for computing tanh(x) = (e* -e*)/(e*+e) was found to return NaN for large

3. The following Matlab function function y mytanh (x) y (exp(x)-exp(-x))/(exp(x)+exp(-x)) for

   

3. The following Matlab function function y mytanh (x) y (exp(x)-exp(-x))/(exp(x)+exp(-x)) for computing tanh(x) = (e* -e*)/(e*+e) was found to return NaN for large values of |x| (say x = 1000). Rewrite the code so that it computes accurate values for both large and small values of x whether x is positive or negative. Test your code for the values: x = 10%, k = -2, -1, 0, 1, 2, 3. Submit your code and your test results. You can compare with the built-in function tanh.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!