Hi,
I understand that you are trying to solve a boundary value problem (BVP) for a second-order ordinary differential equation (ODE) using a numerical method implemented in MATLAB, and you are encountering issues with the computation taking an infinite amount of time, particularly with the calculation of the Jacobian matrix J(l,k+1).
From the code, it seems you are using some form of collocation method with an iterative Newton-Raphson approach to solve the nonlinear system of equations. The code constructs a Jacobian matrix "J" and a residual vector "phi" to find the corrections "delta" to the approximate solution "u".
As per my understanding, the variable "deltanew" contains the next value of "delta" and you want to upgrade it with every iteration of "while" loop in the "ex_collNL" function. The value of "deltanew" in turn depends on the Jacobian matrix "J" and vector "phi". However, note that the value of "delta" is nowhere updated in the while loop. It is just initialized once in "ex_collNL" function and the same "delta" is used in every iteration while updating the matrix "J" and vector "phi". Kindly observe the snapshot of the respective code lines as follows for a better understanding :
Now, because of the above mentioned reason, the values of "J" and "phi" are not updated correctly and hence the variable "deltanew" is also not converging, leading to an infinite "while" loop. I will recommend to make the necessary changes in the code such that the value of variable "delta" inside the loop is also updated.
One way to do that is to store the initial value of the variable "delta" in another variable, say "deltaold" and then update the value of delta with a new value in every iteration as shown below:
I am getting the following output after making the above changes and the code runs within a few seconds.
I hope it resolves your query.
Best Regards
Zuber