Anonymous function hyperbolic function code

sinh(x) =(exp^(x)-exp(-x))/2
cosh(x) =(exp(x)+exp(-x))/2
anonymous functions mysinh(x) and mycosh(x)
which perform the calculations above. Call these functions and plot both mysinh and
mycosh from −2 ≤ x ≤ 2 using 1/100 increments on a single figure. Label, add a
legend, and title it ”Anonymous Output”.
Please help to write this function, Thanks I know about @, but I get errors all the time, so i feel lost here.

 Accepted Answer

Matt Fig
Matt Fig on 24 Sep 2012
Edited: Matt Fig on 24 Sep 2012
When asking for help, please be as specific as possible. You get errors? WHAT ERRORS?
snh = @(x) (exp(x)-exp(-x))/2
snh(1:5)
This sounds like homework. Please show all of the work you have done so far and describe where you are stuck.

7 Comments

it says converting to double function is not possible, and when I try to define a function at the beginning like function out=mysinh(x) ,it will say unknown matlab syntax! snh = @(x) (exp(x)-exp(-x))/2 snh(-2:2) csh = @(x) (exp(x)+exp(-x))/2
figure plot(snh,csh)
it is along homework, it has 4 parts, and that is the last part i'm stuck on, I tried to copy the whole code here , but it doesn't look good I don't know why
Did you try what I wrote?
When pasting your own code you need to paste the code, then highlight the code, then click the button that says: {} Code
function ssimaie_hw9
%
x=-pi:pi/100:pi;%x-values are Space
y=acos(exp(i*x)-i*sin(x));
y2=cos(x);
close all
%%Part 1 - Euler
% function out=exp(x*i)-i*sin(x) %You missed the point about function definitions. This line, like line 1, is just the [ou]=name(in) line - MM
%Try this:
function out=mycos(x)
out=exp(x*i)-i*sin(x) %ALWAYS define outputs as a function of inputs. - MM
%Nest a function here - and don't forget its matching end!
%This
%figure %To remind you to make separate windows for plots
end
figure
fplot(@mycos,[-pi pi])
%%Part 2 - Euler Error
function subfunction(x,y,y2)
y2=y2-y
end
figure %To remind you to make separate windows for plots
plot(x,y2)%plot(...)
%%Part 3 - Anonymous
%Define these:
snh = @(x) (exp(x)-exp(-x))/2
snh(1:5)
csh = @(x) (exp(x)+exp(-x))/2
%mycosh=
figure %To remind you to make separate windows for plots
%plot(...)
plot(snh,csh)
end
Ok, I tried what you said now this is the error:
Error using plot
Conversion to double from function_handle is not possible.
Error in ssimaie_hw9 (line 47)
plot(snh,csh)
Thank you very much, I know I might be asking stupid questions, but this is my last resource, and so far I learned lot from you, Thank you again!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 24 Sep 2012

Community Treasure Hunt

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

Start Hunting!