Programming van der Waals Equation

1,842 views
Skip to first unread message

Southpaw Wooldridge

unread,
May 6, 2016, 3:18:52 PM5/6/16
to tins...@googlegroups.com
I have never tried programming or creating functions yet.  I would like to create a program or function (not sure which to use) to ask for the variables (via a popup entry window if possible) in the van der Waals equation and solve for the missing variable. Here is the equation
Inline image 1
measured in the following:
P,  (uppercase in my textbook) = atm
n= mol
a=L^2*atm/mol*K(elvin)
b=L/mol
V=L
R= constant= .08206 L*atm/mol*K
T= K

If someone wants to create the program that would be great, but links/directions on how to create a program or function would be wonderful too.  The units are not needed but I am curious how to add those and have it give the answer with the correct units.   
Thanks 
Southpaw

John Hanna

unread,
May 6, 2016, 4:16:09 PM5/6/16
to tins...@googlegroups.com

See education.ti.com… Activities>TI Codes for ‘getting started lessons on coding both TI-84 and TI-NSpire

 

On TI-Nspire…

Programs and functions are most easily created using the Calculator app.

Press menu, ,select Programs and Functions>Program Editor>New

This creates a Program Editor app next to the Calculator app.

This allows you to tweak the program/function and test it side-by-side.

Remember to press ctrl-B (Check Syntax & Store) after editing the program.

 

Your equation is going to be challenging to code: How will it know what to solve for?

You can use Request “prompt”,var

      for input (‘pop-up’ windows) but what will you enter for the unknown var?

You might need CAS for ‘Solve”ing but Nsolve works on numeric if you’re OK with approximate answers.

You definitely need CAS for the units.

 

Good luck on the adventure!

Best Regards,

         John Hanna

         jeh...@optonline.net

         www.johnhanna.us

         T3 - Teachers Teaching with Technology

         http://education.ti.com

--
--
To post to this group, send email to tins...@googlegroups.com
To unsubscribe send email to tinspire+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com.au/group/tinspire?hl=en-GB?hl=en-GB
The tns documents shared by group members are archived at
https://sites.google.com/site/tinspiregroup/classroom-news/welcome-abouttime

---
You received this message because you are subscribed to the Google Groups "tinspire" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinspire+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

image001.png

eagl...@duetsoftware.ca

unread,
May 6, 2016, 4:48:10 PM5/6/16
to tins...@googlegroups.com
In addition to what John said, programs cannot return values - you'd have to display it - so if you want to use it in inline calculations, you'd want a function.

If you want to solve for any variable, you'd be best off creating separate functions to solve each.  If you wanted, you could then create another function that differentiates between cases and calls the appropriate function, passing back the appropriate result.

Finally, if it's just going to be a function, why not treat it like an actual function and pass the values as parameters?  It's easier.  It's also faster since after the user has done it once, it wastes time for them to wait for and read each box and put the values in - just type them in when you call the function.  And it would definitely assist with creating a menu program because then you can have the menu program ask for appropriate values depending on which variable it's solving for, and call the correct function without further interruptions.

  --Eric

<image001.png>

Southpaw Wooldridge

unread,
May 7, 2016, 2:00:57 PM5/7/16
to tins...@googlegroups.com

this sounds like what I want to do.  I have both the CAS and non-CAS versions but can use the CAS for chemistry. Ok, I was able to make a function that worked the actual equation.  But I want to add a couple features and I am not sure how to write them, I will try making it as a program.
I want to add a couple of messages that 
1) remind me of which values to enter.  either when I start or If I hit enter with no values entered.  instead of giving me an error, it will give me a message telling me which values to enter in what order
2)  I got the equation to work by specifying with the solve command to solve for "x" so with 6 values, i just enter X for the value of the unknown and numbers for the other 5 values as they will be given.  I want to have a message that says "enter X for unknown value" I would really like a popup like you get with the financial interest app that has all the values on one screen and have the 2 messages included.  What I don't really understand is how to format and use the Disp, Request, and Requeststr(how is this function different from Request?)  functions to do that.   I also thought I might need to use an If/then/else type function...  
I have never programmed anything in my life so I am winging it here.  
I am thinking something like:
Request "Enter X if ukn, Enter (P,V,a,n,b,T)" P,V,a,n,b,T  but I get syntax errors.

my other idea is to have it ask "enter unknown variable"  then have the program specify unknown variable as X and then ask for the remaining 5 variables.  But I have no idea how to go about this. probably 6 lines of code like: if X=p then request v,a,n,b,t else if V=p then request p,a,n,b,t else ....  etc.  remember I have never done coding, just trying to use logical approach.
here is what I got so far.

Thanks for any help
Southpaw

Csaba Tizedes

unread,
Jul 20, 2016, 7:25:28 PM7/20/16
to tinspire
1.) As you can see in the vdw equation the a, b and R are constants, therefore no need to use in the definition of the equation.

2.) I defined vdw equation in this form:
Define vdw(p,v,n,t)=(p+n^2×a/v^2)×(v-n×b)-n×r×t

3.) After then I defined the values of constants (sorry I can think only SI) - a and b for air:
135.8->a
0.0364->b
8.314->r

4.) I set the values of known variables, for example what is the volume of n=1mol, p=101.3kPa pressure, t=(20+273)K temperature air?
1->n
101.3->p
20+273->t

5.) After than I solved the vdw equation for the unknown V, and immediately stored the result in V:
nSolve(vdw(p,v,n,t)=0,v)->v
The result is 24.028dm^3 is stored into variable v

6.) What is the temperature of this air if we have n=2mol and the other values are not changed?
nSolve(vdw(p,v,n,t)=0,t)|n=2->t
The result is 147.3K, stored in variable t

I hope this straightforward method was useful for you.


Csaba

Csaba Tizedes

unread,
Jul 20, 2016, 7:39:41 PM7/20/16
to tinspire
Short notes to the above:

a.) The dimensions of a and b:
[a]=(kPa × dm^6)/mol^2
[b]=dm^3/mol

b.) The point 6.) is a little dangerous, because the variable n is not change if you use the "when" operator. Just check the value of n, you get n=1. If you do not want any trouble with it, simple store n=2 value and use the nSolve without "where" operator:
2->n
nSolve(vdw(p,v,n,t)=0,t)->t


Csaba
Reply all
Reply to author
Forward
0 new messages