The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
How to seperate equation for making a program
Discuss How to seperate equation for making a program in the Python Programming forum on Dev Shed. How to seperate equation for making a program Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 1st, 2013, 08:19 AM
|
|
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.
|

January 1st, 2013, 12:52 PM
|
 |
Contributing User
|
|
|
|
|
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!
|

January 1st, 2013, 01:15 PM
|
|
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. .
|

January 1st, 2013, 02:46 PM
|
 |
Contributing User
|
|
|
|
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.
require'~addons/math/misc/amoeba.ijs'
Sn=: adverb define
'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 04:37 PM.
|

January 1st, 2013, 03:42 PM
|
|
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. .
|

January 1st, 2013, 03:43 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 88
  
Time spent in forums: 1 Day 5 h 29 m 39 sec
Reputation Power: 2
|
|
NumPy is a third-party library, not part of the standard library.
|

January 1st, 2013, 03:47 PM
|
|
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
|

January 1st, 2013, 04:23 PM
|
 |
Contributing User
|
|
|
|
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))
[edit]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 04:43 PM.
|

January 1st, 2013, 04:46 PM
|
|
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. .  ))
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|