# Coupled PDE solver

**URL:** <https://discourse.julialang.org/t/coupled-pde-solver/113636>\
**Category:** Modelling & Simulations\
**Created:** [April 30, 2024, 2:47am UTC](https://discourse.julialang.org/t/coupled-pde-solver/113636 "2024-04-30T02:47:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avishipoddar](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@avishipoddar](https://discourse.julialang.org/u/avishipoddar)\
**Post date:** [April 30, 2024, 2:47am UTC](https://discourse.julialang.org/t/coupled-pde-solver/113636/1 "2024-04-30T02:47:30Z")

</div>

I am trying to solve a coupled linear pde  
I have attached my code below

using DifferentialEquations  
using FiniteDifferences

# Define your system of coupled linear partial differential equations

function coupled\_pdes(du, u, x)  
# Extracting variables  
t, z = x  
# Parameters  
g = 1  
n = 200  
c = 1  
gamma = 4

```
#psi = u[1]
#phi = u[2]

#dpsi/dt = deriv(u[1], (1,), Diferences(), (t,)) 
#dpsi/dz = deriv(u[1], (1,), Diferences(), (z,)) 

#dphi/dt = deriv(u[2], (1,), Diferences(), (t,))
#dphi/dz = deriv(u[2], (1,), Diferences(), (z,))

#g(y::Real) = [sin(y), cos(y), tan(y)]; # returns a vector
#julia> ForwardDiff.derivative(g, pi/4)

function theta(t1)
    return Base.Math.acot(100*(1-0.5*tanh(0.1*(t1-15))+0.5*Base.tanh(0.1*(t1-125))))
end

function fs(t1)
    return sin(theta(t1))
end

function fc(t1)
    return cos(theta(t1))
end

thetadot = ForwardDiff.derivative(theta,t)

#ForwardDiff.derivative(x -> ForwardDiff.derivative(f, x), 1.0)

sder2 = ForwardDiff.derivative(x -> ForwardDiff.derivative(fs, x), t)
cder2 = ForwardDiff.derivative(x -> ForwardDiff.derivative(fc, x), t)

# Define the PDEs
du[1] = -c*(cos(theta(t)))^2 * deriv(u[1], (1,), Diferences(), (z,)) - thetadot*u[2] - c*sin(theta(t))*cos(theta(t))*deriv(u[2], (1,), Diferences(), (z,))
du[2] = (1/(gamma*tan(theta(t))*cos(theta(t))))*(-g^2*N*u[2]*1/sin(theta(t))
         +((sec(theta(t)))^2*thetadot)*(-thetadot*cos(theta(t))*u[1]+sin(theta(t))*deriv(u[1], (1,), Diferences(), (t,)))
         -((sec(theta(t)))^2*thetadot)*(-thetadot*sin(theta(t))*u[2]+cos(theta(t))*deriv(u[2], (1,), Diferences(), (t,)))
         +tan(theta(t))*sder2*u[1]+tan(theta(t))*sin(theta(t))*deriv(u[1], (2,), Diferences(), (t,)) 
         -tan(theta(t))*cder2*u[2]-tan(theta(t))*cos(theta(t))*deriv(u[2], (2,), Diferences(), (t,)) 
         +gamma*tan(theta(t))*cos(theta(t))*thetadot*u[1]+gamma*tan(theta(t))*sin(theta(t))*deriv(u[1], (1,), Diferences(), (t,)) 
         +gamma*tan(theta(t))*sin(theta(t))*thetadot*u[2])

return du

```

end

# Define initial conditions

u0 = [x → e(-x^2/2), x → cos(π\*x)]

# Define parameters

#p = [1.0, 200, 1.0, 4.0]

# Define the range of independent variables

xspan = (0.0, 10.0)

prob = PDEProblem(coupled\_pdes, u0, xspan)

# Solve the problem

sol = solve(prob)

# Access the solution

u = sol.u[5] # Get the solution at the final time

the error I get is: type PDEProblem has no field u0

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 4, 2024, 10:45am UTC](https://discourse.julialang.org/t/coupled-pde-solver/113636/2 "2024-05-04T10:45:16Z")

</div>

I’m not entirely sure what you’re trying to do here. Is this code generated by ChatGPT? `PDEProblem` is not exposed as a documented thing, and the function here should be an ODE?
