How can I plot the Voigt Profile function with varying values of a in Python?

  • Context: Python 
  • Thread starter Thread starter sketos
  • Start date Start date
  • Tags Tags
    Python
Click For Summary

Discussion Overview

The discussion revolves around plotting the Voigt Profile function in Python, specifically focusing on how to implement the integral representation of the function for varying values of the parameter 'a'. The scope includes programming assistance, numerical integration, and the application of mathematical concepts in coding.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant requests help in writing a Python code to plot the Voigt Profile function, defined by an integral involving the parameter 'a'.
  • Another participant emphasizes the importance of showing prior attempts before receiving help, suggesting a collaborative approach to problem-solving.
  • A participant shares a code snippet attempting to implement the Voigt function using numerical integration with the SciPy library, but does not complete the implementation.
  • Another participant suggests using external resources, such as Wolfram Alpha, to assist with integral calculations and translating those into Python code.
  • A further participant provides a link to Wikipedia for additional information on numerical integration techniques for infinite intervals.

Areas of Agreement / Disagreement

Participants generally agree on the need for collaborative problem-solving and the importance of prior attempts in coding. However, there is no consensus on the specific implementation details or the best approach to take in coding the Voigt Profile function.

Contextual Notes

Some limitations include the incomplete code provided by participants and the potential challenges in numerical integration over infinite intervals, which may require careful handling in the implementation.

sketos
Messages
55
Reaction score
0
I very new to python and this might look relatively easy to some of you. I need to write a code so that

H(a,u) = \frac{a}{\pi} \int_{-\infty}^{\infty} \frac{e^{-y^2}}{a^2+(u-y)^2}dy

it plots the above function for different values of the a parameter, so that ultimately i will have a graph of 3 or more function of the form H(a_1,u), H(a_2,u), H(a_3,u) as functions of u. Can anyone provide a code ?
 
Technology news on Phys.org
sketos said:
I very new to python and this might look relatively easy to some of you. I need to write a code so that

H(a,u) = \frac{a}{\pi} \int_{-\infty}^{\infty} \frac{e^{-y^2}}{a^2+(u-y)^2}dy

it plots the above function for different values of the a parameter, so that ultimately i will have a graph of 3 or more function of the form H(a_1,u), H(a_2,u), H(a_3,u) as functions of u. Can anyone provide a code ?

The key is
sketos said:
I need to write a code
We're not going to do this for you. We'll be happy to help you out on it, but you need to show us what you've tried.
 
import numpy as np
import pylab as pl
from math import exp
from scipy.integrate import quad

def voigt( u , a ):

def integrand( y ):

return exp(-y**2)/( a**2 + ( u - y )**2 )

return quad( integrand ,-np.inf , np.inf )x = np.linspace(-100 , 100 )

Func = voigt( x , 0.1 )

pl.plot( x , Func )

pl.show()

This is as far as i got before i posted...
 
sketos said:
I very new to python and this might look relatively easy to some of you. I need to write a code so that

H(a,u) = \frac{a}{\pi} \int_{-\infty}^{\infty} \frac{e^{-y^2}}{a^2+(u-y)^2}dy

it plots the above function for different values of the a parameter, so that ultimately i will have a graph of 3 or more function of the form H(a_1,u), H(a_2,u), H(a_3,u) as functions of u. Can anyone provide a code ?

Teach a man to fish he eats for a lifetime. Here's some important tools to breaking it down. I suck at calculus so I use this to calculate integrals.
http://integrals.wolfram.com/index.jsp
You would enter it in the Wolfram language, where x^y means x to the power of y, remember your parenthesis. Then take the output, and code it in the python language...its the same except x**y = x to the power of y.
 

Similar threads

  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 50 ·
2
Replies
50
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K