[Tutor] Gaussian function

optimum jozzy_a at hotmail.com
Mon Aug 18 23:05:10 CEST 2008


SOrry, just started python programming. I have so much to learn still.
My output was 
What is the value of xmin?-2.5
What is the value of dx?0.5
What is the value of nx?11
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
Please choose a scale for your plot50
*

I think I called the functions now...but I don't get the desired output, is
it my gaussian function which is wrong?
We had a lecture on "def" function, but wasn't really told how to do this
program. 

from __future__ import division
import math

a=raw_input("What is the value of xmin?")
b=raw_input("What is the value of dx?")
c=raw_input("What is the value of nx?")

xmin=float(a)
dx=float(b)
nx=int(c)
n=int(c)
l=[]

for x in range(0.00,n):
    print xmin+x*dx

def line(n):
    s=''
    i=raw_input("Please choose a scale for your plot")
    n=int(i)
    for j in range(0.00,n):
        s= s+ "*" + "\n"
        print s
        return s
        
def gauss(x):
    gaussa=math.pi(2)
    gaussb=math.sqrt(gaussa)
    gaussc=1/gaussb
    gaussd=math.exp(-0.5*-2.00**2)
    gausse= gaussc*gaussd
    return gausse
    print gausse

    
    
line(gauss)





optimum wrote:
> 
> I dont think that this program uses the gaussian function, am I in the
> right wavelength? 
> 
> from __future__ import division
> import math
> 
> a=raw_input("What is the value of xmin?")
> b=raw_input("What is the value of dx?")
> c=raw_input("What is the value of nx?")
> 
> xmin=float(a)
> dx=float(b)
> nx=int(c)
> n=int(c)
> l=[]
> 
> for x in range(0.00,n):
>     print xmin+x*dx
> def line(n):
>     s=''
>     i=raw_input("Please choose a scale for your plot")
>     n=int(i)
>     for j in range(0.00,n):
>         s= s+ "***" + "\n"
>         print s
>         return s
>         
> def gauss(x):
>     gaussa=math.pi(2)
>     gaussb=math.sqrt(gaussa)
>     gaussc=1/gaussb
>     gaussd=math.exp(-0.5*-2.00**2)
>     gausse= gaussc*gaussd
>     print gausse
> 
> 
> 
> Bob Gailer wrote:
>> 
>> optimum wrote:
>>> Hey. Is there anyone who can give me some help? 
>>> Below is the question I was set.
>>>   
>> This sounds like a homework assignment. We don't write programs for 
>> assignments. We offer help after you give it your best effort.
>>> I am having trouble with the gaussian function and don't really know
>>> where
>>> to start.
>>>   
>> 
>> It sounds like you are having trouble with programming, not with the 
>> gaussian function. Did you run the following code? Did it give you any 
>> useful results? (I expect it to raise an exception.) At least run it and 
>> see what happens. How does it contribute to the overall result?
>> 
>>     s=''
>>     for n in range (0,100):
>>     s=s+ '*'
>>     print s
>> 
>> 
>> Can you at least outline the program or algorithm as a starting place.
>>> "Write a program which asks the user for values
>>> of xmin, dx and nx. The program should then
>>> output a plot of the gaussian function
>>>
>>>
>>> at the following series of values of x:
>>> xmin, xmin+dx, xmin+2*dx, xmin+3*dx, : : :,
>>> xmin+(nx-1)*dx. e.g. the following output
>>> should result if xmin = 2:5, dx = 0:5 and
>>> nx = 11.
>>> -2.50 *
>>> -2.00 ***
>>> -1.50 ******
>>> -1.00 ************
>>> -0.50 ******************
>>> 0.00 ********************
>>> 0.50 ******************
>>> 1.00 ************
>>> 1.50 ******
>>> 2.00 ***
>>> 2.50 *
>>> The program should contain and make full use
>>> of the following functions:
>>> gauss(x) - Returns the value of the Gaussian
>>> function
>>>
>>> line(n) - Prints a line of n asterisks followed
>>> by a newline character.
>>>
>>> You will need to choose a scale for your plot;
>>> in the example shown the number of asterisks
>>> is 50 * gauss(x).
>>>
>>> Should I start with a program like this?
>>>
>>>     s=''
>>>     for n in range (0,100):
>>>     s=s+ '*'
>>>     print s
>>>
>>> Thanks for any help received. :confused:
>>>   
>> 
>> 
>> -- 
>> Bob Gailer
>> Chapel Hill NC 
>> 919-636-4239
>> 
>> When we take the time to be aware of our feelings and 
>> needs we have more satisfying interatctions with others.
>> 
>> Nonviolent Communication provides tools for this awareness.
>> 
>> As a coach and trainer I can assist you in learning this process.
>> 
>> What is YOUR biggest relationship challenge?
>> 
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Gaussian-function-tp19022946p19039962.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list