Solve for only certain variables with symbolic solver

怎甘沉沦 提交于 2019-12-10 18:01:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3605071/solve-for-only-certain-variables-with-symbolic-solver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!