如何在SymPy中求解线性方程组?

编程入门 行业动态 更新时间:2024-10-10 07:30:49
本文介绍了如何在SymPy中求解线性方程组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对不起,我一般对sympy和python还是陌生的.

Sorry, I am pretty new to sympy and python in general.

我想解决以下欠定的线性方程组:

I want to solve the following underdetermined linear system of equations:

x + y + z = 1 x + y + 2z = 3

推荐答案

SymPy最近获得了一个新的线性系统求解器:sympy.solvers.solveset中的linsolve,您可以按以下方式使用它:

SymPy recently got a new Linear system solver: linsolve in sympy.solvers.solveset, you can use that as follows:

In [38]: from sympy import * In [39]: from sympy.solvers.solveset import linsolve In [40]: x, y, z = symbols('x, y, z')

方程列表形式:

In [41]: linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z)) Out[41]: {(-y - 1, y, 2)}

增强矩阵形式:

In [59]: linsolve(Matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x, y, z)) Out[59]: {(-y - 1, y, 2)}

A * x = b表格

In [59]: M = Matrix(((1, 1, 1, 1), (1, 1, 2, 3))) In [60]: system = A, b = M[:, :-1], M[:, -1] In [61]: linsolve(system, x, y, z) Out[61]: {(-y - 1, y, 2)}

注意:解决方案的顺序与给定符号的顺序相对应.

Note: Order of solution corresponds the order of given symbols.

更多推荐

如何在SymPy中求解线性方程组?

本文发布于:2023-11-30 06:13:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   线性方程组   SymPy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!