问题描述
我正在尝试用3个变量和5个常数解决MATLAB中的方程组.是否可以通过solve求解三个变量,同时保持常量为符号常量而不用数值代替它们?
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?
推荐答案
使用解决函数(来自符号工具箱)您可以指定要求解的变量.例如,假设您有三个方程式,它们的变量分别为x
,y
和z
,常数为a
和b
.下面将为您提供一个结构S
,其中的字段'x'
,'y'
和'z'
包含这些变量的符号方程,其中包括常数a
和b
:
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.
这篇关于使用符号求解器仅求解某些变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!