# Solving two very simple first differential equations

**URL:** <https://discourse.julialang.org/t/solving-two-very-simple-first-differential-equations/61472>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 19, 2021, 10:06pm UTC](https://discourse.julialang.org/t/solving-two-very-simple-first-differential-equations/61472 "2021-05-19T22:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)\
**Post date:** [May 19, 2021, 10:06pm UTC](https://discourse.julialang.org/t/solving-two-very-simple-first-differential-equations/61472/1 "2021-05-19T22:06:40Z")

</div>

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[1]=-(R/L)\*u[1]-(1/L)\*u[2]+(1/L)\*a;  
du[2]=(1/C)\*u[1];  
end  
u0=[0,0];  
tspan = (0.0,100)  
prob = ODEProblem(lorenz!,u0,tspan)  
sol = solve(prob)  
gr()  
plot(sol,vars=(0,1))

---

<div class="post-metadata">

**Author:** ![leonandonayre](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@leonandonayre](https://discourse.julialang.org/u/leonandonayre)\
**Post date:** [May 19, 2021, 10:38pm UTC](https://discourse.julialang.org/t/solving-two-very-simple-first-differential-equations/61472/2 "2021-05-19T22:38:13Z")

</div>

Look at this example: [https://diffeq.sciml.ai/stable/tutorials/ode\_example/#Defining-Parameterized-Functions](https://diffeq.sciml.ai/stable/tutorials/ode_example/#Defining-Parameterized-Functions)

> using Plots, DifferentialEquations  
> function lorentz!(du,u,p,t)  
> I, V = u  
> R, L, C, a = p  
> du[1] = dI = -(R/L)\*I-(1/L)\*V+(1/L)\*a  
> du[2] = 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))

---

<div class="post-metadata">

**Author:** ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)\
**Post date:** [May 19, 2021, 10:57pm UTC](https://discourse.julialang.org/t/solving-two-very-simple-first-differential-equations/61472/3 "2021-05-19T22:57:04Z")

</div>

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