I am working on some Numerical Analysis with Maple as a part of my course and I am not sure where my error is with the code I am using.. If anyone can point out my flaw It would be very much appreciated as I seem to be getting the answer wrong.
f(x)=sqrt((cosh(x))^2 + 1) - sinh(x). Find a good approximation to f(4.86) using a 6-digit arithmetic. Then, Use 20 digit arithmetic to calculate the relative error. Finally, round it to 6 (significant) digits
f := sqrt(cosh(x)^2+1)-sinh(x);
f1 := evalf[6](f(4.86));
f1 := 0.0155
f2 := evalf(f(4.86));
f2 := 0.01550004
Digits := 20;
Digits := 20
Q4 := abs((f2-f1)/f2);
Q4 := 0.0000025806385015780604437
Digits := 6;
Digits := 6
evalf[6](Q4);
0.00000258064
Thanks everyone
You've made one syntax transcription mistake, and one Maple programming mistake.
Your first line is
f := sqrt(cosh(x)^2+1)-sinh(x);
but you subsequently call it like an operator (procedure), eg. f(4.86)
and obtain a numeric value. Therefore you must have originally used something like this procedure, instead.
f := x -> sqrt(cosh(x)^2+1)-sinh(x);
So that was likely just a transcription error when posting here.
You have made a programming mistake, in computing
f2 := evalf(f(4.86));
before setting the working-precision environment variable Digits
to 20
. Thus you have computed f2
at only the default Digits=10
working precision. But from the wording of the question it seems that you are being asked to compute f2
also at 20 digits of working precision.
Your code might be revised as follows:
restart;
f := x -> sqrt(cosh(x)^2+1)-sinh(x):
f1 := evalf[6](f(4.86));
f1 := 0.0155
Digits := 20:
f2 := evalf(f(4.86));
f2 := 0.015500036806894590
Q4 := abs((f2-f1)/f2);
Q4 := 0.0000023746327217512077767
evalf[6](Q4);
0.00000237463
You have used two different mechanisms for specifying the working precision. You could have also done it (slightly more consistently in methodology) as follows:
restart;
f := x -> sqrt(cosh(x)^2+1)-sinh(x):
f1 := evalf[6]( f(4.86) );
f1 := 0.0155
f2 := evalf[20](f(4.86));
f2 := 0.015500036806894590
rel := evalf[20]( abs((f2-f1)/f2) );
rel := 0.0000023746327217512077767
evalf[6]( rel );
0.00000237463
There's always the possibility that I have misunderstood the question. What is the desired answer?