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

조회 수: 3 (최근 30일)
Big
Big 2011년 4월 27일
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
Andrew Newell
Andrew Newell 2011년 4월 27일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2011년 4월 27일
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
Walter Roberson
Walter Roberson 2011년 4월 27일
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...

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by