Matlab function for ln(1-x) approach

Asked

Viewed 458 times

0

inserir a descrição da imagem aqui

Good morning guys, I need to make a Function according to the image, but I do not have much knowledge with the matlab, Could someone help me ? Thank you !

1 answer

1

I wasn’t going to answer, I understand that people need help, I’ll do my part, the formula of the question 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 enunciation equation is very simple, the sigma(Σ) of the formula tells us that you must make the sum of the equation (-(x^n)/n), the iteration goes from 1 up to the infinito, does not mean that we will be calculating it to infinity, in fact the iteration will end when the value of n reach the limit set by the user, in the statement it makes explicit some things, use the x amid -1 e 1, he also says that ln(1-x) is equal to Σ(-(x^n)/n), I won’t do everything for you, this is the function that makes exactly the formula calculation Σ(-(x^n)/n):

function F = equacao(x,n)
F=0
for n=1:n
     F=F+(-(x^n)/n);
end
end

Yes... that’s what the lyrics say a of the question, maybe you have to create within this function a if which ensures that its x is within the range the exercise asks for...

But let’s see if Taylor’s series is correct ? the return of this function is the same as ln(1-x)? does it have any ready-made Matlab function that calculates this ? how about :

help log

Compute the natural logarithm, 'ln (X)', for each element of X.

When typing help log appeared this help 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 cool and let me use any value of n and any value of x amid 1 e -1 :

equacao(0.3,20)

-0.35667

Bingoooo ln(1-x) é igual a Σ(-(x^n)/n) huahuahua ONLY THAT NOT oooo... as far as I remember this series has a terrible precision to calculate the Natural Logarithm, will be that was why the exercise of the letter c asked for the error concerning ? lol...

I’ve done enough, the rest is up to you :-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.