# Solving two very simple first differential equations

Hi dear. I am a newbie in Julia. I wanted to solve two first differential equations as
di/dt=-(R/L)i-(1/L)*v+(1/L)a
dv/dt=(1/C)i

with Julia which R,L, C is constant and the variable is i(t) and v(t).
I used the function Lorenz!(du,u,p,t) but plot is a sinusoidal waves, while it should be a damed sinusoidal wave
This is my Code:
using Plots
using DifferentialEquations
R=0.1;
L=0.01
C=0.001;
a=1;
function lorenz!(du,u,p)
du=-(R/L)*u-(1/L)*u+(1/L)*a;
du=(1/C)*u;
end
u0=[0,0];
tspan = (0.0,100)
prob = ODEProblem(lorenz!,u0,tspan)
sol = solve(prob)
gr()
plot(sol,vars=(0,1))

using Plots, DifferentialEquations
function lorentz!(du,u,p,t)
I, V = u
R, L, C, a = p
du = dI = -(R/L)*I-(1/L)*V+(1/L)*a
du = dV = (1/C)*I
end
u0 = [0,0];
tspan = (0.0,10)
p = [0.1, 0.01, 0.001, 1.0]
prob = ODEProblem(lorentz!,u0,tspan,p)
sol = solve(prob)
gr()
plot(sol,vars=(0,1),xlim=(0,1))

1 Like

Thanks a million for the response.
It works:). I don’t know how to appreciate the time and energy you spent