How to Graph and Use the Results of Numerical Integration as a Function

plwillson shared this question 2 years ago
Answered

I am a senior using my quarantine to learn geogebra and love what I've been able to do, but I have spent much time unsuccessfully trying to do something I suspect is simple. I have numerically integrated a function of the form: 1/(1/x^2+x+x^2)^.5. (It's the Friedman equation from general relativity and must be integrated numerically.) I want to graph the integral as f(x) and subsequently to use the resulting f(x) for additional calculations.

The only method I have found to graph it is using Locus(pointcreating, point). I get nothing from LocusEquation(Locus) and have not discovered another method for generating an equation. The integrand is singular for negative x and I have limited the range using If(x < 0, 0, integral()).

I would greatly appreciate any help,

Pete

Best Answer
photo

Well did not knew that either

g(x) = If(x > 0, 1 / (-0.00008 + 0.00008 / x^2 + 0.3 / x + 0.7 x^2)^0.5, 0)
DataFunction(Join({{0},Sequence(t, t, 0.1, 20, 0.1)}), Join({{0},Sequence(Integral(g, 0, t), t, 0.1, 20, 0.1)}))

Comments (14)

photo
1

this?

photo
1

Mathmagic, I'm very new to this and don't know if my initial response to you was posted. If so, I apologize for being redundant. Thank you again for your response. I don't see how to achieve either the accuracy or precision I need by using the freehand tool as you suggest. Perhaps I don't understand the tool. Could you explain in more detail, please?

I think my problem must have been solved. It is analogous to the acceleration, speed, and distance problem, i.e., one integrates the acceleration to get speed and uses speed and time to get distance. In my case the acceleration is not constant (there is jerk) and the acceleration must be integrated numerically to get the speed as a function of time. Only with that (numerical) function can one calculate distance as a function of time. In my case, the result of the numerical integration is an expansion parameter, which is analogous to speed as a function of time.

Pete Willson

photo
1

the method for numerical integral is runge-kutta I think. I can not speak about this question because I do not know the accuracy of the method in GG.

nintegral command give a colection of points that are an aprox solution of ODE


you can see it in my file typing l1 = First(Element({NSolveODE({f', g', h'}, 0, {1, 2, -2}, 3)}, 1), Length(Element({NSolveODE({f', g', h'}, 0, {1, 2, -2}, 3)}, 1)))

freehand creates a function with this list

photo
photo
1

Mathmagic, Thank you for responding. I am not certain how the freehand tool would provide me the accuracy that I need. For example, the integration over the very short interval from 0 to 1 leads to an estimate of the age of the universe and 4 significant figures is reasonable, The numerical integration over that interval is both accurate and precise enough, but I don't see how to achieve that same precision with the freehand tool. What am I missing?

Regards, Pete Willson

photo
1

can you provide your current state (your applet with that numerical integration)?

photo
1

Loco,

Here you go. The constants are currently hard coded in the function, but they will become parameters.

photo
1

Loco, I lost version control. Here is the correct file. Sorry!

photo
1

okay, there are different possible approaches in GGb


you could determine some data points and define linear or some other functions over some subsets and use them for further computation kinda like (FEM)

or you could use some function fit over the data points that you want to have as function

or you use the approach of mathmagic which was unknown to me (for sure undocumented functionality) that approach uses the given function to numerically integrate extract the data points and use them for a linear interpolated free hand function?

g(x) = If(x > 0, 1 / (-0.00008 + 0.00008 / x² + 0.3 / x + 0.7x²)^0.5, 0)

f(x) = Function(Join({{0, 40}, Zip(y(P), P, First(Element({NSolveODE({g}, 0, {0}, 40)}, 1), Length(Element({NSolveODE({g}, 0, {0}, 40)}, 1))))}))

photo
1

DataFunction() might be better than Freehand function, eg https://www.geogebra.org/m/nrxmfnmf

photo
3

Well did not knew that either

g(x) = If(x > 0, 1 / (-0.00008 + 0.00008 / x^2 + 0.3 / x + 0.7 x^2)^0.5, 0)
DataFunction(Join({{0},Sequence(t, t, 0.1, 20, 0.1)}), Join({{0},Sequence(Integral(g, 0, t), t, 0.1, 20, 0.1)}))

photo
1

note: datafunction is not updated automatically. it needs to be updated with a script

photo
1

Thanks very much to each of the three of you. I have enough to give it a try--I was stumped! I can also compare results with an excel calculation from an independent party. Unfortunately it will be a good four hours before I am able to do so, but I will report the results.

Michael, you asked for an example of subsequent calculation. This function is the so-called scale factor in cosmology that comes from the Friedman solution to Einstein's (gravitational) field equation. I will use it subsequently in a model to calculate and plot the expansion of the universe as function of time following the "big bang". I'll also use it to calculate the (geodesic) paths that light travels as space (the universe) expands. I'm trying to animate some of this to help others visualize the expanding universe. The dynamic geometry is not easy to visualize. This is neither new science nor aimed at any commercial endeavor--I'm a (retired) volunteer who likes to teach.

photo
1

PERFECT! Thank each of you--it works perfectly. I had spent soooo much time trying figure out how to do this. The most important check of accuracy/precision is spot-on to at least four significant figures.

Perhaps there are two options for dynamic updates. The only things that change are the individual coefficients in the denominator of the the function (and their sum, which is also in the denominator). I thought perhaps a simple If statement that checked the sum of the coefficients to trigger a recalculation may be simpler than a script. I visited Michael's Piece-Wise Curve on the website, but am unable to figure out how to see the underlying script.

Thank you again. I hope that I, too, will be able to help somebody in the future.

There must be a way to mark this as "solved", but I don't find the button.

Pete Willson

photo
photo
1

subsequently to use the resulting f(x) for additional calculations.
For example...?

© 2023 International GeoGebra Institute