Python Forum
how can I create graphics using matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can I create graphics using matplotlib
#1
hello, I'm trying to use the matplotlib library and since I'm new my code has been written wrong, can you tell me what I failed ?, more than anything I would like to be corrected
x = np.arange(1,41)
b = 0.7
a =(1 - b) / (1-b**5)
i = np.arange(1,5)

w = a*(b**(5-i))
for n in range[5:40]:
    y = [w*x[n-4:n].conj().T]
n = range[5:40]
plt.plot(x,y)
plt.show()
my question from the book is the following:

  1. Generate a MATLAB graph of the output response and y[n], for 5 <= n <= 40 of the filter
    PMPE in point 5, with b = 0.7, when the input x[n] is:

    a) x[n] = 1, 0 <= n <=40
graphic that I want to obtain
[Image: fu4du3k5scs6je27g.jpg]
I would appreciate any help from you
Reply
#2
There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y?
Reply
#3
(Nov-20-2018, 01:20 PM)Gribouillis Wrote: There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y?
ok,sorry for the delay
[Image: dy6u5128enq07ay7g.jpg]
Reply
#4
It is still unclear, what are the possible values of n? When i varies from 0 to N-1, the index n-i decreases from n to n-N+1, which may be negative. Can you explain this point?

It looks like a convolution, some special functions such as numpy.convolve may be useful later once we understand what you are doing.
Reply
#5
(Nov-20-2018, 05:16 PM)Gribouillis Wrote: It is still unclear, what are the possible values of n? When i varies from 0 to N-1, the index n-i decreases from n to n-N+1, which may be negative. Can you explain this point?

It looks like a convolution, some special functions such as numpy.convolve may be useful later once we understand what you are doing.

Well the code had found it in Matlab and I have guided him, now I show you the code made in Matlab.
vew image
Reply
#6
I could run your code in Scilab. Here is a first python equivalent
import numpy as np
from matplotlib import pyplot as plt
N = 40
x = np.ones(N+1)
b = 0.7
S = 5
a =(1 - b) / (1-b**S)
i = np.arange(1,S+1)
 
w = a * (b**(S-i))
# print(w)
y = np.zeros(N)
y[S-1:] = [ np.dot(w, x[n-S+1:n+1].T) for n in range(S-1, N)]
print(y)
print(len(y))
plt.plot(range(S, N+1),y[S-1:], marker='o')
plt.plot(range(S, N+1),y[S-1:], linestyle='-')
plt.show()
Reply
#7
(Nov-20-2018, 07:07 PM)Gribouillis Wrote: I could run your code in Scilab. Here is a first python equivalent
import numpy as np
from matplotlib import pyplot as plt
N = 40
x = np.ones(N+1)
b = 0.7
S = 5
a =(1 - b) / (1-b**S)
i = np.arange(1,S+1)
 
w = a * (b**(S-i))
# print(w)
y = np.zeros(N)
y[S-1:] = [ np.dot(w, x[n-S+1:n+1].T) for n in range(S-1, N)]
print(y)
print(len(y))
plt.plot(range(S, N+1),y[S-1:], marker='o')
plt.plot(range(S, N+1),y[S-1:], linestyle='-')
plt.show()

fantastic, thank you very much for doing it saved me from a headache, thank you very much
Reply
#8
but I want to know how you did the graph, see if I have the following, how would you do it?
  • x[n] = n, 0 <= n <= 40
Reply
#9
I think one only needs to replace line 4 with
x = list(range(N+1))
If you want to go further, you need to analyse the python code to understand how it works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped. Nidwolff 1 328 Mar-04-2024, 06:07 AM
Last Post: Danishhafeez
  treatment of graphics KirillCh 0 1,354 Sep-16-2020, 10:05 AM
Last Post: KirillCh
  matplotlib.pyplot functions create new figures instead of applying to the current one karkas 2 2,049 Jul-09-2020, 08:32 AM
Last Post: karkas
  How to create matplotlib subplots from figures vitaly 3 3,087 Mar-02-2020, 12:58 AM
Last Post: scidam
  how can I create a recursive graphic with matplotlib royer14 3 3,695 Nov-22-2018, 05:00 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020