# Newbie question, how to solve this simple ODE with ff++?

**URL:** <https://community.freefem.org/t/newbie-question-how-to-solve-this-simple-ode-with-ff/3786>\
**Category:** General Discussion\
**Created:** [February 28, 2025, 4:51pm UTC](https://community.freefem.org/t/newbie-question-how-to-solve-this-simple-ode-with-ff/3786 "2025-02-28T16:51:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldoldman](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/oldoldman/32/2725_2.png) [@oldoldman](https://community.freefem.org/u/oldoldman)\
**Post date:** [February 28, 2025, 4:51pm UTC](https://community.freefem.org/t/newbie-question-how-to-solve-this-simple-ode-with-ff/3786/1 "2025-02-28T16:51:34Z")

</div>

Hi guys,  
I’m trying to solve this ODE

```auto
u''=6x
u(0)=0

```

with following script

```c++
/*
u''=6x
u(0)=0
*/
border b(i=0,1) {
  x=i;
  y=0;
}
meshL Sh=buildmeshL(b(50));
fespace Vh(Sh,P1);

Vh u,v;
func f = 6*x;
func real ue(int i) {
  if(i==0)
    return 0;
  return x;
}
int i=0;
func ue2 = ue(i++);

solve p(u,v,solver=CG)=int1d(Sh)(dx(u)*dx(v))-int1d(Sh)(f*v)+on(0,1,2,u=ue2);

plot(u,wait=true,value=true,fill=true);
for(int i=0;i<u[].n;i++) {
  cout << u[][i] << "\n";
}

```

I konw its analytic solution is x^3, but when I plot the numeric solution, I found they does not match. What’s wrong with my script? many thanks!

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/d0d4d79281bad2be83dcca8c8e454db043f3f07a.png)

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [February 28, 2025, 6:53pm UTC](https://community.freefem.org/t/newbie-question-how-to-solve-this-simple-ode-with-ff/3786/2 "2025-02-28T18:53:45Z")

</div>

Hello, you can do as

```auto
/*
u''=6x
u(0)=0
u(1)=1
*/
border b(i=0,1) {
  x=i;
  y=0;
  label=i+1;
}
meshL Sh=buildmeshL(b(50));
fespace Vh(Sh,P1);

Vh u,v;
func f = -6*x;
// solve -u''=f

solve p(u,v,solver=CG)=int1d(Sh)(dx(u)*dx(v))-int1d(Sh)(f*v)+on(1,u=0.)+on(2,u=1.);

//plot(u,wait=true,value=true,fill=true);
//for(int i=0;i<u[].n;i++) {
// cout << u[][i] << "\n";
//}
real error=sqrt(int1d(Sh)((u-x^3)^2));
cout << "error=" << error << endl;

```

---

<div class="post-metadata">

**Author:** ![oldoldman](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/oldoldman/32/2725_2.png) [@oldoldman](https://community.freefem.org/u/oldoldman)\
**Post date:** [March 1, 2025, 1:45am UTC](https://community.freefem.org/t/newbie-question-how-to-solve-this-simple-ode-with-ff/3786/3 "2025-03-01T01:45:08Z")

</div>

Many thanks! I’ve learned a lot from your solution!
