简体   繁体   中英

Matlab: Solving Symbolic System of Linear Equations with Interpolation functions

I've been trying to solve a system of linear equations, with some variables being interpolated functions of other variables. I've tried turning these functions into symbolic functions, but that doesn't seem to work. Does anybody have a workaround that doesn't involve curve-fitting the data ? I would really like to keep my original dataset for accuracy. My dataset is too large to put the real one in this code example, so I've supplied a placeholder dataset of [0 100],[100 0],[0 100;0 100].

Here is my code:

%  Setting up system of equations
syms FD ICE EM GEN
AM = [0 1 1 0 ;
0 1 0 0 ;
0 0 1 0;
0 0 0 1];

Tvec = [FD;ICE;EM;GEN]

eqs=  AM * Tvec  ==   Tvec %System of symbolic equations

% Adding the givens to my system of equations
eqs(5) = FD==1;
eqs(6) = ICE==4;
eqs(7) = interp2([0 100],[100 0],[0 100;0 100], ICE,EM)  % <-- this is where the problem is.  

results=solve(eqs)

I don't know if your system is just an example, but it can be solved trivially by inspection without the use of solve . You might try writing out what it represents on paper or doing just this:

syms FD ICE EM GEN
AM = [0 1 1 0
      0 1 0 0
      0 0 1 0
      0 0 0 1];
Tvec = [FD;ICE;EM;GEN]
eqs =  AM*Tvec == Tvec

returns

eqs =

EM + ICE == FD
    ICE == ICE
      EM == EM
    GEN == GEN

The last three equations should look pretty silly to you as they provide no information. You specified in your fifth and sixth equations that FD == 1 and ICE == 4 . These aren't trivial at least. Indeed, along with your first equation, EM + ICE == FD , you can use them to solve for the fact that EM == -3 .

Next, your seventh equation isn't even an equation as there's no == anywhere. Additionally, as you discovered, interp2 doesn't accept symbolic inputs. This is true of many Matlab functions. Generally, if you don't see sym/thefuncname listed at the bottom when you get help for a function funcname , then that function doesn't have a version for symbolic math (or you can directly search help sym/funcname ). If you want to evaluate the interp2 line, it appears that you have all of the necessary values:

 interp2([0 100],[100 0],[0 100;0 100],4,-3)

which returns NaN indicating that it used extrapolation (see the help/ documentation ).

All in all, I can't figure out what you're trying to do or why you're using interpolation. I'd suggest reading up more on the Symbolic Math toolbox and and figuring out what your problem really is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM