The hyperbolic cosine function is defined by the equation cosh x = (e x + e -x )
ID: 1716296 • Letter: T
Question
The hyperbolic cosine function is defined by the equation
cosh x = (ex + e-x)/2
Write a MATLAB program to calculate the hyperbolic cosine of a user-supplied value x. Use the program to calculate the hyperbolic cosine of 3.0. Compare the answer that your program produces to the answer produced by the MATLAB intrinsic function cosh(x). Use fprintf to display the results to control the number of digits displayed after the decimal point. Also, use MATLAB to plot the functioncosh(x). what is the smallest value that this function can have? At what value of xdoes it occur?
Explanation / Answer
%%Code to hyperbolic function
clc
clear
x=input('input x= ');
%% Finding cosh for given x
y=(exp(x)+exp(-x))/2;
fprintf('code value of cosh(x)=%6.4f ',y);
y2=cosh(x);
fprintf('inbuit cosh(x)=%6.4f ',y2);
if (y==y2)
disp('Code output of cosh and inbuilt function cosh are equal ')
end
for x=0:100
i=x+1;
y=(exp(x)+exp(-x))/2;
y1(i)=y;
x1(i)=x;
y33=min(y1);
if(y33==y1(i))
x22=x1;
y44=y1;
end
end
fprintf('value of x where cosh is minimum x = %6.4f ',x22);
fprintf('minimum value of cosh(x) = %6.4f ',y44);
plot(x1,y1)
OUTPUT:-
input x= 3
code value of cosh(x)=10.0677
inbuit cosh(x)=10.0677
Code output of cosh and inbuilt function cosh are equal
value of x where cosh is minimum x = 0.0000
minimum value of cosh(x) = 1.0000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.