如何在Matlab中求解符号方程组 [英] How to solve a symbolic system of equations in Matlab

查看:540
本文介绍了如何在Matlab中求解符号方程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这一定是一个愚蠢的错误,但是我真的无法解决这种类型的系统:

I know it has to be a stupid error,but I really can't solve a system of this type:

b =

 a2*cos(q1 + q2) + a1*cos(q1)
 a2*sin(q1 + q2) + a1*sin(q1)
                 d1 + d4 + q3

>> solve(b,[q1,q2,q3,q4])
Warning: The solutions are parametrized by the symbols:
z1 = C_

> In solve at 190 

ans = 

    a1: [1x1 sym]
    d1: [1x1 sym]
    d4: [1x1 sym]
    q1: [1x1 sym]
    q2: [1x1 sym]
    q3: [1x1 sym]
    q4: [1x1 sym]

基本上,我希望我的程序将a1,d1,d4视为参数,并将q1,q2,q3,q4视为变量. 这就是为什么我以这种形式调用resolve(b,[q1,q2,q3,q4])的原因,但是它甚至尝试在我没有放入向量中的符号值中进行求解.

basically I want my program to see a1,d1,d4 as parameters and q1,q2,q3,q4 as variables. that's why I call solve(b,[q1,q2,q3,q4]) in this form,but it tries to solve even in the symbolic values that I haven't put into the vector.

请寻求帮助.

推荐答案

根据的提示solve :

...调用[b,a] = solve(eqns,b,a)分配给a的解和分配给b的b的解.

... the call [b,a] = solve(eqns,b,a) assigns the solutions for a assigned to a and the solutions for b assigned to b.

然而,您可能只想求解b - [e1 e2 e3]' = 0的3个变量(假设q1 q2 q3),却无法求解4个变量,这将是3个方程式和4个没有意义的变量.

However you probably want to solve, b - [e1 e2 e3]' = 0 for only 3 variables (Let's say q1 q2 q3), you can't solve it for 4 variables, that would be 3 equations and 4 variables which does't make sense.

由于我认为这与某些机械系统有关,因此您可能只想求解实际值.您可以执行solve (eqn, 'Real', true)或声明实际值:syms a1 a2 ... real.

Since I think that it is related to some mechanical system you may want to solve for only real values. You can either do this solve (eqn, 'Real', true) or declare real values: syms a1 a2 ... real.

但是,除非在这种情况下使用'IgnoreAnalyticConstraints'选项,否则您仍然无法获得不错的结果:

However you still wouldn't get a pretty result, unless you use the 'IgnoreAnalyticConstraints' option in this case:

syms q1 q2 q3 d1 d4 a1 a2 e1 e2 e3 real

b = [...
    a2*cos(q1 + q2) + a1*cos(q1)
    a2*sin(q1 + q2) + a1*sin(q1)
    d1 + d4 + q3];

res = solve(b-[e1 e2 e3]', q1, q2, q3, 'IgnoreAnalyticConstraints', true);

输出:(简体)

>> simplify(res.q1)

ans =

 2*atan((2*a1*e2 + (- a1^4 + 2*a1^2*a2^2 + 2*a1^2*e1^2 + 2*a1^2*e2^2 - a2^4 + 2*a2^2*e1^2 + 2*a2^2*e2^2 - e1^4 - 2*e1^2*e2^2 - e2^4)^(1/2))/(a1^2 + 2*a1*e1 - a2^2 + e1^2 + e2^2))
 2*atan((2*a1*e2 - (- a1^4 + 2*a1^2*a2^2 + 2*a1^2*e1^2 + 2*a1^2*e2^2 - a2^4 + 2*a2^2*e1^2 + 2*a2^2*e2^2 - e1^4 - 2*e1^2*e2^2 - e2^4)^(1/2))/(a1^2 + 2*a1*e1 - a2^2 + e1^2 + e2^2))

>> res.q2

ans =

 -2*atan(((- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2)*(a1^2 + 2*a1*a2 + a2^2 - e1^2 - e2^2))^(1/2)/(- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2))
  2*atan(((- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2)*(a1^2 + 2*a1*a2 + a2^2 - e1^2 - e2^2))^(1/2)/(- a1^2 + 2*a1*a2 - a2^2 + e1^2 + e2^2))

>> res.q3

ans =

 e3 - d4 - d1
 e3 - d4 - d1

这篇关于如何在Matlab中求解符号方程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆