MATLAB, function that evaluates sinh, cosh, tanh

  • Thread starter Thread starter btbam91
  • Start date Start date
  • Tags Tags
    Function Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 4K views
btbam91
Messages
91
Reaction score
0
Hey guys, my problem asks me to create one function, the incorporates the 3 functions (sinh, cosh, and tanh) that I created in the previous problem.

The function requires 2 arguments:

1. A string containing the function names 'sinh', 'cosh', 'tanh'
2. the value of x at which the function should be evaluated at


Here's my script thus far.


function result = myhyperbolic8_17('name',x);
%Purpose: Create a function that evaluates sinh, cosh and tanh, having all
%three of them as sub functions.

msg= nargchk(2,2,nargin);
error(msg);

function sinh = sinh1(x)

%State equation
sinh = ((exp(x) - exp(-x))/(2));
end

function cosh = cosh1(x)

cosh = ((exp(x) + exp(-x))/(2));
end

function tanh = tanh1(x)

tanh = ((exp(x) - exp(-x))/(exp(x) + exp(-x)));
end



%Initiate a switch for the parent, myhypberbolic8_17 function

switch (name)
case 'sinh'
result = sinh1(x);
case 'cosh'
result = cosh1(x);
case 'tanh'
result = tanh1(x);
otherwise
disp('Argument Error')
end
end


I guess the first problem is, how do I make it so that the overall function accepts a string as an input?

But when I do run this script with say:

myhyperbolic8_17(sinh,2)

I get an error message saying that sinh does not have enough arguments.




Thanks!
 
Physics news on Phys.org
Try:

Code:
myhyperbolic8_17('sinh',2)
with quotes