Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solve for only certain variables with symbolic solver

I am trying to solve a system of equations in MATLAB with 3 variables and 5 constants. Is it possible to solve for the three variables with solve while keeping the constants as symbolic and not replacing them with numerical values?

like image 634
Brian Avatar asked Nov 24 '25 16:11

Brian


1 Answers

When you use the SOLVE function (from the Symbolic Toolbox) you can specify the variables you want to solve for. For example, let's say you have three equations with variables x, y, and z and constants a and b. The following will give you a structure S with fields 'x', 'y', and 'z' containing symbolic equations for those variables which include the constants a and b:

>> S = solve('x+y=a','x-y=b','z=x^2+y^2','x','y','z');  %# Solve for x, y, and z
>> [S.x; S.y; S.z]  %# Get the equations from the structure

ans =

     a/2 + b/2  %# Equation for x
     a/2 - b/2  %# Equation for y
 a^2/2 + b^2/2  %# Equation for z

If symbolic solutions can't be found for a system of equations, numeric solutions will be returned instead.

like image 199
gnovice Avatar answered Nov 28 '25 06:11

gnovice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!