solve a set of two linear equations

조회 수: 5 (최근 30일)
mary
mary 2021년 10월 1일
편집: Alan Weiss 2021년 10월 3일
Hello,
I have a set of two linear equations. I know how to solve it on paper. The only issue is how to make a well-structured code for it by using function handels (so without using symolic variables). Let's consider the following example:
f1 = @(x,y) y - x - a(x) - b(y) + cst1 ;
f2 = @(x,y) y - x - c(x) - d(y) + cst2 ;
a and c are functions of x, b and d functions of y, cst 1 and cst 2 are constants.
Thanks in advance for your help.

답변 (2개)

Steven Lord
Steven Lord 2021년 10월 1일
If this isn't a homework assignment, use fsolve from Optimization Toolbox.
If this is a homework assignment, check your textbook to see if there is an algorithm and/or pseudocode that you can implement as MATLAB code. If there is but you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
  댓글 수: 1
mary
mary 2021년 10월 1일
No, it is not a homework and I am familiar with Matlab. The only problem is that I dont see how to use fsolve with function handels (f1 = @(x,y) ... and f2 = @(x,y) ...). Here: https://nl.mathworks.com/help/optim/ug/fsolve.html, for instance F1 and F2 are not function handles. I want to use function handle for the sake of clarity of the code (as each equation includes many terms depending on x and y like a(x) or b(y) in the above example). I dont want to use symbolic parameters neither. Is there any way to use fsolve with my f1(x,y) and f2(x,y) ?

댓글을 달려면 로그인하십시오.


Alan Weiss
Alan Weiss 2021년 10월 3일
편집: Alan Weiss 2021년 10월 3일
I don't really understand what you are trying to do, but it sounds to me like your best bet is to use the Problem-Based Optimization Workflow or more specifically the Problem-Based Workflow for Solving Equations. You can write your optimization variables with perfect clarity, and your will get the same underlying solver (fsolve) if it is appropriate.
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by