Answer the question
In order to leave comments, you need to log in
PascalABC.NET does not count logarithm
In the lab, you need to calculate the logarithm.
I use a function from the base library Ln .
I pass 1 as an argument (in a variable).
Outputs : -1.11022302462516E-16.
What to do?
Answer the question
In order to leave comments, you need to log in
Most likely, he just gave you an approximate value and you need to round it up, because you don’t store 1 in the variable.
Check again what you have stored in the variable, if it doesn’t help, then throw off the program code and I’ll take a look.
For example, the code below returns 0
var i: double;
begin
i:=1;
writeln(Ln(i));
end.
All finally figured out!!!
There is a small error in the calculation of the tangent:
(so the value of Pi is constant and equal in the standard library PABCSystem Pi = 3.141592653589793)
n1 + n2 = 0.785398163397448;
tan(n1 + n2)=1.0000...
Most likely that is why, as a result of calculating the value of the logarithm, we get an approximate value of 0.0000000000000001...
I think that such an error is quite normal...
PS
I immediately answer your comment: "I understand, shitcode, but it's just laba))" I advise you to immediately download skills on writing good code on the labs, although the code is not particularly bad.
Thank you for your attention and success in your studies!
///Возвращает интеграл
function Integral(var x: integer; n: integer): real;
var
tng, temp: real;
n1, n2: real;
begin
if n = 1 then
begin
n1 := (Pi / 4);
n2 := (x / 2);
tng := tan(n1 + n2);
temp := ln(tng);
integral := temp;
//компилятор неверно считает логарифм!!!
end;
if n = 0 then
integral := x;
if n >= 2 then
integral := ((1 / n - 1) * (sin(x)) / power(cos(x), n - 1)) + (((n - 2) / (n - 1)) * integral(x, n - 2))
else
end;
//Разобраться со ссылками на параметры
var
x: integer;
n: integer;
begin
writeln('read(x)');
read(x);
writeln('readln(n)');
readln(n);
//writeln('Интеграл dx/(cos', x, ')^', n, '=', integral(x, n));
end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question