Help, I need to work on this assignment using MATLAB. I dont have a clue on this
ID: 3862241 • Letter: H
Question
Help, I need to work on this assignment using MATLAB. I dont have a clue on this assignment.
The hyperbolic tangent function tan h x: sinh x/cosh x = e^x - e^-x/e^x + e^-x is an important function in water-wave theory, waveguide design, etc. Show that tan h x rightarrow 1 as x rightarrow infinity. Now use MATLAB to set up a vector of the four x values 10, 100, 1000, 10000. The command you'll need is x = [10; 100; 1000; 10000]. (The semi-colon makes a new row in a matrix). Evaluate the function tan h x in three different ways: (i) Directly from the definition above. [You'll need to tell MATLAB that you want to carry out the operation on each element of the vector of x-values that you've set up. The way you give this information is to use a dot before each major binary operation - that way. MATLAB won't try to do clever things with matrix multiplication, but will instead know to do its operations element-by-element. So the command you'll need is y = ((exp (x) - exp (-x)) ./(exp (x) +exp (-x)).] (ii) Using MATLAB's own internal function for the hyperbolic tangent. If you don't know what that is, use the lookfor command in MATLAB's help menu. (iii) Using the formula tan h x = 1 - e^-2x/1 + e^-2x. Give an intelligent discussion of what's going on here! It would be appropriate to make a value judgment as to which of these is the best to use, and why that might be.Explanation / Answer
Matlab code
x = [10;100;1000;10000]; % column vector of x
% Part (i)
% Evaluating the tanh(x) function for each values in x
yi = (exp(x)-exp(-x))./(exp(x)+exp(-x));
% Part (ii)
% evaluating the tanh function using the matlabs internal function
yii = tanh(x);
% Part (iii)
% Evaluating the tanh function using the formula given in Part iii
yiii = (1-exp(-2*x))./(1+exp(-2*x));
% Displaying the results
fprintf('x Part (i) Part (ii) Part (iii) ');
fprintf('%d %1.3f %1.6f %1.6f ',[x';yi'; yii'; yiii']);
OUTPUT
x Part (i) Part (ii) Part (iii)
10 1.000 1.000000 1.000000
100 1.000 1.000000 1.000000
1000 NaN 1.000000 1.000000
10000 NaN 1.000000 1.000000
Remarks:
MATLAB may be using the formula given in the Part iii. For lager values of x the function exp(x) become infinity, hence the function given in the Part i will not work in Matlab, because the function will become Inf/Inf It is not a number (NAN) in matlab. That is why for x = 1000 and x = 10000, NAN printed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.