Advertisement

08.18.2008 at 03:26PM PDT, ID: 23657938 | Points: 500
[x]
Attachment Details

Calling Gaussian function-Python-Beginner

Asked by optimum_ in Python Scripting Language

I was set this question in class, I wrote most of the code, but I cant get the same output as required.
Below is the code I wrote, any help on this is greatly appreciated/

"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).
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
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)
print line(gauss)   
 
 
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 plot100
*
 
Please choose a scale for your plot100
*
 
*
[+][-]08.18.2008 at 06:14PM PDT, ID: 22256606

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 06:17PM PDT, ID: 22256612

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 06:29PM PDT, ID: 22256651

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 07:14PM PDT, ID: 22256833

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 07:37PM PDT, ID: 22256907

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:46AM PDT, ID: 22259666

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:57AM PDT, ID: 22259780

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 07:36AM PDT, ID: 22260202

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 08:45AM PDT, ID: 22260879

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 09:50AM PDT, ID: 22261564

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628