File Exchange

image thumbnail

Tutorial on solving BVPs with BVP4C

version (197 KB) by Jacek Kierzenka
Solving boundary value problems with BVP4C. Tutorial + Examples.


Updated 01 Sep 2016

View Version History

View License

This tutorial shows how to formulate, solve, and plot the solutions of boundary value problems (BVPs) for ordinary differential equations.
The tutorial introduces the function BVP4C (available in MATLAB 6.0 and later), briefly describes the numerical method used, and illustrates solving BVPs with several examples and exercises.

The M-files for all the examples and exercises in the tutorial are available in the directory BVP_examples.

The directory BVP_examples_65 contains the files for the examples and exercises, updated to take advantage of features available in MATLAB 6.5 (R13).
Correspondingly, BVP_examples_70 contains files modified for use with MATLAB 7.0 (R14).

More information about solving BVPs in MATLAB, can be found in the paper

Jacek Kierzenka, Lawrence F. Shampine,
A BVP Solver based on Residual Control and the MATLAB PSE,
ACM TOMS, Vol. 27 (2001), No. 3, pp. 299-316.

or in the book

L.F. Shampine, I. Gladwell, and S. Thompson,
Solving ODEs with MATLAB, Cambridge University Press, 2003.

Cite As

Jacek Kierzenka (2021). Tutorial on solving BVPs with BVP4C (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (67)

Jingyu Jiang

can this method be used to solve BVPs with integration in ODEs?

Yin Zhang

Sergei Dodzin

Alex Sabrekov

Thank you, this tutorial is very useful.

Zeming Wu



c j

Matteo Melai

Xingkong Wei

raghuveer manikanta

Tarique Shaikh

Jiafu Liu

Ahsan Ahsan

rohith reddy

amin nikravesh

I have an example for using bvp4c
consider we will solve a bvp problem like this
Matlab code:
dydt=@(x,y)[y(2); -6*y(2)+x];
bc=@(ya,yb)[ya(1)+1; yb(1)-4];
yinit=@(x)[exp(-x); -exp(-x)];
% "sol" callback you three part:x,y,y'

Faqiha Sultan

These tutorials are excellent, but I still need help in solving a system of coupled differential equations using bvp4c.Ref. (ex8bvp)

f(0)=0, f'(0)=0,g(0)=1,h(0)=1,f'(infinity)=0,g(infinity)=0, h(infinity)=0

Luan Trinh

Could anyone help me solve this problem:
Equation : d2y/dx2 + y = f(x)
Restrains: y(a) = m; y(b) = n.

Thank you so much for your help.


How do I actually watch this file? Website is taking me in circles.


Why in the example 8 they can have more boundary conditions than equations?. I want to do something similar; solve a system of two equations with 4 boundary conditions, but matlab only let me put 2 boundary conditions.



Adel Ahmadyan

There is a bug in example 4, which cause it to not follow the boundary values,
the correct res. function should be:
res = [ ya(1)
(ya(2)-yb(2)) ];
which is not dependent on T, instead of
res = [ya(1) - yb(1)
ya(2) - yb(2)
T*(-1/3)*(ya(1) - 0.7 + 0.8*ya(2)) - 1];

Nayyar Mehmood

Its good for beginners


I can't understand how can I chose the right guess... and for examples the two guesses in example 1. Can somebody help me?

Ali MalekpourKoupaei

I was wondering to solve:


but I could not use the tutorial,

sandeep reddy n

Nayyar Mehmood

downloading problem


bvp4c is really helpful in bvps. I have a question,
to solve a bvp like
d^y/dx^2 + y=0 where y and x are both vectors how can I modify the code?

Elif Hocaoglu

helpful, thx

Dr. Rajeev Shrivastava


with ode45 solving initial value problems I have no problem,but to use bvp4c I have some problem,most of time I receive the message,
??? Error using ==> bvp4c
Unable to solve the collocation equations --
a singular Jacobian encountered.I try to change initial guess but I'm reiceving the same message.bvp4c need to be improved in order to help user strigling to solve two-point boundary value problems.

sharareh Bayat

Hello, I want to solve 24 diffrential equations in matlab using BVP4C but it says singular jacobian . could you please help me

Muhammad Noaman ul Haq


chaudhari urmila


harvinder kaur

judith p

bhbh ffff

Needs Improvement

Fabricio Nápoles

prakriti trivedi

Valery Naunyka

You strongly help me to solve my numerical problem

wahid ghanem

Mircea-Jean Cristea

John D'Onofrio

Daniel Magohe

I hope people with basic knowledge of pure mathematics will find it quite useful.

Sunil Arya

Its a very good tool fou boundary value problem. One can learn a lot of from this m.code.

Vince Aderangi

It is a very good resource. However, the m files of examples could have more comments. For example, in example 1 it does not explain what is used as initial guess.

mohammed kalil

F.L. Lewis , Optimal Estimation , NY John Wiley & Sons, 1986

Nikolaos Tubanos

Francesco Sarnari

abdullah al-khudhiri

Leonardo Molisani

Troy Eastin

lisa jam


I am working on CFD(non-Newtonian). The tutorial by Dr.Jacek helped me a lot to improve my skills.

Leo Trav

kong dong

Mr.Kierzenka,thanks a lot.The tutorial is very useful.

Matjaz Licer

Helped me a whole lot!! - from zero knowledge of Matlab to calculation of the polyelectrolyte density distributions in colloid crystals (involving nonlinear coupled systems of BVP's) in 3 weeks! Without bvp4c and this tutorial, i'd be torturing Fortran, c++ and myself as we speak.

dhilip kumar ramalingam

David Brooks

Summarize everything you need to know

Volkan Çark

perfect to learn.

w a

Mao Wei


raavi kumar

i ned matlab r14, because i will do the project with the the help of this software

kalbin salim

Spyridon Gerontas

khaled khalaf

chi ho

much helpful to begineers

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!