3

I'm trying to implement an equation from a paper in Python (black square equations) -

enter image description here

So far I have a simplified model but I'm unable to generate the intended output (below image); I suspect the issue is with np.exp() though I'm unsure - any suggestions of how I can do this?

import numpy as np
import math
import matplotlib.pyplot as plt

f     = 1e6
T     = 1/f
Omega = 2*np.pi*f

i = np.arange(0,50e-6,100e-9)
y = np.sin(Omega*i) * (i**2) * np.exp(-i)   

plt.figure(1)
plt.plot(i,y,'b-')
plt.grid()
plt.show()

enter image description here

1
  • 2
    Have you played with the input values? Try decreasing the frequency and extending the range of i. Commented Oct 27, 2013 at 22:15

3 Answers 3

2

To illustrate Jacob's comment, here's what you can get by tweaking the constants:

Graph

Code:

import numpy as np
import matplotlib.pyplot as plt

f     = 5
Omega = 2*np.pi*f

i = np.arange(0, 10, 0.001)
y = np.sin(Omega*i) * (i**2) * np.exp(-i)

plt.figure(1)
plt.plot(i,y,'b-')
plt.grid()
plt.show()

Or, you could keep the time scale and introduce an h of about 5e-6, as Bas Swinckels suggests in his answer:

f     = 1e6
Omega = 2*np.pi*f

i = np.arange(0,50e-6,100e-9)
y = np.sin(Omega*i) * (i**2) * np.exp(-i/5e-6)

This produces a very similar output.

Sign up to request clarification or add additional context in comments.

Comments

2

I suggest to use the exact same variable names as in the paper, that makes things so much clearer. For time, always use t or time, no excuses. The variable i is normally used for indices or complex numbers. You are also missing the variables m (which you hard-coded as 2), v_0 and h. I guess you need to set h to the correct value to solve your problem. In this sort of problems, h is usually a decay time, which you, by forgetting it in the formula, implicitly took as 1 second. Given the high frequencies of your problem, this should be much shorter. Looking at your example plot, you should probably set it to a few times T.

1 Comment

+1, h seems to be the problem, as illustrated in my answer below.
0

Also, I think one primary mistake that you are making is that you are plotting yagainst i- which IMHO should be actually a yvs. 1/iplot. this, combined with the comment from @BasSwinckels, when you start fiddling around with the parameters, you should get closer to the aim plot.

Cheers! And all the best!

2 Comments

OK, thanks all for taking a look - yes t for time makes sense, I was using i as in index. Also, h=1 in my first look, and I know see h as the decay factor.
@BasSwinckels I stand corrected. I had tried a few plots with 1/i and it looked like something similar but I was definitely on the wrong track. Sorry for the obfuscation @Jake French

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.