Could fsolve cause trouble when using it to solve linear equations?
이전 댓글 표시
Hello,
I have used fsolve optimisation algorithm to solve linear integral equations using integral command. But I know fsolve works for non-linear equations. So can I use it to solve linear equation system? Thanks
채택된 답변
추가 답변 (1개)
John D'Errico
2015년 4월 4일
2 개 추천
Think of it like this. Fsolve CAN solve a linear system of equations, but do you want to use the wrong tool for the job? In general, many tools can solve problems they are not really targeted to solve. But for a linear system, use a tool designed to solve that particular problem VERY well and efficiently.
A nonlinear solver will assume that you have a nonlinear problem. That means it will need starting values. It will need convergence tolerances. Fsolve will first need to compute the derivatives of what it thinks are nonlinear equations. (Or you will need to supply them.) So all of this makes fsolve less efficient for the problem than it need be.
After all, while I can probably drive in a nail by banging it with a screwdriver, a hammer will do so much better. And I suppose I could find a way to drive a screw with a hammer, but a screwdriver will be the right tool for the job.
So instead, just use backslash (or linsolve, or pinv, etc.) to solve linear problems. These tools are designed to be quite efficient and accurate on linear problems.
댓글 수: 3
Mohammad Abouali
2015년 4월 4일
agree. People do all sort of tricks to keep the model to a linear system as long as it doesn't invalidate the results and it is possible. Here, we do have a linear system to begin with, why should we use fsolve which is for non-linear systems anyway!?
gautam vatsa
2021년 12월 10일
Hi I have a similar difficulty. I totally admit your points - why at all should we use fsolve for solving linear problems. The issue in my case is that the my linear equations arrive after discretizing my partial differential equations (which are although linear but very complicated - coupled and 4th order). So for me it is much easier to form a function handle than to create the matrix vector form. Can you suggest some linear equation solver that admits function handle (consisting of set of linear equations in variables) just like fsolve does.
The function equationToMatrix requires me to represent my variables in symbolic variables, however I have too many variables and therefore, using symbolic variables makes my codes run too slow. Please suggest something.
Torsten
2021년 12월 10일
If your equations are linear in the vector x of unknowns, use the function handle to calculate the Jacobian of your system (with Jacobianest, e.g.) (Result is A) and evaluate your function handle with all variables set to 0 (Result is b).
Then your linear system to solve reads
A*x = -b
such that
x = A\(-b).
카테고리
도움말 센터 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!