Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2013, 08:19 AM
usama khan usama khan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 usama khan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old January 1st, 2013, 12:52 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old January 1st, 2013, 01:15 PM
usama khan usama khan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 usama khan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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. .

Reply With Quote
  #4  
Old January 1st, 2013, 02:46 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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.

Reply With Quote
  #5  
Old January 1st, 2013, 03:42 PM
usama khan usama khan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 usama khan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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. .

Reply With Quote
  #6  
Old January 1st, 2013, 03:43 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 74 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 37 sec
Reputation Power: 2
NumPy is a third-party library, not part of the standard library.

Reply With Quote
  #7  
Old January 1st, 2013, 03:47 PM
usama khan usama khan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 usama khan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old January 1st, 2013, 04:23 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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.

Reply With Quote
  #9  
Old January 1st, 2013, 04:46 PM
usama khan usama khan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 usama khan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 43 sec
Reputation Power: 0
thanks. .

i got u. .

reallly really bunch of thanks sir. .))

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How to seperate equation for making a program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap