Math 方程线性代数

Math 方程线性代数,math,tcl,Math,Tcl,我需要解这个方程并找到t: 4x + z − 2 = 0 带参数: x =− 1 − 2t z = 1 + t 结果: 4(− 1 − 2t) + (1 + t) − 2 = 0 t = − 5/7 我如何将我的t值分组到这个等式中?我们可以将等式重写为术语列表吗 set terms {4x 1z -2} set x {-1 -2t} set z {1 1t} 如果我们有一个命令将项拆分为系数和变量部分(如果项是常量,则变量部分为空字符串) 一个命令,用于将术语列表与一个因子相乘 pro

我需要解这个方程并找到
t

4x + z − 2 = 0
带参数:

x =− 1 − 2t
z = 1 + t
结果:

4(− 1 − 2t) + (1 + t) − 2 = 0
t = − 5/7

我如何将我的
t
值分组到这个等式中?

我们可以将等式重写为术语列表吗

set terms {4x 1z -2}
set x {-1 -2t}
set z {1 1t}
如果我们有一个命令将项拆分为系数和变量部分(如果项是常量,则变量部分为空字符串)

一个命令,用于将术语列表与一个因子相乘

proc multiplyTerms {factor terms} {
    lmap term $terms {
        lassign [splitTerm $term] c v
        format %d%s [expr {$factor * $c}] $v
    }
}
一个命令用于添加项并获得常量项的一个和,另一个命令用于带有变量的项(在此阶段,由于替换,假设变量为一个且相同)

最后是一个用变量替换术语的命令,这些变量包含术语列表

proc replaceTerms terms {
    concat {*}[lmap term $terms {
        lassign [splitTerm $term] c v
        if {$v eq {}} {
            set c
        } else {
            multiplyTerms $c [set ::$v]
        }
    }]
}
然后我们可以替换原始术语列表中的变量

% set replaced [replaceTerms $terms]
-4 -8t 1 1t -2
并总结如下:

% set result [addTerms $squashed]
-5 -7
这对应于方程
-7t-5=0
,该方程产生了解
t=-5/7

文件: , , , , , , , , , , , , , , ,

我们能把方程改写成术语列表吗

set terms {4x 1z -2}
set x {-1 -2t}
set z {1 1t}
如果我们有一个命令将项拆分为系数和变量部分(如果项是常量,则变量部分为空字符串)

一个命令,用于将术语列表与一个因子相乘

proc multiplyTerms {factor terms} {
    lmap term $terms {
        lassign [splitTerm $term] c v
        format %d%s [expr {$factor * $c}] $v
    }
}
一个命令用于添加项并获得常量项的一个和,另一个命令用于带有变量的项(在此阶段,由于替换,假设变量为一个且相同)

最后是一个用变量替换术语的命令,这些变量包含术语列表

proc replaceTerms terms {
    concat {*}[lmap term $terms {
        lassign [splitTerm $term] c v
        if {$v eq {}} {
            set c
        } else {
            multiplyTerms $c [set ::$v]
        }
    }]
}
然后我们可以替换原始术语列表中的变量

% set replaced [replaceTerms $terms]
-4 -8t 1 1t -2
并总结如下:

% set result [addTerms $squashed]
-5 -7
这对应于方程
-7t-5=0
,该方程产生了解
t=-5/7

文件: , , , , , , , , , , , , , , ,

看看这里的答案:谢谢Peter,我在发帖前没有看到这个帖子,我尝试过但失败了,我将尝试使用regexp捕获并乘以我不知道的每个值??看看这里的答案:谢谢Peter,我在发帖前没有看到这个帖子,我尝试过但失败了,我将尝试使用regexp来捕获和乘以我不知道的每个值??谢谢你,彼得,我很期待你的解决方案,我的想法是使用regexp。可惜tcl不知名,我希望她能给你很多选票。。。谢谢你,彼得,我很想知道你的解决方案,我的想法是使用regexp。可惜tcl不知名,我希望她能给你很多选票。。。谢谢