Solve only for specific 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 resolve for three variables with a solution, saving the constants as symbolic and not replacing them with numeric values?

+3
source share
1 answer

When you use the SOLVE function (from the Symbolic Toolbox ) you can specify the variables you want to solve. For example, suppose you have three equations with variables x, yand zand constants aand b. The following will give you a structure Swith fields 'x', 'y'and 'z'containing symbolic equations for these variables, which include constants aand 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 cannot be found for the system of equations, numerical solutions will be returned instead.

+4
source

Source: https://habr.com/ru/post/1762377/


All Articles