- #1
btbam91
- 91
- 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!
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!