Help Please! Numerical methods help

I need help I am trying to understand why this does not work properly I know logspace starts off the with value of 10 to the a and ends with 10 to the b and the last number spaces out
The aS (absolute error) and rS (relative error) should be very small but it is not
here is my code:
x=logspace(-12,12,100); s =.5.*(exp(x)-exp(x)); S = sinh(x); aS = abs((s-S)/(S)); rS = abs((s-S)); %This is the actual function for sinh(x) and that is why it is such % a small value for sinh(x) loglog(aS,'b') hold on loglog(rS,'r')

 채택된 답변

Matt Fig
Matt Fig 2011년 3월 19일

0 개 추천

You are missing a dot (.) and a minus (-).
x=logspace(-12,12,100);
s =.5.*(exp(x)-exp(-x));
S = sinh(x);
aS = abs((s-S)./(S));
rS = abs((s-S));
loglog(aS,'b')
hold on
loglog(rS,'r')
.
.
As far as to why there are differences between the two results, look at your range for x, then remember that MATLAB uses floating point arithmetic. In the exponential formula, you are finding the difference between two numbers which have vastly different magnitudes. I suspect the built-in SINH function is specially formulated to avoid these kinds of roundoff errors.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2011년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by