ODE - what exactly does Jacobian matrix do

Hi:
I have a gnereal question regarding to the Jacobian matrix when solving the ODE. I don't know why the Jacobina matrix needs to be provided? And could you explain how does Matlab use it to improve the efficiency for sovling ODE?
Is it better to provide the Jacobian matrix for both the stiff and non-stiff system of ODE?
Thanks,

 Accepted Answer

Jacobian is an equivalent of a gradient vector for a vector-valued function. In an oversimplified way, you can think of it in the same way as the derivative of a scalar function.
You don't need to specify the Jacobian matrix for ODE functions in MATLAB explicitly. However, providing it will increase the speed because otherwise, the MATLAB will have to estimate the Jacobian matrix using finite difference, which essentially involves nudging each variable a little bit and estimating its effect on the output vector. If you explicitly provide it, then MATLAB does not have to go through all that nudging.

9 Comments

Hi,
Would you mind helping me to understand how the boundary jacobian matrix is calculated (Jy(a) and Jy(b))? I couldn't figure it out.
Please check the attachment.
Many thanks.
Chao, I found that you mentioned this example from here: https://www.mathworks.com/help/matlab/math/solve-bvp-using-continuation.html
Since we have the boundary conditions
So he matrices and are defined as
Similarly you can write the expression for and after putting the values, you will get the matrices as given in the example.
Got it. Many thanks!
Hi Ameer:
I have another question and hope you don't mind helping me to explain. I am reading the document '
Solve BVP with Multiple Boundary Conditions
'
The bouddary condition is
v(0)=0,
C(λ)=1.
However, I don't quite understnad the intial guess.
It says 'A simple guess that satisfies the boundary conditions is the constant guess y = [1; 1].'.
My question is why the constant guess y is not set as y = [0, 1] instead? From my understanding, [0, 1] is the one satisying the given boundary conditions instead.
Thanks,
Chao
Chao, I think you are under the impression that [1 1] defines the initial guess at two end-points. But if you look at the output of the following, you will see how the initial guess is calculated from [1 1]
xc = 1;
xmesh = [0 0.25 0.5 0.75 xc xc 1.25 1.5 1.75 2];
yinit = [1; 1];
sol = bvpinit(xmesh,yinit);
sol.y
ans =
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
The vector [1 1] is use to specify the initial guess for both variables, v and C, on their entire range, not just end-point. Instead of [1 1], you can also input a vector of dimension size(xmesh,2)*2. The first row of initial guess corresponds to the first variable (i.e., v) and second row is for the second variable (C).
The initial guess does not need to satisfy the boundary conditions. It is just an initial guess, you can give whatever value you want. The solver will just use that initial point to get toward the final solution.
Hi Ameer,
Thanks for taking time to answer my question and I really appreciate your great help.
However, the 'whatever value' part of the initial guess still confuses me. According to the guideline of creating a good initial guess as below, it's better to have the intial guess satisfy the boudary conditions (bullet 1). Also, I understand [1 1] is used to specify the intiial guess for both varaibles. I just don't see why first term isn't set as 0 instead to satisfy v(0) = 0, which makes the initial guess as [0, 1], though I am aware both initial guess give the same solutions. However, I don't get how does '1' in first term come from in initial guess [1,1] and why '1' is used. This also makes sol.y(1,:) as all 1s and doesn't satisfy the condition v(0) = 0. Would you mind eplaining this in more detials? Also, when saying 'you can give whaterever value you want' for initial guess, is it always true?
Thanks, and looking forward to the answers.
Chao, It is correct a good initial guess is necessary for the quick convergence performance of the bvp4c() function; however, following the boundary condition is a guideline, not a pre-requisite. A close enough value for initial guess is enough as a starting point for solving a BVP. For simple problems, even a rough initial guess can work. Additionally, this page, https://www.mathworks.com/help/matlab/math/solve-bvp-with-multiple-boundary-conditions.html, also mentions that "For multipoint BVPs, the boundary conditions are automatically applied at the beginning and end of the interval of integration," so internally the solution might always enforce the constraint at the end-point despite the initial guess.
You can also think of it in this way. In the case of this problem, there are actually 4 boundary conditions. The initial guess [0;1] will only satisfy 2 of these conditions. Whereas, the initial guess [1;1] satisfy three of these conditions. Besides, the MATLAB might enforce the boundary constraint internally, as already stated.
Ameer, thanks so much. This really clear things up. Really appreciate your time and great help!
Glad to be of help.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!