Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Need help with fixing Python code to make output match with the corresponding graph from numpy import zeros, linspace import matplotlib.pyplot as plt from

# Need help with fixing Python code to make output match with the corresponding graph
from numpy import zeros, linspace
import matplotlib.pyplot as plt
from scipy import stats
import math
dt =5
N_t =7
B =[0.015,0.021,0.031,0.04,0.055,0.075,0.106]
dB = zeros(N_t)
Bexp = zeros (N_t)
t = linspace(0, N_t-1, N_t)
t_actual = linspace(0,(N_t-1)*dt, N_t)
for i in range(0, N_t-1):
dB[i]= B[i+1]- B[i]
copy_dB = dB[:(N_t-1)]
copy_B = B[:(N_t-1)]
slope, intercept, r_value, p_value, std_err = stats.linregress (copy_B, copy_dB)
tdouble = math.log(2)/math.log(1+slope)*dt
mu= math.log(2)/tdouble
Bexp[0]= B[0]
for i in range(1, N_t):
Bexp[i]= B[0]* math.exp(mu*t_actual[i])
plt.figure(2)
plt.plot(t_actual, B,"bo", t_actual, B[0]*pow(slope+1,t), t_actual, Bexp, "ro")
plt.legend(["data","B0*(1+c)^(t/5)","B0*exp(mu*t)"], loc= "upper left")
plt.xlabel("time")
plt.ylabel("B")
dt_7=7
t_actual_7= linspace(0,(N_t-1)*dt_7, N_t)
Bexp_7= zeros(N_t)
Bexp_7[0]= B[0]
for i in range (1, N_t):
Bexp_7[i]= Bexp_7[i-1]* math.exp(mu*t_actual[i])
plt.plot(t_actual, B,"bo", t_actual, B[0]*pow(slope+1,t),"r-", t_actual_7, B[0]*2.718**(mu*t_actual_7),"gs")
plt.legend(["data","B0*(1+c)^(t/5)","B[0]*2.718**(mu*t_actual_7)"], loc="upper left")
plt.xlabel("time")
plt.ylabel("B")
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions