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.

 Réponse acceptée

Matt Fig
Matt Fig le 24 Sep 2012
Modifié(e) : Matt Fig le 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 commentaires

Salar
Salar le 24 Sep 2012
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)
Salar
Salar le 24 Sep 2012
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
Matt Fig
Matt Fig le 24 Sep 2012
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
Salar
Salar le 24 Sep 2012
Modifié(e) : Salar le 24 Sep 2012
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)
plot(x, snh(x), x, csh(x))
Salar
Salar le 25 Sep 2012
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Mobile Fundamentals dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by