473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Table interpolation..

Hello all,

I'm very new to visual basic and would like to have your help.

I have a two dimensional table with the values representing the mass. Each row representing a speed and each column represents a temperature. So that for a particular speed and temperature, you have a unique mass value.

The speed and temperature values are entered by the user. The code should give me the mass value for that particular speed and temperature. The code should give a interpolated value in case the speed or the temperature entered by the user is not found on the table.

How to implement this using visual basic? I just have the values. I need to create a table or array variables which represents the table mentioned above. Then the interpolation based on user input (speed and temperature).

Any directions on this would be really appreciated.

Thanks in advance.
Mar 5 '12 #1
17 8205
Guido Geurs
767 Expert 512MB
Please, is it possible to attach in Bytes a demo of the sheet with the values and an example of the end results?
If the sheet is to big, only a few values as example are enough.
Mar 7 '12 #2
Hi Guido,

I have the sample table in excel file but not sure how to attach the file to this post. Please help me.

Thanks..
Mar 8 '12 #3
@Guido Geurs
Hi Guido,

I might not have been clear in my earlier post. I have attached an image of the table.

The sample table represents the mass values for various speed and temperature.

For example, 40 is the mass for temperature 285 K and 1600 rpm

What if i need to find the mass for a temperature of 277 K at 1500 rpm?

Also, i need to know how to extrapolate the data.

What if i need to find the mass for a temperature of 265 K at 1500 rpm?

I would like to know how to implement the entire idea in visual basic, like implementing the table structure, interpolation and so on.

Hope my problem is clear now. Please guide me in this.

Thanks in advance.
Attached Images
File Type: jpg InterpolationTable.jpg (29.1 KB, 766 views)
Mar 8 '12 #4
Guido Geurs
767 Expert 512MB
attached is a zippd file with DOC and PDF file explaining how to attach files in Bytes.
Attached Files
File Type: zip Bytes_manual_v3.zip (241.2 KB, 286 views)
Mar 8 '12 #5
Rabbit
12,516 Expert Mod 8TB
Your chart looks wrong, should 1200 @ 270 = 26? It seems to break the pattern of the other values. Besides, you haven't specified what kind of interpolation you want to do, there are different types.
Mar 8 '12 #6
Guido Geurs
767 Expert 512MB
Do you want the results in a sheet with multible temps and speeds?
Or do you want to use a form on which the user enter the temp and speed in two textboxes and the interpolated mass is in a third textbox?
Mar 8 '12 #7
Guido Geurs
767 Expert 512MB
The function is linear.
Only the transposition is 5 for the first line (other = 6).
See attachment
Attached Files
File Type: xls Table interpolation_v1.0.xls (14.5 KB, 576 views)
Mar 8 '12 #8
Guido Geurs
767 Expert 512MB
How to interpolate:
1 - find the function for the line of the speed = interpolation between 2 speeds.
2 - mass = intersection between temp and found function for speed.
For more details: see attachment.
Attached Files
File Type: doc How to interpolate.doc (63.5 KB, 416 views)
File Type: pdf How to interpolate.pdf (40.1 KB, 530 views)
Mar 10 '12 #9
Guido Geurs
767 Expert 512MB
This is the code to use with an userform (see attachments)

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2. Dim TOPspeed As Double
  3. Dim BOTTOMspeed As Double
  4. '§ coordinates BOTTOM and TOP speed
  5. Dim TBSx1 As Double
  6. Dim TBSx2 As Double
  7. Dim By1 As Double
  8. Dim By2 As Double
  9. Dim Ty1 As Double
  10. Dim Ty2 As Double
  11. '§ coordinates SPEED
  12. Dim Sy1 As Double
  13. Dim Sy2 As Double
  14. '§ coordinates bottom speed
  15. Dim m_SLOPE As Double '§ m is the slope
  16. Dim b_Y_INTERSECT As Double '§ b is the y-intercept
  17.     Range("B3").Activate
  18.     '§ find first value > speed
  19.     Do Until ActiveCell.Value = ""
  20.         If ActiveCell.Value > Val(TextBoxSpeed.Text) Then
  21.             TOPspeed = ActiveCell.Value
  22.             BOTTOMspeed = ActiveCell.Offset(-1, 0).Value
  23.             TBSx1 = Range("C2").Value
  24.             TBSx2 = Range("D2").Value
  25.             By1 = ActiveCell.Offset(-1, 1).Value
  26.             By2 = ActiveCell.Offset(-1, 2).Value
  27.             Ty1 = ActiveCell.Offset(0, 1).Value
  28.             Ty2 = ActiveCell.Offset(0, 2).Value
  29.             Sy1 = (((Val(TextBoxSpeed.Text) - BOTTOMspeed) / (TOPspeed - BOTTOMspeed)) * (Ty1 - By1)) + By1
  30.             Sy2 = (((Val(TextBoxSpeed.Text) - BOTTOMspeed) / (TOPspeed - BOTTOMspeed)) * (Ty2 - By2)) + By2
  31.             m_SLOPE = (Sy2 - Sy1) / (TBSx2 - TBSx1)
  32.             b_Y_INTERSECT = Sy1 - (m_SLOPE * TBSx1)
  33.             TextBoxMass = (m_SLOPE * TextBoxTemp) + b_Y_INTERSECT
  34.             Exit Sub
  35.         End If
  36.         ActiveCell.Offset(1, 0).Activate
  37.     Loop
  38. End Sub
Attached Files
File Type: xls Table interpolation_v1.4.xls (31.5 KB, 636 views)
File Type: doc How to interpolate_2.doc (70.0 KB, 441 views)
File Type: pdf How to interpolate_2.pdf (52.5 KB, 478 views)
Mar 10 '12 #10
Thanks for all your replies.

@ Rabbit, The table was framed with my own sample values and does not replicate the actual data. I was at the moment looking for linear interpolation only.


@ Guido - It was an excellent effort from you. I'm mesmerised indeed. Thanks a million.

I have few more questions on this.
1. Does it work well with extrapolation also? for example,the mass value @ 265 temp and 980 speed
2. I want the table to fit in the code itself. The user just specifies the temperature and speed value. How do i formulate the table in the code (using Array variables?..)?

Once again many thanks in advance.
Mar 13 '12 #11
@Guido,
To make it clear..

I am looking for a subroutine\function which takes temperature and speed as arguments and returns me the mass value (interpolated or extrapolated value).

Sorry for troubling you.

Thanks a lot.
Mar 13 '12 #12
@Guido,
The code doesn't work with the last speed value (i.e, 2000)...
Mar 13 '12 #13
Guido Geurs
767 Expert 512MB
It's normal because the code has no error detections!
It search for the speed bigger then 2000 and there is not one! so it calculates on an error.
It needs more fine tuning!
This code was so complex because the values for speed where not linear ! (error in the valus ??)
If it's all linear than the code is even simple : only need 8 values and no search for bigger speed.

But this was only the first step in solving the problem.

If all the functions are linear than the solution is even simple.
It only needs 8 values to enter to calculate all the values (interpolated or extrapolated ).
From the 8 given values we can calculate the Slope and the y-intersect for a speed.
Once we have the function we can calculate the mass for any temp.

Attached is an demo in VB6.
I have pre-entered the first values for speed 1000 and 1200 but it can be any value for any speed.
Enter them in the green and bleu textboxes and the speed and temp to calculate in the red textboxes.
Click on "Calc" to calculate the Mass (=red).

Do you want the solution in Excel or in VB6 ?
Attached Files
File Type: zip Table interpolation_v1.1.zip (7.7 KB, 207 views)
Mar 13 '12 #14
Guido Geurs
767 Expert 512MB
In the ZIP is a "Table interpolation_v1.1.exe" file which you can run to see the program I have written in VB6.
You can use this program for any mass, temp and speed !

No need to enter the data IN the program (function) because once the data changes, you have to rewrite the program or function code !

This is the code:
the first IF's are only to check if all needed data is entered.
The real calculation is in the 5 last lines.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdCalc_Click()
  2. '§ coordinates SPEED
  3. Dim Sy1 As Double
  4. Dim Sy2 As Double
  5. '§ coordinates bottom speed
  6. Dim m_SLOPE As Double '§ m is the slope
  7. Dim b_Y_INTERSECT As Double '§ b is the y-intercept
  8.    If TextMassB1 = "" Then
  9.       MsgBox ("Enter a value for Mass Bottom 1")
  10.       Exit Sub
  11.    End If
  12.    If TextMassB2 = "" Then
  13.       MsgBox ("Enter a value for Mass Bottom 2")
  14.       Exit Sub
  15.    End If
  16.    If TextMassT1 = "" Then
  17.       MsgBox ("Enter a value for Mass Top 1")
  18.       Exit Sub
  19.    End If
  20.    If TextMassT2 = "" Then
  21.       MsgBox ("Enter a value for Mass Top 2")
  22.       Exit Sub
  23.    End If
  24.    If TextTempTB1 = "" Then
  25.       MsgBox ("Enter a value for Temp Top Bottom 1")
  26.       Exit Sub
  27.    End If
  28.    If TextTempTB2 = "" Then
  29.       MsgBox ("Enter a value for Temp Top Bottom 2")
  30.       Exit Sub
  31.    End If
  32.    If TextSpeedT = "" Then
  33.       MsgBox ("Enter a value for Speed Top")
  34.       Exit Sub
  35.    End If
  36.    If TextSpeedB = "" Then
  37.       MsgBox ("Enter a value for Speed Bottom")
  38.       Exit Sub
  39.    End If
  40.    If TextTempCalc = "" Then
  41.       MsgBox ("Enter a value for Temp Calc")
  42.       Exit Sub
  43.    End If
  44.    If TextSpeedCalc = "" Then
  45.       MsgBox ("Enter a value for Speed Calc")
  46.       Exit Sub
  47.    End If
  48.    Sy1 = (((TextSpeedCalc.Text - TextSpeedB.Text) / _
  49.          (TextSpeedT.Text - TextSpeedB.Text)) * _
  50.          (TextMassT1.Text - TextMassB1.Text)) + TextMassB1.Text
  51.    Sy2 = (((TextSpeedCalc.Text - TextSpeedB.Text) / _
  52.          (TextSpeedT.Text - TextSpeedB.Text)) * _
  53.          (TextMassT2.Text - TextMassB2.Text)) + TextMassB2.Text
  54.    m_SLOPE = (Sy2 - Sy1) / (TextTempTB2.Text - TextTempTB1.Text)
  55.    b_Y_INTERSECT = Sy1 - (m_SLOPE * TextTempTB1)
  56.    TextMassCalc.Text = (m_SLOPE * TextTempCalc.Text) + b_Y_INTERSECT
  57. End Sub
Do you want to write the project in "VBA.net in Excel" or in "Visual studio VB.net" ?
Mar 14 '12 #15
Guido Geurs
767 Expert 512MB
Attached is a demo in VB.net 2010.

I have make it possible to save and load the data because my personal experience is that putting the data in the program not the optimal solution is.
When each time some of the values changes, you have to rebuild the program and distribute it!

With this solution it's possible to save the values for each different situation (product, item, ...) and load it in the same program.

the files have the extension *.TSM_data and are just a textfile with the data of the 8 values necessary to calculate any mass for that situation.
Attached Files
File Type: zip Table interpolation.zip (553.3 KB, 213 views)
Mar 17 '12 #16
Hi Mr. Guido Geurs, I just saw your VB files. I am a civil engineer and i need a VB macro file for an excel sheet that is being used to design RCC Column members of buildings. I would like to know whether is that possible for me to learn Visual Basic so that I could prepare Macro files by myself. I am not a Computer Programmer and should honestly say I am zero in it. But I am aware of PC Hardwares and softwares, since I use it daily. I need a macro file to be created for an interpolation similar to the above case.S, could you tell me whether is that possible for me to learn that? Or should I learn C & C++ in first ?? Thank you
Jan 6 '18 #17
Guido Geurs
767 Expert 512MB
Dear Areesh Kumar S

If you are new on the topic of programming then it is good to start with learning writing Algorithms (just google for "learning algorithms".
This is a method to see with blocks how a problem comes to a solution in a computer language .
Mostly with questions and statements like "IF .... then... else.....
Second is the language itself.
Then you have to learn the syntax of the code (each language has his own methode of writing the code) and the properties if each element in the language.
Now you have to chose a language for your problem.
If you want to write macros in Excel you have to learn VBA (visual basic for Applications).
If you want to write small programs for using on a PC you have to learn VB6 (visual basic from Microsoft visual Studio) or VB.net (=later generation of VB6 with other syntaxes) .
I'm still working on Win7 and VB6 does still the work for me.
If you want to write for a webpage you have to learn HTML (totally different syntax than VB6)
...aso.

If you have a problem with a macro in Excel or VB6 I can always help you to solve it with an explanation how i have written the code.
Just open a new topic (question) in Bytes with a little demo attached.
Also send me a mail "guido.geurs@gmail.com" with the title of the question so i can trace it in Bytes.
Jan 7 '18 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dave.harper | last post by:
I'm relativly new to C++, and have been looking for a way to interpolate data (i.e. a table indexed by 2 arrays, or just an array indexed by another array). I haven't been able to find an easy way...
14
by: Charles Banas | last post by:
I'm not sure if this is the right place to ask about this, but I've seen several posts in the past regarding Akima's Bivariate Interpolations routines, and i'm wondering if someone can give me some...
3
by: Jonas Ernst | last post by:
Hi, Can somebody give me some hints how to do a line interpolation without using floating point arithemtics? The function shall do a linear interpolation between 2 points (line interp?) and...
2
by: Kun | last post by:
I have an html form that takes dates and inserts them into a mysql file. Currently, users have to type in dates in the yyyy-mm-dd format. As of now, this process works with the sql. However, I...
5
by: xandra | last post by:
i understood the concept of interpolation search. but i couldn't understand what would be the steps for that search. for example, if i'm searching for J in this file A A B E F H J M N N N N O P P...
5
by: different | last post by:
Hi, I have a program which reads a file containing integers in . The program reads the value of a variable every 2 seconds, then maps it to another interval, say , obtaining a new value. I already...
2
by: Colin McKinnon | last post by:
Hi all, I'm wondering if this is possible with PHP: $query = "SELECT * FROM table WHERE afield='$something'"; has quite a different meaning from $query = 'SELECT * FROM table WHERE...
0
by: MonkeeSage | last post by:
There are several string interpolation functions, as well as string.Template. But here's yet another. This one emulates ruby's inline interpolation syntax (using #{}), which interpolates strings as...
11
by: ideaboy | last post by:
I want to write a query to get the interpolated result. I have a table (which contains the gridded data - means lat, long, sst values for some points), the table contains around 100 million...
6
by: Mark Smith | last post by:
I wanted to calculate some values on a screen by using interpolation to get the values required Example; Price running vertically as follows 0 90 93 96 105
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.