Hyperbolic sine, cosine, and tangent with arguments, please help

3 visualizaciones (últimos 30 días)
Big
Big el 27 de Abr. de 2011
Write a single MATLAB function to calculate the hyperbolic sine, cosine, and tangent functions. The function should have two arguments. The first argument will be a string containing the function names ‘sinh’, cosh, or ‘tanh’, and the second argument will be the value of x at which to evaluate the function. The file should also contain three subfunctions sinh1, cosh1, and tanh1 to perform the actual calculations, and the primary function should call the proper subfunction depending on the value in the string. [Note: Be sure to handle the case of an incorrect number of arguments, and also the case of an invalid string. In either case, the function should generate an error.]
You can create 4 function files separately, sinh1.m, cosh1.m, tanh1.m, and hyperbolic.m.
The function statements are:
function result = sinh1(x)
function result = cosh1(x)
function result = tanh1(x)
function result = hyperbolic(functionname, x)
In hyperbolic.m, if function name is ‘sinh’, call sinh1(x). similarly handle ‘cosh’, tanhand other invalid string.
1. write a function hyperbolic(x,y), to test the function, run hyberbolic(‘sinh’, 1), hyberbolic(cosh, 2), hyberbolic(tanh, 3),
2. When running hyberbolic(‘sinh’, 1), using sinh1(x) for calculation.
3. You must write the user-defined functions and can not use MATLAB
built-in function sinh, cosh, and tanh.
4. Handle the case of an invalid number of arguments, and also the case of an invalid string.
Here are the user defined functions for sinh1(x), cosh(x), and tanh1(x).
sinh(x) = (e^x - e^-x)/2
cosh(x) = (e^x + e^-x)/2
tanh(x) = (e^x - e^-x)/(e^x + e^-x)
  1 comentario
Andrew Newell
Andrew Newell el 27 de Abr. de 2011
ELFS: What is wrong with this question? You may use http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers to help you answer it.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Abr. de 2011
There isn't much to do other than to copy and paste from the assignment in to your code, make a trivial syntax modification, and add in some error checking.
  1 comentario
Walter Roberson
Walter Roberson el 27 de Abr. de 2011
Of course if the teacher will be deducting marks for miscalculating the solutions, you might want to give some serious thought to how you could increase accuracy compared to the obvious method...

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by