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.

 Risposta accettata

Matt Fig
Matt Fig il 24 Set 2012
Modificato: Matt Fig il 24 Set 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 Commenti

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
Salar
Salar il 24 Set 2012
Modificato: Salar il 24 Set 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))
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!

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by