solve a set of two linear equations
1 view (last 30 days)
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.
Steven Lord on 1 Oct 2021
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.
Alan Weiss on 3 Oct 2021
Edited: Alan Weiss on 3 Oct 2021
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.
MATLAB mathematical toolbox documentation