Jump to content
Fórum Script Brasil
  • 0

Erro = can only concatenate str (not "int") to str


Estou com problema no linspace, da o seguinte erro na linha  can only concatenate str (not "int") to str


N_0 = input('Give initial population size N_0: ')
r   = input('Give net growth rate r: ')
dt  = input('Give time step size: ')
N_t = input('Give number of steps: ')
t = linspace(0, (N_t+1)*dt, N_t+2)
N = zeros(N_t+2)

N[0] = N_0
for n in range(N_t+1):
    N[n+1] = N[n] + r*dt*N[n]

import matplotlib.pyplot as plt
numerical_sol = 'bo' if N_t < 70 else 'b-'
plt.plot(t, N, numerical_sol, t, N_0*exp(r*t), 'r-')
plt.legend(['numerical', 'exact'], loc='upper left')
plt.xlabel('t'); plt.ylabel('N(t)')
filestem = 'growth1_%dsteps' % N_t
plt.savefig('%s.png' % filestem); plt.savefig('%s.pdf' % filestem)

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 1

seu erro

t = linspace(0, (N_t+1)*dt, N_t+2)


t = linspace(0, (int(N_t)+1)*int(dt), int(N_t)+2)


comece pelo o inicio, pois seu erro é coisa que se aprende na primeira hora, deixe o matplot para depois

sugiro ir no site oficial e seguir a apresentação na documentação

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...