MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 2 problems!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120330] Re: 2 problems!
  • From: W Craig Carter <ccarter at mit.edu>
  • Date: Tue, 19 Jul 2011 06:56:15 -0400 (EDT)
  • References: <201107181014.GAA26923@smc.vnet.net>

Hello Mary,

Before giving you a brief answer, it looks like you are exploring the 
critical points of a van der Waals gas. I have a fairly complete 
mathematica notebook to do this---I use it for teaching--and 
demonstrates how one should rescale the van der Waals equation. If you 
would like a copy, contact me directly.

I don't recommend continuing on the path that you are following, but 
here are some pointers to help you learn some mathematica-ology.

There are several things you can do immediately to help your code.
1. Avoid using upper case first letters for your own variables.
2. Take a look at your intermediate output in your Do[] (btw, I think 
you meant to loop over u and w).

3. Note the form of one of your intermediate expressions:

sol = Solve[Rationalize[der1 && der2 && p, 0], {a, b, V}, Reals] // N

This is a long set of six solutions that has Root[] functions in them 
for subsequent numerical processing.  You probably would be better off 
writing a function that takes arguments for u_ and w_, and then uses 
NSolve to get your solution. You don't need to use the Rationalize here. 
 Note the form of one of your intermediate solutions:

N[({a, b, V} /. sol) /. {u -> 10, w -> 12}]

4. You get one real solution and the others are undefined.  You will 
want an automatic method of picking out your real solution. Here is an 
example:

Cases[N[({a, b, V} /. sol) /. {u -> 10, w -> 12}], {_Real, _Real, 
_Real}]

I don't follow what you had intended for this expression: \[CapitalPsi] 
-> a; in your Do[].  Also, I don't think your values of a,b, and V are 
changing in your loop, so there is no need to recompute the solution 
each iteration.

5. Collect your solutions into a table:


sol = Solve[Rationalize[der1 && der2 && p, 0], {a, b, V}, Reals] // N;
abV = {a, b, V} /. sol

vdwSolutions = 
Table[Cases[N[abV /. {u -> ui,  w -> 12}], {_Real, _Real, 
_Real}],{ui,-100,100,.01,{vi,-100,100,.01}]

6. Then export your data to excel if you wish
Export["solutions.xls", vdwSolutions]

Again, This isn't the solution path I recommend....
Kind Regards,

W Craig Carter
Professor of Materials Science, MIT



On Jul 18, 2011, at Mon, Jul 18, 11 ---6:14 AM, Mary R wrote:

> Hi to everyone!
> I've got two problems that for me is quite difficult...
> 1. I want to calculate in the same cicle Do this coefficient a,b,V and
> evaluate the difference beetween this calculate coefficient and the 
real
> parameter areal,breal,Vreal and evaluate a coefficient Omega.
> I was able to calculate only the coefficient a,b,V;
> e.g.
> value u , w {2,2}:=
> 
{{{a->-2.57258*10^7,b->-1108.81,V->679.954},{a->1.59736*10^6,b->-210.798,V->380.617},{a->1.3548*10^7,b->53.9538,V->292.367}},
> *3.03895*10^-8 a*,-*3.34268*10^12+a,128465. +b,-200+V*}
> can you hel me?
> 2. The second problem is to change the result from InputForm in a table to
> export in Excel;
> that is trasform my result
> (e.g.)
> value u , w {2,2}: =
{{{a->-2.57258*10^7,b->-1108.81,V->679.954},{a->1.59736*10^6,b->-210.798,V->380.617},{a->1.3548*10^7,b->53.9538,V->292.367}},3.03895*10^-8
> a,-3.34268*10^12+a,128465. +b,-200+V}
> in a table!
> ---------------------listing-----------------------
> pression = (R Subscript[T, c])/(V - b) - a/(
>    b^2 w + b u V + V^2) /. {Subscript[T, c] -> 425.1,  R -> 83.14};
> der1 = D[pression, V] == 0;
> der2 = D[pression, {V, 2}] == 0;
> p = 37.96 - pression == 0;
> Vreal = 200;
> areal = 3.3426778202443823`*^12;
> breal = -128465.27253980785`;
> \[CapitalPsi] = \!\(TraditionalForm\`
> \*FractionBox[\(a\ P\), \(
> \*SuperscriptBox[\(R\), \(2\)]\
> \*SuperscriptBox[\(T\), \(2\)]\)]\  /. {T -> 425.1, \ \ R -> 83.14,
>      P -> 37.96}\);
> Do[sol = Solve[Rationalize[der1 && der2 && p, 0], {a, b, V},
>    Reals] // N; \[CapitalPsi] -> a; A = a - areal; B = b - breal;
> volume = V - Vreal;
> Print[ "value u , w, Omega,difference ", {u, w},
>  ": ", {sol, \[CapitalPsi], A, B, volume}], {u,-100, 100,0.1}, {u,-100,
> 100,0.1}]
> {a, b, V} /. sol
>
> Thanks a lot in advance for your help.
> MR
>
>



  • References:
  • Prev by Date: Re: remarks on significance arithmetic implementation [Was: Re: Numerical accuracy/precision - this is a bug or a feature?]
  • Next by Date: Re: Unexpected Behavior: SetDelayed versus Set
  • Previous by thread: 2 problems!
  • Next by thread: Find position of nonzero elements