I'm trying to solve a second order nonlinear differential equation by using central difference. In this case, I obtain a system of nonlinear equations where T denotes time. First I create a vector of symbolic variables, by using these variables I create another vector where I put my nonlinear functions, and then by using
matlabFunction
I convert my nonlinear functions into a single function handle. Finally, I try to solve this system by fsolve using the code;
X=ones(N-1,1);options=optimset('disp','iter','LargeScale','off','TolFun',.0001,'MaxIter',1000000000,'MaxFunEvals',1000000000);P=fsolve(f,X,options);
where and f is the function handle I mentioned before. My code is working properly for , and , but when I try to take fsolve runs for a couple of minutes and then stops after giving nowhere near the actual values and this respond:
Equation solved, inaccuracy possible.The vector of function values is near zero, as measured by the selected valueof the function tolerance. However, the last step was ineffective.<stopping criteria details>
I tried to take,
X=zeros(N-1,1);X=rand(N-1,1);X=randn(N-1,1);
as initial values but none of them solve this issue, only
X=rand(N-1,1);
gave better results among the others. I solved this differential equation by another numerical method and by forward difference. In the case where I use forward difference, I used fsolve again and it worked perfectly fine. I also checked the similar discussions, but none of them helped. I'll be grateful for any help. Thanks in advance.
Regards.
Best Answer