首页 > 其他分享 >2.7

2.7

时间:2024-10-21 20:59:32浏览次数:1  
标签:linalg least print rank np squares 2.7

import numpy as np

A = np.array([[4, 2, -1], [3, -1, 2], [11, 3, 0]])
b = np.array([2, 10, 8])
x = np.linalg.lstsq(A, b)
if np.linalg.matrix_rank(A) == np.linalg.matrix_rank(np.column_stack((A, b))):
if np.linalg.matrix_rank(A) == A.shape[1]:
print("线性方程组有唯一解")
x_unique = np.linalg.solve(A, b)
print("唯一解 x =", x_unique)
else:
print("线性方程组有无穷多解")
x_least_squares = np.linalg.lstsq(A, b, rcond=None)[0]
print("最小二乘解 x =", x_least_squares)
else:
print("线性方程组无解")
x_least_squares = np.linalg.lstsq(A, b, rcond=None)[0]
print("最小二乘解 x =", x_least_squares)
x_min_norm = np.linalg.pinv(A).dot(b)
print("最小范数解 x =", x_min_norm)

A = np.array([[2, 3, 1], [1, -2, 4], [3, 8, -2],[4,-1,9]])
b = np.array([4, -5, 13,-6])

x = np.linalg.lstsq(A, b)

if np.linalg.matrix_rank(A) == np.linalg.matrix_rank(np.column_stack((A, b))):
if np.linalg.matrix_rank(A) == A.shape[1]:
print("线性方程组有唯一解")
x_unique = np.linalg.solve(A, b)
print("唯一解 x =", x_unique)
else:
print("线性方程组有无穷多解")
x_least_squares = np.linalg.lstsq(A, b, rcond=None)[0]
print("最小二乘解 x =", x_least_squares)
else:
print("线性方程组无解")
x_least_squares = np.linalg.lstsq(A, b, rcond=None)[0]
print("最小二乘解 x =", x_least_squares)
x_min_norm = np.linalg.pinv(A).dot(b)
print("最小范数解 x =", x_min_norm)

标签:linalg,least,print,rank,np,squares,2.7
From: https://www.cnblogs.com/Lntano/p/18490387

相关文章

  • SpringBoot 2.3 升级到 SpringBoot 2.7 爬坑-- SpringDoc & Swagger
    注意:Swagger支持SpringBoot2.0但不支持SpringBoot3.0OpenApiOpenApi是一个用于描述、定义和共享RESTfulAPI文档的规范。最新规范是OpenAPI3.0SwaggerSwagger是一个用于设计和测试RESTfulAPIs的工具。它提供了API描述、请求和响应示例、API测试和文档生成等丰富的......
  • SpringBoot 2.3 升级到 SpringBoot 2.7 爬坑-- Cors 跨域
    WhenallowCredentialsistrue,allowedOriginscannotcontainthespecialvalue"*"sincethatcannotbesetonthe"Access-Control-Allow-Origin"responseheader.Toallowcredentialstoasetoforigins,listthemexplicitlyorconside......
  • SpringBoot 2.7.18 集成 Mybatis Plus + Druid
    目录Pom依赖yml配置Config配置Mapper扫描EntityMapper.xmlMapper-SysMenuMapperServiceController一并附上Mybatis和MybatisPlus的使用区别MyBatisMapper.XML标签使用说明Pom依赖Mybatis<!--统一管理jar包版本--><properties><druid-boot.version>1.......
  • VMware Fusion 13.6.1 OEM BIOS 2.7 - 在 macOS 中运行 Windows 虚拟机的最佳方式
    VMwareFusion13.6.1OEMBIOS2.7-在macOS中运行Windows虚拟机的最佳方式VMwareFusion13原版App中集成OEMBIOS请访问原文链接:https://sysin.org/blog/vmware-fusion-13-oem/查看最新版。原创作品,转载请保留出处。作者主页:sysin.org2024-10-11,版本13.6.1例......
  • SpringBoot 2.3 升级到 SpringBoot 2.7 爬坑-- Swagger 3
    SpringBoot2.3升级到SpringBoot2.7爬坑--Swagger报错需要升级到3Failedtostartbean'documentationPluginsBootstrapper';nestedexceptionisjava.lang.NullPointerException<!--swagger2--><dependency><groupId>io.springfox......
  • Ubuntu 16.04 编译安装Python 2.7.18
    安装python2.7.18(注)使用aptinstallpython安装的版本是2.7.10,该版本对部分项目存在兼容性问题,因此需要手动编译安装安装python编译环境sudoaptinstallpython-devpkg-configlibreadline-devlibc6-devlibncursesw5-devbuild-essentialgdbpkg-configlibbz2-devlibffi-......
  • Project ‘org.springframework.boot:spring-boot-starter-parent:2.7.7’ not found
    原文链接:Project‘org.springframework.boot:spring-boot-starter-parent:2.7.7’notfound–每天进步一点点(longkui.site)某日构建springboot项目,构建完毕以后发现下面这样然后打开pom文件,发现springboot的依赖爆红(这个版本号是随便举例)我去本地仓库看了看,有这个依赖,......
  • 习题2.7(2)
    importnumpyasnp#定义系数矩阵A和常数项向量bA=np.array([[2,3,1],[1,-2,4],[3,8,-2],[4,-1,9]])b=np.array([4,-5,13,-6])#使用numpy的lstsq函数求解最小二乘解#对于这个特定的问......
  • 数学建模习题2.7
    importnumpyasnp定义系数矩阵A和常数项向量bA=np.array([[4,2,-1],[3,-1,2],[11,3,0]])b=np.array([2,10,8])使用numpy的lstsq求解最小二乘解x,residuals,rank,s=np.linalg.lstsq(A,b,rcond=None)print("最小二乘解为:")print(x)打印残差和矩阵A的......
  • VMware ESXi 7.0U3q macOS Unlocker & OEM BIOS 2.7 Dell HPE 联想定制版 9 月更新发
    VMwareESXi7.0U3qmacOSUnlocker&OEMBIOS2.7标准版和厂商定制版ESXi7.0U3标准版,Dell(戴尔)、HPE(慧与)、Lenovo(联想)、Inspur(浪潮)、Cisco(思科)、Fujitsu(富士通)、Hitachi(日立)、NEC(日电)OEM定制版请访问原文链接:https://sysin.org/blog/vmware-esxi-......