×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Calculating Area Under the Graph Using Visual Basic
4

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

RE: Calculating Area Under the Graph Using Visual Basic

Well, that's so simple that I wonder if...
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

(OP)
Prex thanks for your quick reply but I am not sure if I understand what you mean. Could you please elaborate?

Sorry.

Regards,
YEN

RE: Calculating Area Under the Graph Using Visual Basic

This sounds like you are doing an definite integral.  All calculus books should have a description of how to perform the calculation.  However, there is another method for doing this calculation.  Unfortunately, I can not remember the name of it right now.  I will look through some of my old school stuff and post any findings.  But in the mean time, try doing an internet search on definite integrals.

Good luck and keep us posted!

RE: Calculating Area Under the Graph Using Visual Basic

3
yliew:

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

(OP)
Many thanks to jproj and malone for contributing to the discussion. Jproj, what you have suggested is exactly what I need. Thanks!!!

Regards,
YEN

RE: Calculating Area Under the Graph Using Visual Basic

Why not do the calculus?

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

(OP)
Thanks Troy. I have since use calculus to find the area under the graph. Thanks for your advice!

Regards,
YEN

RE: Calculating Area Under the Graph Using Visual Basic

yliew:

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

(OP)
Jproj, thanks for the offer!!! Can you please email me your codes? My email address is:

yliew@civag.unimelb.edu.au

Thanks again!

RE: Calculating Area Under the Graph Using Visual Basic

JPROJ, SIMPSON's rule is exactly what I was thinking about.

RE: Calculating Area Under the Graph Using Visual Basic

Here is the procedure function code from the Simpson tool in the TK Solver math library.  You could link your spreadsheet with TK and have it do the calculations for you.  In this case, the best solution is just to do the calculus.

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

(OP)
Thanks TKsolver for your input!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close