Write three MATLAB functions to caiculate the hyperbolic sine, cosine, and tangent functions. $$ \sinh (x)=\frac{e^{x}-e^{-x}}{2}, \cosh (x)=\frac{e^{x}+e^{-x}}{2}, \tanh (x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}} $$ Use your functions to plot the shapes of the hyperbolic sine, cosine, and tangent functions.

Short Answer

Expert verified
Create three MATLAB functions to calculate the hyperbolic sine, cosine, and tangent functions as follows: 1. Hyperbolic Sine function: ```MATLAB function y = sinhfunc(x) y = (exp(x) - exp(-x))/2; end ``` 2. Hyperbolic Cosine function: ```MATLAB function y = coshfunc(x) y = (exp(x) + exp(-x))/2; end ``` 3. Hyperbolic Tangent function: ```MATLAB function y = tanhfunc(x) y = (exp(x) - exp(-x))/(exp(x) + exp(-x)); end ``` Then, plot the functions using this code: ```MATLAB x = linspace(-5, 5, 1000); y_sinh = sinhfunc(x); y_cosh = coshfunc(x); y_tanh = tanhfunc(x); subplot(3,1,1) plot(x, y_sinh) title('Hyperbolic Sine') subplot(3,1,2) plot(x, y_cosh) title('Hyperbolic Cosine') subplot(3,1,3) plot(x, y_tanh) title('Hyperbolic Tangent') ``` This will produce three separate plots for the hyperbolic sine, cosine, and tangent functions.

Step by step solution

01

1. Hyperbolic Sine function

Here is how to write a MATLAB function for the hyperbolic sine function: \[ \text{function y = sinhfunc(x)} \\ \text{y = (exp(x) - exp(-x))/2;} \\ \text{end} \]
02

2. Hyperbolic Cosine function

Here is how to write a MATLAB function for the hyperbolic cosine function: \[ \text{function y = coshfunc(x)} \\ \text{y = (exp(x) + exp(-x))/2;} \\ \text{end} \]
03

3. Hyperbolic Tangent function

And here is how to write a MATLAB function for the hyperbolic tangent function: \[ \text{function y = tanhfunc(x)} \\ \text{y = (exp(x) - exp(-x))/(exp(x) + exp(-x));} \\ \text{end} \]
04

4. Plotting the Functions

Now that we have the functions, we can make the plots of each function. Here's how to do it in MATLAB: \[ \text{x = linspace(-5, 5, 1000);} \\ \text{y_sinh = sinhfunc(x);} \\ \text{y_cosh = coshfunc(x);} \\ \text{y_tanh = tanhfunc(x);} \\ \text{subplot(3,1,1)} \\ \text{plot(x, y_sinh)} \\ \text{title('Hyperbolic Sine')} \\ \text{subplot(3,1,2)} \\ \text{plot(x, y_cosh)} \\ \text{title('Hyperbolic Cosine')} \\ \text{subplot(3,1,3)} \\ \text{plot(x, y_tanh)} \\ \text{title('Hyperbolic Tangent')} \\ \] This code will produce three separate plots, one each for the hyperbolic sine, cosine and tangent functions. The linspace function is used to generate a vector of evenly spaced points within a specified range, in this case from -5 to 5. This vector is then used as the input to each of the functions, and the output is plotted against the input. The subplot function is used to display multiple plots in a single figure window.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

The Birthday Problem. The birthday problem is: if there is a group of \(n\) people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation. Write a function that calculates the probabulity that two or more of \(n\) people will have the same birthday, where \(n\) is a calling argument. (Hint: To do this, the function should create an array of size \(n\) and generate \(n\) birthdays in the range 1 to 365 randomly. It should then check to see if any of the \(n\) birthdays are identical. The function should perform this experiment at least 5000 times and calculate the fraction of those times in which two or more people had the same birthday.) Write a test program that calculates and prints out the probability that 2 or more of \(n\) people will have the same birthday for \(n=2,3, \ldots, 40\).

Read Traffic Density. Function random0 produces a number with a uniform probability distribution in the range \([0.0,1.0)\). This function is suitable for simulating random events if each outcome has an equal probability of occurring. However, in many events the probability of occurrence is not equal for every event, and a uniform probability distribution is not suitable for simulating such events. For example, when traffic engineers studied the number of cars passing a given location in a time interval of length \(t\), they discovered that the probability of \(k\) cars passing during the interval is given by the equation $$ P(k, t)=e^{-\lambda t} \frac{(\lambda t)^{4}}{k !} \text { for } t \geq 0, \lambda>0, \text { and } k=0,1,2, \ldots $$ This probability distribution is known as the Poisson distribution: it occurs in many applications in science and engineering. For example, the number of calls \(k\) to a telephone switchboard in time interval \(t\), the number of bacteria \(k\) in a specified volume \(t\) of liquid, and the number of failures \(k\) of a complicated system in time interval \(t\) all have Poisson distributions. Write a function to evaluate the Poisson distribution for any \(k, t\), and A. Test your function by calculating the probability of \(0,1,2, \ldots, 5\) cars passing a particular point on a highway in I minute, given that \(\lambda\) is \(1.6\) per minute for that highway. Plot the Poisson distribution for \(t=1\) and \(\lambda=1.6\).

Use the Help Browser to look up information about the standard MATLAB function sortrows and compare the performance of sortrows with the sort-with-carry function created in the previous exercise. To do this, create two copies of a \(1000 \times 2\) element array containing random values, and sort column 1 of each array while carrying along column 2 using both functions. Determine the execution times of each sort function using tic and toe. How does the speed of your function compare with the speed of the standard function sorerows?

Dice Simulation. It is often useful to be able to simulate the throw of a fair die. Write a MATLAB function dice that simulates the throw of a fair die by returning some random integer between 1 and 6 every time that it is called. (Hint: Call randomo to generate a randem number. Divide the possible values out of random0 into six equal intervals, and return the number of the interval that a given random value falls into.)

Modify the selection sort function developed in this chapter so that it accepts a second optional argument, which may be either ' up ' or "down'. If the argument is 'up', sort the data in ascending order. If the argument is 'dewn', sort the data in descending order. If the argument is missing, the default case is to sort the data in ascending order. (Be sure to handle the case of invalid arguments, and be sure to include the proper help information in your function.)

See all solutions

Recommended explanations on Psychology Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free