Good morning, I need to make a Function according to the image, but I do not have much knowledge with matlab
, could anyone help me? Thank you!
I was not going to respond, I understand that people need help, I will do my part, the question formula looks a lot like the Taylor series to find natural logarithm (as far as I remember the university lol).
To write a function using the equation of the statement is very simple, the sigma ( Σ ) of the formula tells us that you must sum the equation (-(x^n)/n)
, the iteration goes from 1
to infinito
, does not mean that we will be calculating this to infinity, in fact the iteration will end when the value of n
reaches the limit defined by the user, in the statement it leaves some things explicit, use x
between -1 e 1
, it also says ln(1-x)
is equal to Σ(-(x^n)/n)
, I will not do everything for you, this is the function that does exactly the calculation of the formula Σ(-(x^n)/n)
:
function F = equacao(x,n)
F=0
for n=1:n
F=F+(-(x^n)/n);
end
end
Yes ... this is what asks for the letter a
of the question, you may have to create within this function a if
that ensures that your x
is within the range that the exercise asks for .. .
But let's see if the Taylor series is correct? the return of this function is the same as ln(1-x)
? does it have some ready-made matlab function that computes this? What's up?
help log
Compute the natural logarithm, 'ln (X)', for each element of X.
When typing help log
this help appeared on the log function, this is exactly what we need right? let's compare using a x
that is within the range that the exercise asks for, for example x=0.3
log(1-0.3)
-0.35667
Now let's try using the function I created, sum with progression of 20
( n=20
), no matter the exercise of the letter a
was legal and let me use any value of n
and any value of x
between 1 e -1
:
equacao(0.3,20)
-0.35667
Bingoooo ln(1-x) é igual a Σ(-(x^n)/n)
huahuahua ONLY NOOOOO ... as far as I remember this series has a very poor accuracy to calculate the Natural Logarithm, is that why the exercise of the letter c
asked the relative error? lol ...
I've done a lot, the rest is up to you :-)