Hi Guys
Please refer to the below code. It was running perfectly and now for some reason I am getting the following error, “ERROR: UndefVarError: sol
not defined”. Which makes no sense it has been defined…
Any assistance would be appreciated.
using Plots
using DifferentialEquations
function sdof!(dx,x,p,t)
m,k,c,f,w = p
dx[1] = x[2]
dx[2] = (-c*x[2]-k*x[1]+f*sin(w*t))/m
end
nf = [9.69,57.77,127.28,174.53,313.719]*6.28 # [rad/s]
m = [74.11,13.241,2.4,3.4,2.366]/100# [%]
f = 1000 # [N] forcing function
M = 611.778
tspan = (0,1)
x0 = [0.00,0.00]
T_displacement = zeros(length(tspan[1]:0.001:tspan[2]))
for i in 1:length(nf)
k = nf[i]^2*m[i]*M
c = 0.01*(m[i]*M+k)
p = m[i]*M,k,c,f,50*6.28
prob = ODEProblem(sdof!, x0, tspan, p)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8, saveat = 0.001)
T_displacement += sol[1,:]
end
plotly()
#plt_1 = plot()
display(plot(sol.t,T_displacement,xlabel = "Time (sec)", ylabel = "Displacement (m)"))