Author Topic: Release of FormulaPro for the Nspire  (Read 59950 times)

0 Members and 1 Guest are viewing this topic.

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #30 on: September 24, 2012, 02:56:44 pm »
Code: [Select]
While in Units.lua (Git version) I have:
[code]Units["Pa"] = {}
Units["Pa"]["MPa"] = {Mt.M    , 0}
Units["Pa"]["GPa"] = {Mt.G    , 0}
Units["Pa"]["hPa"] = {Mt.h    , 0}
Units["Pa"]["bar"] = {1/100000, 0}
Units["Pa"]["atm"] = {1.01325 , 0}
the output is
Code: [Select]
Pa
hPa
atm
GPa
bar
MPa
which is totally confusing.

When I say default values, I mean either an implementation of a dropbox, in the same manner to the units, where I can select from predefined values or a default value in case a variable is not set.

Furthermore, default units, are really useful, because in civil engineering, units are massive, from  KN to MN, and MPa to GPa.

About my last question, what I meant was that in my field, some values follow a different curve according to some variable. For example, the coefficient α_cw, is
Code: [Select]
1+σ_cp/f_cd      for 0 < σ_cp <= 0.25 f_cd
1.25             for 0.25 f_cd < σ_cp <= 0.5 f_cd
2.5(1-σ_cp/f_cd) for 0.5 f_cd < σ_cp <= 1.0 f_cd

Should I implement the default values and the slope change in that last example, by creating an equation, using max(), min() and abs() in order to make the gradual change?

Finally, the constants, to not update according to constants.lua. They seem to be fixed.


Don't worry about the web version. I don't need it. But many of my friends who are willing to buy the same calculator, would certainly need it.

I am currently preparing for an exam at Saturday, so programming my nspire is of paramount importance.[/code]
« Last Edit: September 24, 2012, 02:58:28 pm by intelx86 »

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #31 on: November 11, 2012, 09:35:08 am »
Using the latest git-version and a Nspire CX CAS v3.1 calculator, I have a serious problem.

I have a set of 4 principal equations in applied hydraulics.
The only way I get an answer is when I implement all four into one. (look Missing D #4)
If I implement them into two-tree equations and providing I give f (provided by Missing D #4), I get the desired D. (look Missing D #2 & #3)
If I have all four, and I provide the D, I'll get the f, but if I provide the f only, I don't get D. (look Missing D #1)

It seems to be a solver issue. Does FormulaPro uses the built-in CAS solvers and if not, is there a way to select the desired solver?


Input
Q = 0.25 m3/s
ν = 1.1E-06 m2/s
ks = 0.00025 m
L = 1015 m
hf = 9.4 m

Expected output
f = 0.0181
D = 0.3988 m

Code: [Select]
addCat(2, "Applied Hydraulics", "Darcy-Weisbach, Colebrook-White etc.")

addCatVar(2, "hf", "Head loss due to friction", "m")
addCatVar(2, "f", "Darcy friction factor", "unitless")
addCatVar(2, "Re", "Reynolds number", "unitless")
addCatVar(2, c_nu, "Kinematic viscosity", "m2/s")
addCatVar(2, "Ks", "Roughness Factor", "m")
addCatVar(2, "L", "Length of the pipe", "m")
addCatVar(2, "D", "Hydraulic diameter", "m")
addCatVar(2, "V", "Mean velocity", "m/s")
addCatVar(2, "Q", "Volumetric flow rate", "m3/s")

addSubCat(2, 1, "Missing D #1", "")
--Darcy-Weisbach
aF(2, 1, "hf=f*(L/D)*(V^2/(2g))", U("hf","f","L","D","V","g"))

--Colebrook-White
aF(2, 1, "1/sqrt(f)+2log(Ks/D+9.35/(Re*sqrt(f)))=1.14", U("f","Ks","D","Re"))

--Reynolds number
aF(2, 1, "Re=V*D/"..c_nu, U("Re","V","D",c_nu))


aF(2, 1, "Q=V*"..c_pi.."*D^2/4", U("Q","V","D"))


addSubCat(2, 2, "Missing D #2", "")
--Darcy-Weisbach with flow rate
aF(2, 2, "hf=f*(L/D^5)*(8*Q^2/("..c_pi.."^2*g))", U("hf","f","L","D","Q","g"))

--Reynolds number
aF(2, 2, "Re*sqrt(f)=sqrt(2*g*hf/L)*D^(1.5)/"..c_nu, U("Re","f","g","hf","L","D",c_nu))

--Colebrook-White
aF(2, 2, "1/sqrt(f)+2log(Ks/D+9.35/(Re*sqrt(f)))=1.14", U("f","Ks","D","Re"))


addSubCat(2, 3, "Missing D #3", "")
--Darcy-Weisbach with flow rate
aF(2, 3, "D=(8*f*L*Q^2/("..c_pi.."^2*g*hf))^(0.2)", U("hf","f","L","D","Q","g"))

--Colebrook-White with Raynolds number
aF(2, 3, "1/sqrt(f)+2log(Ks/D+9.35/(sqrt(2*g*hf/L)*D^(1.5)/"..c_nu.."))=1.14", U("f","Ks","D","g","hf","L",c_nu))

addSubCat(2, 4, "Missing D #4", "")
--Colebrook-White, with the above
aF(2, 4, "1/sqrt(f)+2log(Ks/((8*f*L*Q^2/("..c_pi.."^2*g*hf))^(0.2))+9.35/(sqrt(2*g*hf/L)*((8*f*L*Q^2/("..c_pi.."^2*g*hf))^(0.2))^(1.5)/"..c_nu.."))=1.14", U("f","Ks","g","hf","L","Q",c_nu))
« Last Edit: November 11, 2012, 09:57:21 am by intelx86 »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Release of FormulaPro for the Nspire
« Reply #32 on: November 11, 2012, 10:32:16 am »
Using the latest git-version and a Nspire CX CAS v3.1 calculator, I have a serious problem.

I have a set of 4 principal equations in applied hydraulics.
The only way I get an answer is when I implement all four into one. (look Missing D #4)
If I implement them into two-tree equations and providing I give f (provided by Missing D #4), I get the desired D. (look Missing D #2 & #3)
If I have all four, and I provide the D, I'll get the f, but if I provide the f only, I don't get D. (look Missing D #1)

It seems to be a solver issue. Does FormulaPro uses the built-in CAS solvers and if not, is there a way to select the desired solver?

I haven't had time to look exactly at your code but it "looks" good.

- Can you try to go to the solver in whatever subcategory has a problem.
- Then Ctrl-I to make a new tab, and look at the variable list (Ctrl-L or Var). Do you see what you'd expect ?
   If not something's wrong on your side when entering the data/formula/units/vars. If yes, it's weird...

For the solving, we use nSolve() (so that it works with non-cas models too), as you can see here : https://github.com/adriweb/EEPro-for-Nspire/blob/master/2%20-%20%20FormulaPro/1%20-%20FPSolver.lua#L4 (line 4)
You can try to comment that line 4 and un-comment the one above, just to try ?

I've asked Jim to come see this too, maybe he'll have some ideas...


(By the way :

- your category is #2, meaning you actually removed the original #2 one, right? (Because IIRC, I made something to check if there are conflicts while building the DB, on the latest 1.4a version, but hopefuly you got that version)
- Version 1.4 (latest git version) is only on the source files on Github, but it's not the one on the .tns files there. What do you have written on the script ? 1.3 or 1.4 ?
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #33 on: November 11, 2012, 10:53:01 am »
I have another category named #1 and have also replaced your database.

The version is definitely 1.4a from git source obtained today.
Code: [Select]
git clone git://github.com/adriweb/EEPro-for-Nspire.git
Changing the solver made no difference.

I opened a new tab, and displayed every variable. If it had a value, it showed the value. If not, the variable's name.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Release of FormulaPro for the Nspire
« Reply #34 on: November 11, 2012, 10:53:16 am »
intelx86, could you try to change the following code in '1 - FPSolver.lua'

Code: [Select]
function math.solve(formula, tosolve)
    --local eq="max(exp" .. string.uchar(9654) .. "list(solve(" .. formula .. ", " .. tosolve ..")," .. tosolve .."))"
    local eq = "nsolve(" .. formula .. ", " .. tosolve .. ")"
    local res = tostring(math.eval(eq)):gsub(utf8(8722), "-")
    --print("-", eq, math.eval(eq), tostring(math.eval(eq)), tostring(math.eval(eq)):gsub(utf8(8722), "-"))
    return tonumber(res)
end


to

Code: [Select]
function math.solve(formula, tosolve)
    local eq="max(exp" .. string.uchar(9654) .. "list(solve(" .. formula .. ", " .. tosolve ..")," .. tosolve .."))"
    --local eq = "nsolve(" .. formula .. ", " .. tosolve .. ")"
    local res = tostring(math.eval(eq)):gsub(utf8(8722), "-")
    --print("-", eq, math.eval(eq), tostring(math.eval(eq)), tostring(math.eval(eq)):gsub(utf8(8722), "-"))
    return tonumber(res)
end

Try if it works with that change.
Normally that should switch the solver to the good CAS one. I should see to script something so that the CAS version get's selected when on a CAS model.
Thank's for your feedback, it's stuff like this that really help us!


Edit: nvm, I see that you tried that already.
« Last Edit: November 11, 2012, 10:55:11 am by Jim Bauwens »

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #35 on: November 11, 2012, 10:54:11 am »
Like I said, nothing changes.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Release of FormulaPro for the Nspire
« Reply #36 on: November 11, 2012, 11:02:59 am »
I think this is an implementation issue. I'll look into it and see what I can do .. if I get the time for that.
Sorry for the trouble :/

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #37 on: November 11, 2012, 11:04:57 am »
Don't even mention it! Thank you for this fine code and thanks for sharing in the first place.
Bugs are inevitable! :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Release of FormulaPro for the Nspire
« Reply #38 on: November 11, 2012, 11:28:08 am »
It "may" be not as hard as we can think at first.
In fact, we need to make the line generate a system of equation, and parse the result.
Also make a test to know if it's CAS or not, in order to fully profit of the device's capabilities (and know what [not] to use !).

Jim and/or I will keep you updated here :)
« Last Edit: November 11, 2012, 11:58:16 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #39 on: November 11, 2012, 12:53:52 pm »
When I enter a formula again, but in another category, it is being left out.

Revert
Code: [Select]
    if not checkIfFormulaExists(Formulas, fr.formula) then
        table.insert(Formulas, fr)
    end
    if not checkIfFormulaExists(Categories[cid].sub[sid].formulas, fr.formula) then
        table.insert(Categories[cid].sub[sid].formulas, fr)
    end]
to
Code: [Select]
    table.insert(Formulas, fr)
    table.insert(Categories[cid].sub[sid].formulas, fr)]

or check only inside the subcategory for repetition.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Release of FormulaPro for the Nspire
« Reply #40 on: November 11, 2012, 01:12:28 pm »
Yup, this is the git code and is for the alpha version so far that's why it's not fully tested and especially not "compiled" to the FormulaPro.tns file on the repo (which is the stable 1.3) ;)
I'll see how I can restrict the existence-check to the subcategory :)
« Last Edit: November 11, 2012, 01:13:16 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline intelx86

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #41 on: November 11, 2012, 01:23:39 pm »
Do you remember, in my first posts, where I suggested to control the orderand the visibility of the variables?

This could be implemented, by including an optional parameter for function addSubCat().
An array, U("var1", "var2", "var3"...) could be saved as well, indicating the order and the visibility of variables.
If you do not include a variable, ti won't be shown, but only used for calculations.

Optionally, a third button could be included to show "hidden" vars, if applicable.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Release of FormulaPro for the Nspire
« Reply #42 on: November 15, 2012, 03:21:23 pm »
Thanks for those suggestions.
Right now I really don't have time to implement it though, lots of stuff to do for school.
But I have an idea on how to solve the problem. So that is a good start I guess :)

Offline mannuri

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 12
  • Rating: +0/-0
    • View Profile
Re: Release of FormulaPro for the Nspire
« Reply #43 on: November 23, 2012, 06:18:54 pm »
maybe the problem is there:

 --Reynolds number
 aF(2, 1, "Re=V*D/"..c_nu, U("Re","V","D",c_nu))

trie
aF(2, 1, "Re=V*D/"..c_nu.."", U("Re","V","D",c_nu)) or something close dont use the _ simbol maybe it works

If you edit you .tns using student software you may be able to replace c_nu per ν

edit: ops ν isnt v but the greeg letter, sry my poor english

edit again xD: you have 5 incognits and 4 equations so..

You need use a iterations giving a initial value to f or other variable
« Last Edit: November 23, 2012, 06:51:34 pm by mannuri »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Release of FormulaPro for the Nspire
« Reply #44 on: January 18, 2013, 11:58:11 am »
Update !


This post to announce the release of the version 1.4 (beta) of FormulePro !

Here's the changelog of your favorite program ;)
- Ability to open external formulas DBs (this is still being tested. It works but a DB editor would have to be created for the user's convenience ;) )
- Subcat text in manual solver frame gets cropped if too long.
- Tricky mouseUp now working "properly" (ti "bug" when the cursor wasn't shown and the click button was still pressed. It acts as Enter now, as kind of expected)
- mouseUp overall (since it's expected/needed for sButton's improvement)
- sButton more realistic (actually pushed when being clicked on release when mouse exits the area)
- Overall focus color change : it's now light blue (it now looks better, I guess)
- Bugfixes here and there.

Screenshot of the solver with a "pushed" button :


Download:
http://tiplanet.org/forum/archives_voir.php?id=6034


Original topic : http://tiplanet.org/forum/viewtopic.php?f=50&t=11136

(PS : kinda fixes intelx86's errors, with duplicates. see commits)
« Last Edit: January 18, 2013, 11:59:44 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation