矩阵乘法,求解Ax = b求解x

编程入门 行业动态 更新时间:2024-10-23 18:32:33
本文介绍了矩阵乘法,求解Ax = b求解x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,我得到了一项家庭作业,需要解决三次样条曲线的系数.现在,我清楚地了解了如何在纸上以及MatLab上进行数学运算,我想用Python解决问题.给定一个方程Ax = b,我知道A和b的值,我希望能够用Python求解x,而我很难找到一个好的资源来做这样的事情.

So I was given a homework assignment that requires solving the coefficients of cubic splines. Now I clearly understand how to do the math on paper as well as with MatLab, I want to solve the problem with Python. Given an equation Ax = b where I know the values of A and b, I want to be able to solve for x with Python and I am having trouble finding a good resource to do such a thing.

例如.

A = |1 0 0| |1 4 1| |0 0 1| x = Unknown 3x1 matrix b = |0 | |24| |0 |

解决x

推荐答案

在一般情况下,请使用solve:

In a general case, use solve:

>>> import numpy as np >>> from scipy.linalg import solve >>> >>> A = np.random.random((3, 3)) >>> b = np.random.random(3) >>> >>> x = solve(A, b) >>> x array([ 0.98323512, 0.0205734 , 0.06424613]) >>> >>> np.dot(A, x) - b array([ 0., 0., 0.])

如果您的问题是有条带的(通常是三次样条),则有 docs.scipy/doc/scipy/reference/genic/scipy.linalg.solve_banded.html

If your problem is banded (which cubic splines it often are), then there's docs.scipy/doc/scipy/reference/generated/scipy.linalg.solve_banded.html

要对问题的某些评论进行评论:更好的 not 可以使用inv求解线性系统. numpy.lstsq有点不同,它对拟合更有用.

To comment on some of the comments to the question: better not use inv for solving linear systems. numpy.lstsq is a bit different, it's more useful for fitting.

因为这是家庭作业,所以至少在阅读解决三对角线性系统的方法上确实会更好.

As this is homework, you're really better off at least reading up on ways of solving tridiagonal linear systems.

更多推荐

矩阵乘法,求解Ax = b求解x

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

发布评论

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

>www.elefans.com

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