Post Reply 
SOLVE for Function Vectors
05-26-2018, 10:51 PM
Post: #1
SOLVE for Function Vectors
I made a program that returns VECTOR(x) expressed as [a(x),b(x),c(x)]
given that b(x) is a known value, what would be the sintaxis for solving VECTOR(x) for x with a(x), b(x) or c(x) known?

On the specifics side this is the curve for a pump, where a(x) is the head, b(x) the efficiency and c(x) the shaft power.

At any given time and generally the easiest to know would be the head. So based on the head only known I would like to know how to use the solve function in the case of a vector.

I currently have the functions as separate, but I would like to see if I can simplify this.

Thanks in advance.

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
05-27-2018, 06:17 AM
Post: #2
RE: SOLVE for Function Vectors
Hi NomadVehr,

Welcome! I hope you find this forum both helpful and challenging (in a good way!) I'm at something of a "freshman skill level" with the Prime CAS myself, so I'm not likely to contribute directly to the answer to your question. However, your question does fall into the "show your work" category of problems posted here.

You mention head/efficiency/shaft power. Could you explain the problem you are trying to solve in terms suitable for a general audience, i.e. a water pumping station design problem? Next, could you show the equations you are working with that are used to solve the design problem? Lastly, you mention a program you wrote that addresses your design problem. The program code, if not too large, might help show how you went about trying to solve the design problem you have.

No need to do all at once! Start by describing the problem itself and your own goals. This should attract the attention of those in the forum with a similar background to your own (there are a number of Civil and Mechanical engineers posting here regularly) After that, hopefully the mathematical details will follow, and eventually advice on solving the problem itself.

As I said, I probably can't help you with the problem itself, but it does sound interesting to hear more about!

~Mark

Who decides?
Find all posts by this user
Quote this message in a reply
05-27-2018, 08:25 PM
Post: #3
RE: SOLVE for Function Vectors
Hi Mark,

Thanks for the welcome. After a 20 year hiatus from programmable calculators spent mostly on Excel sheets I'm back into programming.

I´m a Chemical Engineer working in an Oil refinery in the Middle East.

It all started with Pump Curves. Since the statistics and curve adjustment is super friendly, plus the polynomial coefficients have more significant digits, hence more accuracy. I basically simulated the pump curve parameters for a series of pumps.

It all started with the need of having pump curves in the palm of my hand. Head, Efficiency, Power and NPSH all as a function of the flow Q. So I made separate programs for each variable of each Pump. The functions are described below.
H(Q)= Head as a function of flow Q. 4th Degree polynomial.
Eff(Q)= Efficiency as a function of flow Q. 3rd degree Polynomial.
SP(Q)=Shaft power as a function of flow Q. Linear.
NPSH(Q)= Net Positive Suction Head as a function of flow Q. Exponential.

All well here, then I ask myself, what if I just make a program to return all these functions at once by just entering the flow?
Then I faced my first road block: You cant use RETURN multiple times in the program, it will only return the function on the first return line.
Then I bump into this tutorial blog by Eddie Shore:
https://edspi31415.blogspot.com/2013/10/...8245762045
The Solution: A Vector!
So you basically would type:
RETURN [H(Q),Eff(Q),SP(Q),NPSH(Q)];

Of course not these expressions as is, but the respective actual Polynomials or Functions.
Now I have a program that returns all the information at once by entering the flow.

The thing is that now my calculator is cluttered with the vector program and the individual functions.
So end up with programs like
PUMP1H(Q)
PUMP1Eff(Q)
PUMP1SP(Q)
PUMP1NPSH(Q)
And the Vector expression which groups them all.
PUMP1HEPN(Q)
Here´s my conundrum...I have more than 20 pumps to look after.I have done this for only 4 so far so it would take 100 programs to scroll through to solve the function.

Generally, on the field, the easiest of these functions to solve for Q is the head. Power is also relatively easy to estimate.

So when I want to check the flow against the flow meter I would determine the head, lets call it h, and use use for example

SOLVE(PUMP1H(Q)=h,Q); h i an actual number in this case.
Then the Prime will return the flow Q.

What I want to accomplish is just to keep the vector program to declutter the scrolling list then solve using the only known value is h.

Something like:
SOLVE(PUMP1HEPN(Q)=[h,unknown,unknown, unknown]);

In this part I have not succeded so far and where I am looking for someone to give me a clue on how to proceed.

Greetings from the desert,
Boris


Attached File(s) Thumbnail(s)
   

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
05-28-2018, 09:40 AM
Post: #4
RE: SOLVE for Function Vectors
Greetings from a fellow chemical engineer,

Have you considered returning a list instead of a vector? An example of code returning a list:

Code:
EXPORT PUMP1NPSH(q)
BEGIN
 LOCAL temp;
 temp:=q^4-q^3+q^2+2*q+3;
 return {temp,2*temp,3*temp,4*temp};
END;

If that is your program, then:

fsolve(((PUMP1NPSH(x))(1)) = 500,x = 3)

will return 4.91058632644

-road
Find all posts by this user
Quote this message in a reply
05-29-2018, 04:39 PM (This post was last modified: 05-29-2018 05:53 PM by NomadVehr.)
Post: #5
RE: SOLVE for Function Vectors
Thanks a lot Road!

Tried it out and works like a charm.
Here´s the code
I used X since I copied the equations from the 2 variable statistics app.

EXPORT PUMP1(X)
BEGIN
LOCAL h;
h:=2.89237307957ᴇ−8*X^4-2.24570549144ᴇ−5*X^3+4.67273696234ᴇ−3*X^2-0.311626877884*X+175;
LOCAL Eff;
Eff:=8.58164056499ᴇ−8*X^3-1.00216261706ᴇ−3*X^2+0.480844232375*X-0.029541916438;
LOCAL PWR;
PWR:=0.25415412597*X+68.328377716;
return {"h(m)",h,"Eff(%)",Eff,"SHP(kW)",PWR};
END;

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-01-2018, 02:40 PM
Post: #6
RE: SOLVE for Function Vectors
One thing I would like to know is if there is a way to present the ouput as a vertical list

{h(m),169,Eff(%),50,SHP(kW)"170}

Whereas I would like it to display something more like

h(m) 169
Eff(%) 50
SHP(kW) 170

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-01-2018, 04:33 PM
Post: #7
RE: SOLVE for Function Vectors
Will something like this work:

Code:
EXPORT PUMP1(X)
BEGIN
 LOCAL h,a;
 h:=2.89237307957ᴇ−8*X^4-2.24570549144ᴇ−5*X^3+4.67273696234ᴇ−3*X^2-0.311626877884*X+175;
 LOCAL Eff;
 Eff:=8.58164056499ᴇ−8*X^3-1.00216261706ᴇ−3*X^2+0.480844232375*X-0.029541916438;
 LOCAL PWR;
 PWR:=0.25415412597*X+68.328377716;
 a:={"h(m)",h,"Eff(%)",Eff,"SHP(kW)",PWR};
 RECT();
 TEXTOUT(a(1),−10,10);
 TEXTOUT(a(2),0,10);
 TEXTOUT(a(3),−10,8);
 TEXTOUT(a(4),0,8);
 TEXTOUT(a(5),−10,6);
 TEXTOUT(a(6),0,6);
 WAIT(0);
 RETURN a;
END;
Find all posts by this user
Quote this message in a reply
06-02-2018, 05:16 PM (This post was last modified: 06-02-2018 06:02 PM by NomadVehr.)
Post: #8
RE: SOLVE for Function Vectors
Thanks Roadrunner,

I finally found the workaround thanks to the print command.
While the solution you posted didn't work as expected, it helped me get to work around.

I also made an enhancement to the program where it prompts warning messages when flow is below minimum or above end of curve:

EXPORT PUMP1(X)
BEGIN
LOCAL h,a;
h:=-3.96912716744ᴇ−6*X^3+1.33502710425ᴇ−3*X^2-0.230829109114*X+187.74099966;
LOCAL Eff;
Eff:=8.58164056499ᴇ−8*X^3-1.00216261706ᴇ−3*X^2+0.480844232375*X-0.029541916438;
LOCAL PWR;
PWR:=0.25415412597*X+68.328377716;
LOCAL NPSH;
NPSH:=3.42624923327ᴇ−7*X^3-1.02340333129ᴇ−4*X^2+7.55229835063ᴇ−3*X+2.60628404048;
a:={{"h(m)",h},{"Eff(%)",Eff},{"SHP(kW)",PWR},{"NPSH(m)=",NPSH}};
IF X<80 THEN RETURN {" Warning: Flow below minimum",a};END;
IF X>340 THEN RETURN {"Warning: Flow above end of curve",a};END;
PRINT("h(m)");PRINT(h);
PRINT("Eff(%)");PRINT(Eff);
PRINT("SHP(kW");PRINT(PWR);
PRINT("NPSH(m)");PRINT(NPSH);
RETURN a;
END;

Thanks again for helping me get started,
Nomad

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-04-2018, 08:10 PM
Post: #9
RE: SOLVE for Function Vectors
Guys,

Seems I may be in exam mode or something, now when I try the solve function for the program all I get is "[]".
It worked fine until a few hours ago.
Please help.

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-05-2018, 04:08 AM
Post: #10
RE: SOLVE for Function Vectors
Hello,

Exam mode would not have this effect. Do you see the orange header on the top of your calc? If no, then you are not in exam mode...

Most likely, the calculator can not find a solution to the problem (this is what the [] result means)...

Have you subtely changed your program in a way that might cause this?

Try saving/exporting what you are trying to solve to a string and look at it, it might help you notice the issue.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
06-05-2018, 03:21 PM
Post: #11
RE: SOLVE for Function Vectors
Thanks Cyrille,

I already reset my calculator to factory settings version 2018-02. I will start the programs with earlier working versions. Let´s see how it goes...

Nomad

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-05-2018, 06:01 PM
Post: #12
RE: SOLVE for Function Vectors
It might be one of the IF statements causing the unexpected result. REM those out and then try your program to eliminate that possibility. If fsolve suddenly sees a list instead of a number it will stop and return empty brackets.

-road
Find all posts by this user
Quote this message in a reply
06-05-2018, 07:50 PM
Post: #13
RE: SOLVE for Function Vectors
Well guys,

I know some of you will facepalm like me and others will just laugh their heads off...
Here´s the solution: Make copies of the 2 variable statistics app with the data for each pump.

I feel a mix of sense of accomplishment and embarrasment.

Thanks to all of you who stepped in to help!


Nomad


Attached File(s) Thumbnail(s)
           

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-06-2018, 03:58 AM
Post: #14
RE: SOLVE for Function Vectors
Another thing you may not be aware of - the location you are putting your "list" variables allows equations as well. So you can do things "like LOG(C1)+C2" or similar. You might not need to even be calculating things outside of it if you build equations correctly.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
06-06-2018, 05:46 PM
Post: #15
RE: SOLVE for Function Vectors
Thanks Tim and Roadrunner!

I´ll still try your suggestions with the program to see where it leads.

Here's the Pump1 app. Works for me perfectly since I can just use the solve function on the curve regressions rather easily, plus it allows me to see the pump curve plot.
I hope you find it helpful.

Nomad


Attached File(s)
.zip  PUMP1.hpappdir.zip (Size: 5.67 KB / Downloads: 3)

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-10-2018, 03:26 PM
Post: #16
RE: SOLVE for Function Vectors
(06-06-2018 03:58 AM)Tim Wessman Wrote:  Another thing you may not be aware of - the location you are putting your "list" variables allows equations as well. So you can do things "like LOG(C1)+C2" or similar. You might not need to even be calculating things outside of it if you build equations correctly.

Wow!!!! that helps me with the conversion of power to motor Amps. Big facepalm moment!!!
Thanks Time

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-10-2018, 04:04 PM
Post: #17
RE: SOLVE for Function Vectors
Hi Tim,

I´m trying to insert the formula in the columna á la Excel, but it´s not working. Any tips?

NomadVeHr


Attached File(s) Thumbnail(s)
       

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-10-2018, 04:23 PM (This post was last modified: 06-10-2018 04:26 PM by Didier Lachieze.)
Post: #18
RE: SOLVE for Function Vectors
Add '=' before your formula: =PWRkw*1000/(400*1.73)
Select the column name 'Amps' when you enter the formula to apply it to all cells of the column.
Find all posts by this user
Quote this message in a reply
06-10-2018, 05:01 PM
Post: #19
RE: SOLVE for Function Vectors
Thanks Didier,

Still stuck even with the '='

Will keep trying.

Nomad VeHr

HP-27, HP-67 ( both legacy), Casio FX880P, HP-35S, WP34S, DM42, HP Prime.
Find all posts by this user
Quote this message in a reply
06-10-2018, 05:06 PM (This post was last modified: 06-10-2018 05:06 PM by Didier Lachieze.)
Post: #20
RE: SOLVE for Function Vectors
If you enter the formula for the whole column use: =PWRkw*1000/(400*1.73)
But if you enter the formula in a single cell, for ex row 1, then add the row number after the colum name: =PWRkw1*1000/(400*1.73)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)