Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 1st, 2013, 09:19 AM
 usama khan
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 58 m 43 sec
Reputation Power: 0
How to seperate equation for making a program

hi . . my name is usama khan
i am the student of civil engeering and we got assignment to make a project program on flexible pavement design using python.

i know very litle about programing. still learning from tutorials. u can call me a beginner.
now i need to solve this equation so that i can put this in python but the formula of design is very complex

Formula is :

log(W18) = (Z)(S)+9.36log(SN+1) -2.0+(log(dpsi/(4.5-1.5))(/(.40+1094/(SN+1)^2.5)+2.32log(Mr)-8.07

every thing is constant except this SN. . i want to seperate SN like SN= rest of the stuff. how can i seprate it because manualy its impossible to take SN out.
so plz help me out.

#2
January 1st, 2013, 01:52 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,115
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 56 sec
Reputation Power: 455
Please write your formula clearly, or provide a web reference where we can see it.
"search for this that" is probably sufficient since you won't be able to post links. Or replace the dots with spaces. www google com

Given that programming is new for you, does
W18 mean (in LaTeX mathmode notation) W_{18} or 18 times W? Given that it's in a log I presume it means W_{18} .

The parentheses have to balance. Your "(" outnumber the ")" by 2. You probably meant a closing paren instead of (/ .

dpsi (probably means pressure drop in psi rather than d*p*s*i but you must clarify).

Mr means M_r or M*r ?

You want to solve for SN? S_N ? S*N ?

Hint, if wolfram alpha can understand the formula you've written it sufficiently well.
__________________
[code]Code tags[/code] are essential for python code!

#3
January 1st, 2013, 02:15 PM
 usama khan
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 58 m 43 sec
Reputation Power: 0
[IMG]formula is given on this link :

we need to find SN using this graph. .

i want to make a program which doesnot require that all hactic graph work. . shown in the picture. .

remember i am very beginner in pyton. . dont have expertise. .want to learn software as well as civil engeering. .so show me the way. .[/IMG]

i am new user they are not allwing me to put up a link. .

search on google.com . . .flexible pavement nomogram. . u will c in first ten a hug graph. .on it is a formula. .

#4
January 1st, 2013, 03:46 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,115
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 56 sec
Reputation Power: 455
Solutions in 3 languages. I tested the final solution in j www.jsoftware.com which agrees with the example I found. Heck of a nomograph!
Code:
```'''
######################mathematica
mathematica, as I recall
NSolve[Log[w18] == (zr*s0)+9.36 * Log[sn + 1] - 0.2 + ((Log[psi/(4.2-1.5)])/(0.4+(1094/(sn+1)^5.19)))+2.32*Log[mr]-8.07/.{zr->1,s0->2,psi->3,mr->4,w18->5},sn]
'''

#########################python:

from numpy import newtonsMethod # this statement is intended only to give the gist of the idea.

import math

class PVT:

def __init__(self,zr,s0,psi,mr,w18):
(self.zr,self.s0,self.psi,self.mr,self.w18) = (zr,s0,psi,mr,w18)
self.max = 999

def __call__(self,sn):
(zr,s0,psi,mr,w18) = (self.zr,self.s0,self.psi,self.mr,self.w18)
log = math.log
try:
zero = (zr*s0)+9.36 * log(sn + 1) - 0.2 + ((log(psi/(4.2-1.5)))/(0.4+(1094/(sn+1)**5.19)))+2.32*log(mr)-8.07-log(w18)
except:
zero = self.max
self.max = max(zero,self.max)     # prepare for bad values
return zero

# again, this statement is only approximately correct
print(newtonsMethod(function=PVT(zr=1,s0=2,psi=3,mr=4,w18=5),initialGuess=6))

'''
############################### j
NB. www.jsoftware.com  you'll need to install the addons.

'zr s0 psi mr w18' =. m
sn=. y
t0=. zr*s0
t1=. 9.36*^.>:sn
t2=. _0.2
n=. ^.psi%4.2-1.5
d=. 0.4+1094%(>:sn)^5.19
t3=. n%d
t4=. 2.32*^.mr
t5=. _8.07
t6=. -^.w18
terms=. t0,t1,t2,t3,t4,t5,t6
+/terms
)

Note 'Example'
To the best of my understanding, this does solve the example
of page 8, Topic 7 - AASHTO Flexible Pavement Design.pdf

With zr = 0.91, s0 = 0.35, psi = 2, mr = 5, and w18 = 5e6

amoeba is an optimizer,
0.91 0.35 2 5 5e6 Sn  is the verb to zero
hence we square it.  *:
1e_4 is the tolerance,
5,:6 is the starting simplex

(*:@:(0.91 0.35 2 5 5e6 Sn)) (amoeba 1e_4) 5,:6
┌───────┬──────────┐
│5.08594│7.51186e_9│
└───────┴──────────┘
)

'''```

Last edited by b49P23TIvg : January 1st, 2013 at 05:37 PM.

#5
January 1st, 2013, 04:42 PM
 usama khan
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 58 m 43 sec
Reputation Power: 0
thank u very much for that much concerns. .

i copied the program code in to python 2.5. . its giving error. .
newtonsMethod couldnot be found etc. .

so i want to ask will that concerns the python version i am using or i am making a mistake in copying the code. .

#6
January 1st, 2013, 04:43 PM
 Nyktos
Contributing User

Join Date: Dec 2012
Posts: 114
Time spent in forums: 1 Day 11 h 54 m 6 sec
Reputation Power: 3
NumPy is a third-party library, not part of the standard library.

#7
January 1st, 2013, 04:47 PM
 usama khan
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 58 m 43 sec
Reputation Power: 0
again thanks but am beginner. .

can u just explain it.. am sorry am wasting ur time by asking silly questions. . but i am very beginner to python. . very begginer. .

sorry once again for stupid questions. .i realy want to learn. .
i have learnt if elif else while and for loop. . and someone said that its enough for making a mathematical program. .

so guide me what shud i do?

regards

#8
January 1st, 2013, 05:23 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,115
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 56 sec
Reputation Power: 455
Here's a python solution using scipy. www.scipy.org
The program requires a good understanding of python, except you should be able to follow the algebra.
Code:
```# scipy comes from www.scipy.org

import math
import scipy  # also has log
import scipy.optimize

class PVT:

def __init__(self,zr,s0,psi,mr,w18):
(self.zr,self.s0,self.psi,self.mr,self.w18) = (zr,s0,psi,mr,w18)
self.max = 999

def __call__(self,sn):
(zr,s0,psi,mr,w18) = (self.zr,self.s0,self.psi,self.mr,self.w18)
log = math.log
try:
n = log(psi/(4.2-1.5))
d = 0.4+(1094/((sn+1)**5.19))
fraction = n/d
zero = (zr*s0)+9.36*log(sn+1)+(-0.2)+fraction+2.32*log(mr)-8.07-log(w18)
except:
zero = self.max
self.max = max(zero,self.max)     # prepare for bad values
return zero

def minimize_me(**kwargs):
f = PVT(**kwargs)
return lambda sn, f = f : f(sn)**2

func = minimize_me(zr = 0.91, s0 = 0.35, psi = 2, mr = 5, w18 = 5e6)

amoeba_solution = 5.086
print(scipy.optimize.fmin_bfgs(func,amoeba_solution,full_output=True))```

Here's a simple example of fmin_bfgs to find the zero of
4*x + 2
which does find x = -0.5 .
Code:
```def f(x):
return (4*x+2)**2

print(scipy.optimize.fmin_bfgs(f,0))```

The j definition was wrong, is now fixed, and its solution agrees with the python solution, 7.8, which doesn't agree with the charted solution as best I can see it.[/edit]

Last edited by b49P23TIvg : January 1st, 2013 at 05:43 PM.

#9
January 1st, 2013, 05:46 PM
 usama khan
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 58 m 43 sec
Reputation Power: 0
thanks. .

i got u. .

reallly really bunch of thanks sir. .))

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > How to seperate equation for making a program