小编Kam*_*mil的帖子

方程组.如何拆分字符串以获得R中的两个矩阵A和b

我有一个像这样的字符串(变量和常量的数量并不重要):

> my_string <- "-x+2y+z=-1; x-3y-2z=-1; 3x-y-z=4"
Run Code Online (Sandbox Code Playgroud)

我知道如何cbind(A, b)使用替换和数字函数获取矩阵...

#    [,1]   [,2]   [,3]    [,4]
# [1,] -1     2      1      -1
# [2,]  1    -3     -2      -1
# [3,]  3    -1     -1       4
Run Code Online (Sandbox Code Playgroud)

......但不知道如何自动获得两个矩阵Ab

A
#    [,1]   [,2]   [,3]
# [1,]-1     2      1
# [2,] 1    -3     -2 
# [3,] 3    -1     -1  

b
#    [,1]   
# [1,]-1
# [2,]-1
# [3,] 4 
Run Code Online (Sandbox Code Playgroud)

这意味着我如何分割这个字符串=以获得一个矩阵,其中数字元素位于等号前面,另一个矩阵元素位于它之后?

编辑.到目前为止我做了这个:

my_string<-"-x+2y+z=-1; x-3y-2z=-1; 3x-y-z=4"    
my_string<-gsub('([[:punct:]]|\\s)([a-z])', '\\11\\2', my_string)   
my_string<-stringr::str_replace_all(my_string,"[a-z]"," ")    
my_string<-stringr::str_replace_all(my_string,"; …
Run Code Online (Sandbox Code Playgroud)

regex r

3
推荐指数
1
解决办法
158
查看次数

使用“个案”在大括号(R-markdown)中显示线性方程式的系统

我如何自动显示这样的字符串:

zad <-“ 2x + 5y-2z + 2p = 9; 3x-2y + 1z-3p = 34; -3x + 3y + 2z + 4p = 33; 2x + 3y + 4z + 5p = 125”

作为花括号中的一组线性方程式(在R-markdown中)?如图所示,但在更改zad字符串后,它应该会自动工作: lin_eq

latex r r-markdown

1
推荐指数
1
解决办法
3994
查看次数

标签 统计

r ×2

latex ×1

r-markdown ×1

regex ×1