Calculating Area Under the Graph Using Visual Basic
Calculating Area Under the Graph Using Visual Basic
(OP)
Dear All,
I am looking for a way to calculate the area under a non linear graph. I know it can be easily done using spreadsheet but are there any way which I can utilise Visual Basic to do all the calculation in the background and come out with one results.
I have:
~~~~~~~
1. Equation of the non linear graph (Load vs Deflection)
2. I known deflection.
(which means that once I input the deflection I will get the load)
My concept:
~~~~~~~~~~~
For discussion purposes, the non linear equation is:
Load = 0.85*(Displacement)^2
First of all, I determind the size of decrement of displacement which I want, say 0.1mm.
I will use the basic trapeziod and triangle method to find the area.
However, if I used the STEP command, it will come out with a list of results (Load) if I display it in the spreadsheet.
My question is that without it displaying on the spreadsheet, how do I continue with the calculation in Visual Basic and come out with a single answer at the end.
Hope that I didn't confuse all of you.
Regards,
YEN
I am looking for a way to calculate the area under a non linear graph. I know it can be easily done using spreadsheet but are there any way which I can utilise Visual Basic to do all the calculation in the background and come out with one results.
I have:
~~~~~~~
1. Equation of the non linear graph (Load vs Deflection)
2. I known deflection.
(which means that once I input the deflection I will get the load)
My concept:
~~~~~~~~~~~
For discussion purposes, the non linear equation is:
Load = 0.85*(Displacement)^2
First of all, I determind the size of decrement of displacement which I want, say 0.1mm.
I will use the basic trapeziod and triangle method to find the area.
However, if I used the STEP command, it will come out with a list of results (Load) if I display it in the spreadsheet.
My question is that without it displaying on the spreadsheet, how do I continue with the calculation in Visual Basic and come out with a single answer at the end.
Hope that I didn't confuse all of you.
Regards,
YEN





RE: Calculating Area Under the Graph Using Visual Basic
Just sum up the single values calculated in each for loop into a variable and return the value of that variable...
prex
motori@xcalcsREMOVE.com
http://www.xcalcs.com
Online tools for structural design
RE: Calculating Area Under the Graph Using Visual Basic
Sorry.
Regards,
YEN
RE: Calculating Area Under the Graph Using Visual Basic
Good luck and keep us posted!
RE: Calculating Area Under the Graph Using Visual Basic
what prex is saying is to set up a looping proceedure that will step through each value in your set. For example, if you wanted to calculate the area under the graph from 1mm to 10mm with a step of .1mm, then you would have something to the effect of:
Sub AreaUnderGraph()
Dim Load As Double, Displacement As Double
Dim Area As Double, MySum As Double
MySum = 0
Displacement = InputBox("Enter the deflection:")
For i = 0 To Displacement Step 0.1
Load = 0.85 * (i) ^ 2
'...Area under graph equation here...: Area = (...)
MySum = MySum + Area
Next i
Range("A1").Value = MySum
End Sub
Where you as the user would enter "10" in the input box.
As you can see, using the for/next loop calculates the area under the curve from a displacement of 0 to a user specified displacement at a step of 0.1 and enters the sum into cell A1.
If you need more help, let me know
Good Luck!
jproj
RE: Calculating Area Under the Graph Using Visual Basic
Regards,
YEN
RE: Calculating Area Under the Graph Using Visual Basic
Eqn:
Load = 0.85*(Displacement)^2
I take it displacement is the variable:
C = 0.85 'a constant
x = displacement
y = Cx^2
To find the area under the curve:
/end
|
| Cx^2 dx
/start
Start is the starting point, say 1 and end is the end point say 10
Integrating the above equation leads to:
(C/3)(end^3 - start^3)
What jproj is doing is called a Rieman (sp?) sum and is a valid approach. But since the equation that you presented is rather simple, I would approach it using calculus. It has the advantages of being easy to code as well as being fast.
public function area(C as single, start as single, end as single)
area = (c/3)(end^3 - start^3)
end function
P.S. Correct me if I'm wrong it's been awhile since I used my calculus
Troy Williams
fenris@hotmail.com
RE: Calculating Area Under the Graph Using Visual Basic
Regards,
YEN
RE: Calculating Area Under the Graph Using Visual Basic
If you (or anyone else) have any need for it, I wrote a VBA program that uses Simpson's approximation to find the integral approximation of an equation between two finite numbers (Say the integral of Y = 0.85*X^2 from 1 to 3). Let me know and I'll post the code.
jproj
RE: Calculating Area Under the Graph Using Visual Basic
yliew@civag.unimelb.edu.au
Thanks again!
RE: Calculating Area Under the Graph Using Visual Basic
RE: Calculating Area Under the Graph Using Visual Basic
n is the number of function "slices" to evaluate.
a and b are the integration limits.
fun is the function definition.
h = (b-a)/n
x = a
k = 1
value = 0
for i = 2 to n
x = x + h
k = 3 - k
v = v + k*apply(fun,x)
next i
v = (2*v + apply(fun,a) + apply(fun,b))*h/3
RE: Calculating Area Under the Graph Using Visual Basic