Learning Calculus Online

Started by
15 comments, last by alvaro 8 years, 6 months ago
Your function integrates from 0 to x. If the value your are interested in is the integral from -infinity to x, you can break it up as the sum of the integral from -infinity to 0 plus the integral from 0 to x. The integral from -infinity to 0 is 0.5, which is why you are adding that at the end of the code.

Here you can look at the integral from 0 to x, or from -infinity to x, or from x to +infinity: http://www.mathsisfun.com/data/standard-normal-distribution-table.html
Advertisement
Oh, and one nitpick about your code: You really shouldn't use macros where functions are more appropriate.

For instance, this would work for the sin(x) case, but not for the exp(-x^2) case:
  int j = 1;
  while (j <= total)
    sum0 += Func(a + 2 * j++ * h); // This modifies j twice, and it's actually undefined behavior!

No problems if you defined Func like this:
double Func(double x) {
  return std::exp(-0.5 * x * x);
}
I'm aware of when macros are evil.
I'd not have shown that to someone in an interview. It's hack just for my learning process. In fact I didn't even write this code in C or C++. I'm using my script language which looks a lot like C.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


That would have helped significantly in understanding this mess. Now tons of crap falls into place. Now I can follow his code completely (until he does the strange refactors).
But how would anyone know that other than by him saying so? I don’t even see that on the page explaining Simpson’s Rule.

Same with the meaning of h. If all you have is the equation, how would you know what to do with h?





Well I feel less lost than I did before, although there are still very confusing things.

If you feel like you need to gain more theoretical knowledge of math, I would give you advice I have made myself.

I divide math into two subsets: "facts" (axioms, definitions), "findings" (statements, implications, methods..). Findings is such a rich subset of math, that you possibly cannot consume it, but facts are something that if you collect completely, you will be quite sufficient with theory.

The fact is that integration of a function relates to derivation of a function like this:

S(f'(x))=f(x) , where S stands for integral and ' for derivative

In other words, if someone puts integral in front of a function, he seeks a function that the function behind integral is the derivative of.

For example f(x)=2x , then S(f(x))=x^2 , because derivation of x^2 is 2x .

Then there is this interesting "finding" about integrals, that

S f(x)=F(x) , then F(b)-F(a) equals signed surface between x axis and function f(x) on the interval of x in [a,b], if f(x) has a limit on entire interval (is continious).

Also it has been agreed, that F(b)-F(a)=Sa,b what is called definite integral.

To prove this finding, you would need to know as well the definition of derivation of a function, and thus also limit of a function, what is quite too gigantic to even get a preview sight into, but I will try to elaborate further still:

Derivation of f(x) function at point a, exists if there is the limit of the function at point a, then f'(a) can be evaluated as lim (h->0) (f(a+h)-f(a))/h.

This would return a derivation at point a, what if you look closer is a tangential(tan()) of the function tangent at point a with x axis. But in general you want to find the derivation function- the function that will return the derivative of f(x) for any provided point x, thus finding f'(x), not only finding derivation at a single point.

So the last thing of this insight, is to define limit at point of a function, that is, if I will recall my memories from university, should be something not contradicting to this (a both sided limit at least)

lim x->a f(x)=v, if there exists s from R /{0}, for which two numbers L,K from R-{0} exist, so that [all f(x),x in (a-s,a+s), interval] is inclusive to ((v-L),(v+K)) interval.

This means that a limit of a function at a point is most of the time just the value of the function at that point, that is why you are generaly asked for limits rather like:

lim x->2 1/(x-2) where a limit does not exist

There is a lot wrong or confused with what JohnnyCode said. I am sure he is trying to help, and it is very possible that his imprecise knowledge of the subject is enough for his needs; but you should probably learn this from a more rigorous source.


There is a lot wrong or confused with what JohnnyCode said. I am sure he is trying to help, and it is very possible that his imprecise knowledge of the subject is enough for his needs; but you should probably learn this from a more rigorous source.

I left too many things open and didn't detail them. I would not state "something is wrong" about my post though. Appointing wrong stuff would not be off-topic I believe Alvaro, but I am aware that a tremendous pile of stuff can be nit-picked, since my syntax has been so obscure. I am always happy to learn up as well smile.png

I'll go a little bit into it.

The term "integral", the way you are describing it, is what is normally known as "primitive function", "indefinite integral" or "antiderivative".

Your post seems to imply that the definite integral is defined through the fundamental theorem of calculus, which is not true. The definite integral is a concept that has multiple definitions. If a function happens to have a primitive, you can compute its integral using the fundamental theorem of calculus, but there are many situations where you want to compute an integral of a function for which there is no primitive.


Derivation of f(x) function at point a, exists if there is the limit of the function at point a, then f'(a) can be evaluated as lim (h->0) (f(a+h)-f(a))/h.


No, that's not right: f(x) = abs(x) has a limit at x=0, and yet it doesn't have a derivative at that point. Your use of the word "derivation" here is also objectionable.

This topic is closed to new replies.

Advertisement