+- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) (/thread-674.html) Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - DeucesAx - 02-14-2014 07:46 AM For a thermodynamics class I often need to interpolate values which are not given in the tables I use. Say I want to know the specific volume of water at 130 degrees and pressure of 100 kpa, when I only have the specific volume for 100 and 150 degrees at 100kpa. Is there some statistic function I can use, which would be faster than the solver? RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Han - 02-14-2014 02:52 PM In general your interpolation (and its accuracy) depends on the relationship between the parameters. For your example, if you use $$PV=nRT$$ and pressure $$P$$ is kept constant, then in this case a linear interpolation would be fine since $V = \underbrace{\frac{nR}{P}}_{\text{slope}} \cdot T$ So since $$n$$, $$R$$ and $$P$$ are constant, then $$V$$ is a linear function of $$T$$. This should enable you to interpolate the volume provided the pressure is fixed at 100k pascals. Haven't tested this, but using a linear fit with your known values and then using the trace feature should allow you to figure out the interpolated volume. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Rich - 02-14-2014 04:44 PM I just recently took Thermodynamics and fluid flow 1. For linear interpolations, i assigned this object which is pretty fast for me: f(x_1,y_1,x_2,x_3,y_3):=y_2 = (((x_2-x_1)*(y_3-y_1))/(x_3-x_1)) + y_1 x_1 = (Value) y_1 = (Value) x_2 = (Value) y_2 = Unknown x_3 = (Value) y_3 = (Value) To use just perform f(1,1,2.5,10,10) and ENTER The result should be a direct linear interpolation with y_2 = 2.5 I hope this helps. Though I recommend just using the EES software package, if it is available at your school and you can use it on an exam. It comes preloaded with almost all tabulated values of entropy, enthalpy, specific heat...etc etc. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - DeucesAx - 02-14-2014 09:48 PM (02-14-2014 04:44 PM)Rich Wrote:  I just recently took Thermodynamics and fluid flow 1. For linear interpolations, i assigned this object which is pretty fast for me: f(x_1,y_1,x_2,x_3,y_3):=y_2 = (((x_2-x_1)*(y_3-y_1))/(x_3-x_1)) + y_1 x_1 = (Value) y_1 = (Value) x_2 = (Value) y_2 = Unknown x_3 = (Value) y_3 = (Value) To use just perform f(1,1,2.5,10,10) and ENTER The result should be a direct linear interpolation with y_2 = 2.5 I hope this helps. Though I recommend just using the EES software package, if it is available at your school and you can use it on an exam. It comes preloaded with almost all tabulated values of entropy, enthalpy, specific heat...etc etc. Thank you, I will check it out. The linear fit as well. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - patrice - 02-15-2014 01:21 AM Just wandering. Did try to find the answer by yourself before asking? Since this kind of problem is usually a primary school problem, it is surprising to see you asking the question. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - DeucesAx - 02-15-2014 08:22 AM (02-15-2014 01:21 AM)patrice Wrote:  Just wandering. Did try to find the answer by yourself before asking? Since this kind of problem is usually a primary school, it is surprising to see you asking the question. Just wondering. Did you read my OP? Anybody with a primary school level of English should understand that I knew how to calculate it, and did it before. My main concern is and was saving key strokes, as time is critical during exams. I was hoping this could be done without programming my own function which I had not done yet on a calculator. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - patrice - 02-15-2014 08:46 AM I have read again your first post. It is not obvious that the problem was a matter of keystroke saving. Why don't you just define the functions you need? Once defined, you just recall the function and feed with parameters. difficult to save more. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - CR Haeger - 02-15-2014 10:53 AM (02-15-2014 08:22 AM)DeucesAx Wrote:   (02-15-2014 01:21 AM)patrice Wrote:  Just wandering. Did try to find the answer by yourself before asking? Since this kind of problem is usually a primary school, it is surprising to see you asking the question. Just wondering. Did you read my OP? Anybody with a primary school level of English should understand that I knew how to calculate it, and did it before. My main concern is and was saving key strokes, as time is critical during exams. I was hoping this could be done without programming my own function which I had not done yet on a calculator. I was in your shoes last millennium with an hp15c in thermodynamics course. I guess part of the fun of the hp15c was writing a small program for interpolation, even with only 4 stack levels and 5 inputs. I'm enjoying the HP Prime for the same reason today. Note that besides defining a function, you may want to check out the spreadsheet app which is pretty powerful and flexible. Best, Carl RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Tugdual - 02-15-2014 12:16 PM May not be super easy but this is another way: - [Apps] Statistics 2 vars - [Num] key - enter x1, x2 in C1 and y1, y2 in C2 - [Symb] - Make sure that Type1 is Linear - Tab the field Fit1 and [Shift][View] (for Copy) - [Apps] Function - Tap F1 field - [Shift][Menu] (for Paste) Now call F1(X) from Home and you're done. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Tim Wessman - 02-15-2014 02:51 PM (02-15-2014 12:16 PM)Tugdual Wrote:  - Tab the field Fit1 and [Shift][View] (for Copy) - [Apps] Function - Tap F1 field - [Shift][Menu] (for Paste) Now call F1(X) from Home and you're done. No need for that. Use the app functions PredX and PredY. I think a lot of people haven't noticed yet that each application can have its own functions. For example, Stat2Var has PredX,PredY, and Resid. The triangle solver has SSS, SAS, etc. Basically, we'd like to make it so anything that can be done in an application can be done directly with functions as well. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Tugdual - 02-15-2014 03:33 PM (02-15-2014 02:51 PM)Tim Wessman Wrote:  I think a lot of people haven't noticed yet that each application can have its own functions. For example, Stat2Var has PredX,PredY, and Resid. The triangle solver has SSS, SAS, etc. Basically, we'd like to make it so anything that can be done in an application can be done directly with functions as well. Indeed, thanks for mentioning it Tim, I learned something today. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - CR Haeger - 02-15-2014 04:44 PM (02-15-2014 02:51 PM)Tim Wessman Wrote:   (02-15-2014 12:16 PM)Tugdual Wrote:  - Tab the field Fit1 and [Shift][View] (for Copy) - [Apps] Function - Tap F1 field - [Shift][Menu] (for Paste) Now call F1(X) from Home and you're done. No need for that. Use the app functions PredX and PredY. I think a lot of people haven't noticed yet that each application can have its own functions. For example, Stat2Var has PredX,PredY, and Resid. The triangle solver has SSS, SAS, etc. Basically, we'd like to make it so anything that can be done in an application can be done directly with functions as well. Tim - I assume you still have to setup and run the stat2var app before using predx or predy? RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Tugdual - 02-15-2014 05:27 PM (02-15-2014 04:44 PM)CR Haeger Wrote:  Tim - I assume you still have to setup and run the stat2var app before using predx or predy? This is correct. The help also indicates that the functions will use the context of the first selected interpolation. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Joe Horn - 02-16-2014 02:03 AM This is not a one-keystroke solution, but I think it works. CAS only. Example: (x,y)1 = (1,5) (x,y)2 = (7,17) (x,y)3 = (10,?) subst(lagrange([1,7],[5,17]),x=3) --> 23, answer. In general: subst(lagrange([x1,x2],[y1,y2]),x=x3) --> y3, where "x" is a literal x. Can somebody sober verify this? Thanx. I'm currently under the influence of Nyquil. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Tugdual - 02-16-2014 02:13 PM (02-16-2014 02:03 AM)Joe Horn Wrote:  This is not a one-keystroke solution, but I think it works. CAS only. Example: (x,y)1 = (1,5) (x,y)2 = (7,17) (x,y)3 = (10,?) subst(lagrange([1,7],[5,17]),x=3) --> 23, answer. In general: subst(lagrange([x1,x2],[y1,y2]),x=x3) --> y3, where "x" is a literal x. Can somebody sober verify this? Thanx. I'm currently under the influence of Nyquil. I looks good to me :-) Prompt recovery! RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - DeucesAx - 02-19-2014 03:16 AM Hos do I do this? Sorry, for some reason Im an idiot when it comes to this calculator. (02-15-2014 02:51 PM)Tim Wessman Wrote:   (02-15-2014 12:16 PM)Tugdual Wrote:  - Tab the field Fit1 and [Shift][View] (for Copy) - [Apps] Function - Tap F1 field - [Shift][Menu] (for Paste) Now call F1(X) from Home and you're done. No need for that. Use the app functions PredX and PredY. I think a lot of people haven't noticed yet that each application can have its own functions. For example, Stat2Var has PredX,PredY, and Resid. The triangle solver has SSS, SAS, etc. Basically, we'd like to make it so anything that can be done in an application can be done directly with functions as well. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - Joe Horn - 02-20-2014 05:46 AM (02-19-2014 03:16 AM)DeucesAx Wrote:  Hos do I do this? Here's one way. If your Statistics 2Var app is still in its default state, then you can solve this: (x,y)1 = (1,5) (x,y)2 = (7,17) (x,y)3 = (10,?) by doing this, from the Home keyboard: C1:={1,7} [the two X values] C2:={5,17} [the two Y values] PredY(10) Enter --> 23, answer. As Tim mentioned, PredX also exists. It predicts an X from a Y value: PredX(23) --> 10. RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - rprosperi - 02-21-2014 01:49 AM Thanks for explaining in detail how to use the App Functions per Tim's suggestion Joe. I figured out how to use the Stats 2Var Numeric form and the PredY function, but this walk-thru connected several dots for me on how to use App Functions directly from the Home Screen. The list is the form... now I get it! RE: Linear Interpolation: Given a pair of (x1,y1), (x2,y2) and x3 predict (x3,y3) - DeucesAx - 02-21-2014 02:28 AM I ended up writing this little program: export int2(xmin,xmax,ymin,ymax,yreal) BEGIN local xreal; xreal:=xmin+((yreal-ymin)/(ymax-ymin))*(xmax-xmin); return(xreal); END; As few keystrokes as it gets I suppose.