# Software for finding functions

• Einstein44
In summary,You are looking for a simple interpolation. My first suggestion would be to look for a cubic spline extention to Excel - or whatever spreadsheet software you used. The result will be a piece-wise set of functions - one function for each interval.
Einstein44
Homework Statement
I am trying to find the volume of a bottle using the disk method for integration. Dies anyone know a software where I can plot the points of the bottle and it would give me the function for the contour of the bottle?
Or does anyone know if it is possible to find the functions by hand using measurements?
Relevant Equations
.
.

Your looking for a simple interpolation. My first suggestion would be to look for a cubic spline extention to Excel - or whatever spreadsheet software you used.

The result will be a piece-wise set of functions - one function for each interval.

Einstein44, FactChecker and RPinPA
.Scott said:
Your looking for a simple interpolation. My first suggestion would be to look for a cubic spline extention to Excel - or whatever spreadsheet software you used.

The result will be a piece-wise set of functions - one function for each interval.
Thank you, I will try doing that.

If you're just using measured points then you're usually best off to use a numerical integrator like Simpson's rule or a Gauss quadrature. Essentially these methods both fit a polynomial to the points and calculate the area/volume in the one hit.

For the case of Simpson's rule the polynomial fit is just a quadratic (for each three points), but there are other better numerical integrators (like Gauss quadrature) which are extremely efficient.

For a simple example, consider the volume under $y = 1 + 2x - x^2$ rotated around the x-axis between x=0 and x=2.

It's easy to do this one analytically and find the exact value of $\frac{86 pi}{15}$ (approx 18.01 units cubed).

To apply Simpson's rule (with sample points at x = 0, 1, 2) you would proceed as follows.
$$V \simeq \pi \cdot \frac{1}{3} [1 \cdot y(0)^2 + 4 \cdot y(1)^2 + 1 \cdot y(2)^2] = 6 \pi$$
That three point Simpson's rule is is out by about 5% (in this example), but you can check that a five point evaluation here is accurate to about 0.3%.

Simpson's rule is easy to apply (and easy to remember), but there are much better numerical integrators available. Gauss quadrature formulas are extremely efficient and a simple 3 point GQ can remarkably handle up to a 5th order polynomial with perfect accuracy.

To apply a Gauss quadrature in the above example we would use sample points $x = (1-\sqrt{0.6},\, 1, \, 1+\sqrt{0.6} )$ with respective weightings of $(5/9, \, 8/9, \, 5/9)$

If you apply this to the above problem (as in $V = \pi (b-a)/2 \cdot \sum w_i y^2(x_i)$ then you'll find it gives the exact answer of $86 \pi / 15$

Einstein44 and berkeman
uart said:
If you're just using measured points then you're usually best off to use a numerical integrator like Simpson's rule or a Gauss quadrature. Essentially these methods both fit a polynomial to the points and calculate the area/volume in the one hit.

For the case of Simpson's rule the polynomial fit is just a quadratic (for each three points), but there are other better numerical integrators (like Gauss quadrature) which are extremely efficient.

For a simple example, consider the volume under $y = 1 + 2x - x^2$ rotated around the x-axis between x=0 and x=2.

It's easy to do this one analytically and find the exact value of $\frac{86 pi}{15}$ (approx 18.01 units cubed).

To apply Simpson's rule (with sample points at x = 0, 1, 2) you would proceed as follows.
$$V \simeq \pi \cdot \frac{1}{3} [1 \cdot y(0)^2 + 4 \cdot y(1)^2 + 1 \cdot y(2)^2] = 6 \pi$$
That three point Simpson's rule is is out by about 5% (in this example), but you can check that a five point evaluation here is accurate to about 0.3%.

Simpson's rule is easy to apply (and easy to remember), but there are much better numerical integrators available. Gauss quadrature formulas are extremely efficient and a simple 3 point GQ can remarkably handle up to a 5th order polynomial with perfect accuracy.

To apply a Gauss quadrature in the above example we would use sample points $x = (1-\sqrt{0.6},\, 1, \, 1+\sqrt{0.6} )$ with respective weightings of $(5/9, \, 8/9, \, 5/9)$

If you apply this to the above problem (as in $V = \pi (b-a)/2 \cdot \sum w_i y^2(x_i)$ then you'll find it gives the exact answer of $86 \pi / 15$

I am not familiar with this yet, but I will definitely have a look at it. Thank you!

.Scott said:
Your looking for a simple interpolation. My first suggestion would be to look for a cubic spline extention to Excel - or whatever spreadsheet software you used.

The result will be a piece-wise set of functions - one function for each interval.
Ive thought about this and I am thinking of simply calculating the cubic spline functions by hand, using a few points and then integrating this using the disk method to find the volume of the shape I want.
Does that work?

.Scott
Einstein44 said:
Ive thought about this and I am thinking of simply calculating the cubic spline functions by hand, using a few points and then integrating this using the disk method to find the volume of the shape I want.
Does that work?
Yes.

.Scott said:
Yes.
Ok. What points and how many should I select? Do you just select the points at a turning point? And from what I saw so far, the more points, the longer the calculation?

@Einstein44 :

We'll position the bottle so its rotation axis is the x-axis.
The points you have on the bottles surface (inside or outside - depending on which volume you want) will be a series of (x,r) pairs with monotonically increasing x values, such as this:
(0,1.8), (0.5,2), (3,2), (3.5,1), (4,0.5), (5,0.5)

I then choose the Monotone cubic Hermite interpolation for my interpolations.
This requires that the slope of the curve be known at each sample point.

So I set up my spread sheet as follows:
Rows 1 and 3: Left blank.
Row 2: field labels in bold starting in column B: X, R, m, T3, T2, T1, T0, Width, V/(Pi W), V
Rows 4-9, my sample points and calculations:
-- Column B - The "X"s: 0, 0.5, 3, 3.5, 4, 5
-- Column C - The "r"s: 1.8, 2, 2, 1, 0.5, 0.5
-- Column D - The "m"s (slopes):
-- -- Use =IF(OR(C3="",C5=""),0,(C5-C3)/(B5-B3)) for D4, then copy that to D5-9.
-- -- My results are 0, 0.067, -0.333, -1.5, -0.333, 0
-- -- Note 1: that the method I am using forces the endpoint slopes to zero.
-- -- Note 2: This is not the same "Interpolant Selection" specified in the wiki article.
-- Column E to H (parameters to the cubic function of t):
-- -- In each case, I am specifying the equation that appears in Row 4.
-- -- That value must then be copied to rows 5 to 8 (row 9 is left blank).
-- -- E (factor for ##t^3## term): =2*C4+D4-2*C5+D5
-- -- F (factor for ##t^2## term): =-3*C4-2*D4+3*C5-D5
-- -- G (factor for ##t^1## term): =D4
-- -- H (factor for ##t^0## term): =C4
-- -- Note: These formula are based on the "expanded" column of the equations for the Cubic spline Representations table.
-- Column I (Width):
-- -- Use =B5-B4 for I4, then copy that to I5-9.
-- -- Note: These are the "widths" of the spline segments. These values needs to be multiplied into the final volume calculation for each segment.

-- Column J (Volume/##\pi## Width):
-- -- I have set you up for the integration. Each segment is the integration of t=0 to 1 of the cubic polynomial with terms T3, T2, T1, and T0. I removed the "pi" factor from the integration - saving it for the last step.
-- -- I'm expecting you to do this step !

-- Column K (Volume):
-- -- Some simple multiplies and then add up the segments.
-- -- I'm expecting you to do this step !

My result was 43.66:
 My​ Example​ ​ ​ ​ ​ ​ ​ ​ ​ X​ R​ m​ T3​ T2​ T1​ T0​ Width​ V/(Pi W)​ V​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ 0.0000​ 1.8000​ 0.0000​ -0.3333​ 0.5333​ 0.0000​ 1.8000​ 0.5000​ *.****​ *.****​ ​ 0.5000​ 2.0000​ 0.0667​ -0.2667​ 0.2000​ 0.0667​ 2.0000​ 2.5000​ *.****​ *.****​ ​ 3.0000​ 2.0000​ -0.3333​ 0.1667​ -0.8333​ -0.3333​ 2.0000​ 0.5000​ *.****​ *.****​ ​ 3.5000​ 1.0000​ -1.5000​ -0.8333​ 1.8333​ -1.5000​ 1.0000​ 0.5000​ *.****​ *.****​ ​ 4.0000​ 0.5000​ -0.3333​ -0.3333​ 0.6667​ -0.3333​ 0.5000​ 1.0000​ *.****​ *.****​ ​ 5.0000​ 0.5000​ 0.0000​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ 43.6614​

As a check, I did this without interpolation and got 45.1447.

The Example Bottle:

Last edited:
Einstein44
Einstein44 said:
I am trying to find the volume of a bottle using the disk method for integration. Dies anyone know a software where I can plot the points of the bottle and it would give me the function for the contour of the bottle?
.

.
What form is the data that you have about the bottle. Is it given as a scaled drawing, or is it given as a discrete set of points? (or perhaps it's an actual physical bottle you have?) I'm wondering if you can you sample the radii at arbitrary locations or not.

It would help if you could you post your bottle data (or a link to an image etc) here.

Einstein44
uart said:
What form is the data that you have about the bottle. Is it given as a scaled drawing, or is it given as a discrete set of points? (or perhaps it's an actual physical bottle you have?) I'm wondering if you can you sample the radii at arbitrary locations or not.

It would help if you could you post your bottle data (or a link to an image etc) here.

I actually have the bottle, however I do not want to post the concrete bottle or I am going to get a plagiarism strike for posting my own stuff on here. So here is a brief sketch of the contour of the bottle, if this is any help to you.

For the forms of data: I basically took an image and imported it into some software, where I plotted the points along the bottle with decent accuracy. I have to do this again now, which is what I am going to do after this.
By arbitrary locations, do you mean the radii at the different points along the bottle, such as where it is flat, curved, etc?

Einstein44 said:
View attachment 287474
I actually have the bottle ... I basically took an image and imported it into some software, where I plotted the points along the bottle with decent accuracy. By arbitrary locations, do you mean the radii at the different points along the bottle, such as where it is flat, curved, etc?

Ok that's good to know, it's an actual bottle. Are you trying to find the "outer" volume or are you accounting for the wall thickness?

Yes by arbitrary positions I mean can you measure the radius at arbitrary points along the axis. From your description it appears that you can.

Was it asked (or implied) in the question that you use any particular method to solve it?

uart said:
Ok that's good to know, it's an actual bottle. Are you trying to find the "outer" volume or are you accounting for the wall thickness?

Yes by arbitrary positions I mean can you measure the radius at arbitrary points along the axis. From your description it appears that you can.

Was it asked (or implied) in the question that you use any particular method to solve it?
I am just finding the volume without counting for wall thickness, which is something I will mention in the evaluation part if there should be small errors.

For the method: This is basically a topic I chose on my own and decided to do it using integration, since the math behind it is appropriate. Although for finding the functions for example, using some methods such as cubic spline should be a nice addition to it I think. The only thing is the maths has to be complicated enough and have enough.

Einstein44 said:
The only thing is the maths has to be complicated enough and have enough.
Ok that makes sense to do it that way then. Normally the easiest way to measure the volume with a physical bottle you have in hand is to pour the contents into measuring jug or other suitable container. Or if measuring the outer volume of a complex shape to submerge it and measure the volume displaced.

From your sketch it's something like this PTE Fanta bottle then? Unfortunately there is no radial symmetry near the base of the bottle, so this will probably limit the accuracy you can obtain. Personally I'd just use a cylinder appox for the lower half and about a 7 point Simpson's rule for the upper curved part. It will also be worthwhile considering what approximations you could use to account for the non radial symmetry near the base.

Einstein44
uart said:
Ok that makes sense to do it that way then. Normally the easiest way to measure the volume with a physical bottle you have in hand is to pour the contents into measuring jug or other suitable container. Or if measuring the outer volume of a complex shape to submerge it and measure the volume displaced.

From your sketch it's something like this PTE Fanta bottle then? Unfortunately there is no radial symmetry near the base of the bottle, so this will probably limit the accuracy you can obtain. Personally I'd just use a cylinder appox for the lower half and about a 7 point Simpson's rule for the upper curved part. It will also be worthwhile considering what approximations you could use to account for the non radial symmetry near the base.
View attachment 287475
Yes, this is the kind of shape of the bottle. What I thought for the bottom was to model one hole and then kind of subtract that by the number of holes there are...
I don't know if doing approximations would really be appropriate here.
I am not familiar with Simpsons rule, but I will have a look at what it is and how it can be applied to this problem.

Edit: why are you suggesting Simpsons rule for the upper curved part?

Einstein44 said:
I don't know if doing approximations would really be appropriate here.
Edit: why are you suggesting Simpsons rule for the upper curved part?
The whole thing is inherently an approximation, from the measurements themselves down to the accuracy to which the spines fit the actual profile. Even if you do "exact" (algebraic) integration of the resulting spline functions, it's still an approximation as the spline itself is an approximation. Looking at the base, you are most likely going to be making some approximations in order to even describe the shape of the "lobes" that you are going to subtract.

If you really believe that you are calculating the volume to some kind of infinite precision then this will definitely be a learning experience. You will be able to test your answer at the end by comparing it to a simple measuring jug experiment result (take the average of several measurements).

I'm suggesting Simpson rule (on y^2 not y) as it's a fairly easy method and a reasonably efficient way of obtaining this inherently approximate result. A Gauss or Gauss Lobatto quadrature (see previous link) would be even more accurate, but is a little more complicated to explain. Simpson rule is simple, and with 7 points (in the curved region) will probably be accurate to around 1% (not withstanding the accuracy of the actual point measurements themselves).

BTW. Simpsons rule is one of the simpler numerical integration methods and quite easy both to implement and to understand. It's really just the next step up from the very simple trapezoidal method (though a lot more accurate for smooth functions). As with all numerical integration methods, the more regions you divide it into the more accurate the result.

Last edited:
Einstein44
uart said:
The whole thing is inherently an approximation, from the measurements themselves down to the accuracy to which the spines fit the actual profile. Even if you do "exact" (algebraic) integration of the resulting spline functions, it's still an approximation as the spline itself is an approximation. Looking at the base, you are most likely going to be making some approximations in order to even describe the shape of the "lobes" that you are going to subtract.

If you really believe that you are calculating the volume to some kind of infinite precision then this will definitely be a learning experience. You will be able to test your answer at the end by comparing it to a simple measuring jug experiment result (take the average of several measurements).

I'm suggesting Simpson rule (on y^2 not y) as it's a fairly easy method and a reasonably efficient way of obtaining this inherently approximate result. A Gauss or Gauss Lobatto quadrature (see previous link) would be even more accurate, but is a little more complicated to explain. Simpson rule is simple, and with 7 points (in the curved region) will probably be accurate to around 1% (not withstanding the accuracy of the actual point measurements themselves).

BTW. Simpsons rule is one of the simpler numerical integration methods and quite easy both to implement and to understand. It's really just the next step up from the very simple trapezoidal method (though a lot more accurate for smooth functions). As with all numerical integration methods, the more regions you divide it into the more accurate the result.
I don't see the point in using the Simpsons rule to be honest... I just looked it up and it seems to me as if its simply a way to get around having to work out the integral (which is no problem for me)... I also think that this is perhaps too simple to include in this project. And if I understand this correctly you need the integral with the function in it before anyways, so it really makes no difference?
By the way, isn't it simply possible to create a cosine function without using any calculations like the cubic spline by simply plotting some points on a graph by taking measurements and then calculating the cos function very simply?
(if yes, how could the horizontal shift be determined)
Or should I stick to calculating this using the cubic spline?
What is the exact reason you suggest Simpsons rule as opposed to doing the actual integration ?

Einstein44 said:
I don't see the point in using the Simpsons rule to be honest... I just looked it up and it seems to me as if its simply a way to get around having to work out the integral (which is no problem for me)...
No, this is the part that you are not understanding. You are never finding the exact value of the integral, because you never have an exact function to integrate in the first place. Numerical integrals like Simpson rule DO find the exact value of an integral, the integrand being the parabola that passes through any given three points. This parabola however may not be the exact function you are trying to integrate. This is no different to a function given by a spline. You can find the exact integral of the spline, but that spline however may not coincide exactly with the function (square of the profile) that you are trying to integrate. There is no *fundamental* difference in this respect.

There is a difference of course in just how well each function approximates your desired profile, but this can be compensated for by just using a few more points. For any finite given working time, I think you can obtain a better approximation via numerical integration. It's generally well known that numerical integration is the most efficient way to calculate an integral where only point wise evaluations are available (rather than a given continuous function).

If you feel Simpsons rule is too simple for the degree of mathematical difficulty expected in the task, then have a crack at using the Gauss Lobatto quadrature. Two intervals of a 5 point GLQ (requiring 9 measured points) over the curved part of the bottle will give an extremely accurate result.

Last edited:
pbuk and Einstein44
Einstein44 said:
Or should I stick to calculating this using the cubic spline?
Unless you want to make this deliberately more difficult, I would stick with the Monotone cubic Hermite interpolation (McHi) that I used above. Just provide enough points to match the bottle shape to whatever accuracy you wish.
The advantage (or perhaps in your case, disadvantage) of the McHi is that it is pretty simple to integrate.

BTW, my drawing of the bottle was created by using a spreadsheet program (LibreCalc) to calculate 51 points along the length of the bottle (using the interpolation) and putting the result in "L0 0" form so I could output it as an SVG file. Then I did a screen capture to get the png file that I posted.

Archimedes has provided you a direct way of measuring the outside volume of the bottle:
1) Fill the bottle with water (to make it uncrushable).
2) Partially fill a cylindrical pot with water - enough to submerge the bottle.
3) Submerge the bottle.
4) Measure the water level rise and the inside diameter of the pot.

pbuk

## 1. What is "Software for finding functions"?

Software for finding functions is a type of computer program that is designed to help users find mathematical functions based on given data or patterns. It uses algorithms and mathematical models to analyze patterns and relationships in data and generate a function that best fits the data.

## 2. How does "Software for finding functions" work?

Software for finding functions works by taking in a set of data points or a pattern and using mathematical algorithms and models to find a function that best fits the data. It may use techniques such as regression analysis, curve fitting, or machine learning to generate the function.

## 3. What are the benefits of using "Software for finding functions"?

Using software for finding functions can save time and effort in manually finding and analyzing functions. It can also help identify patterns and relationships in data that may not be easily visible to the human eye. This can be useful in various fields such as engineering, finance, and data analysis.

## 4. Are there any limitations to "Software for finding functions"?

While software for finding functions can be a useful tool, it is not infallible. It may not be able to find a perfect function for every set of data, and the generated function may not always accurately represent the data. It also relies on the quality and quantity of the input data provided.

## 5. How can I choose the right "Software for finding functions" for my needs?

Choosing the right software for finding functions depends on your specific needs and the type of data you are working with. Some programs may be more suitable for certain types of data or have more advanced features. It is important to research and compare different options to find the best fit for your needs.

• Precalculus Mathematics Homework Help
Replies
10
Views
600
• Programming and Computer Science
Replies
9
Views
585
• Special and General Relativity
Replies
2
Views
584
• Precalculus Mathematics Homework Help
Replies
15
Views
627
• Art, Music, History, and Linguistics
Replies
14
Views
1K
• Mechanical Engineering
Replies
7
Views
1K
• New Member Introductions
Replies
1
Views
92
• Feedback and Announcements
Replies
23
Views
839
• Computing and Technology
Replies
12
Views
1K
• Electrical Engineering
Replies
18
Views
1K