用Matlab查找线性方程组的完整和符号解 [英] Find complete and symbolic solutions to system of linear equations by Matlab

查看:97
本文介绍了用Matlab查找线性方程组的完整和符号解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有2个线性方程和3个变量.该解决方案至少是一维的.我希望Matlab通过根据另一个自由变量编写两个变量x1,x2,x3来找到所有解决方案.这可能吗?看来Matlab总是给我一个数值解.

Suppose I have 2 linear equations and 3 variables. The solution is at least one-dimensional. I want Matlab to find all solutions by writing two of the variables x1, x2, x3 in terms of the other one free variable. Is this possible? It seems that Matlab always gives me one numerical solution.

在Mathematica中,解决"功能始终返回包含所有解决方案的符号解决方案.但是我发现Matlab只是给我一个数值解,不是很有帮助.

In Mathematica, the "solve" function always returns a symbolic solution, which contains all solutions. But I found Matlab just gives me one numerical solution, which is not very helpful.

推荐答案

首先,定义要使用的符号变量:

First you define symbolic variables that you're gonna be using:

syms x y z;

然后定义每个方程式.如果您具有以矩阵形式给出的线性系统,请使用for循环创建方程.

Then define each of the equations. If you have linear system given in matrix form, create equation with for loop.

eqns = [x + y + z == 1, x + 2*y + 3*z == 2];

定义变量:

vars = [x, y, z];

最后,将ReturnConditions设置为true,并用solve解决.这样,求解器就可以返回所有可能的解决方案.

Finally, solve it with solve with setting ReturnConditions to true. That way solver with return all possible solutions.

[solx, soly, solz, param, conds] = solve(eqns, vars, 'ReturnConditions', true);

上面的示例提供了以下解决方案:

Which gives following solutions for the example above:

solx =

z1

soly =

1 - 2*z1

solz =

z1

param =

z1

这篇关于用Matlab查找线性方程组的完整和符号解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆