在R2010b中的符号工具箱中使用solve和/或linsolve [英] Using solve and/or linsolve with the symbolic toolbox in R2010b

查看:78
本文介绍了在R2010b中的符号工具箱中使用solve和/或linsolve的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我问了一个问题

I asked a question a few days ago here and got an answer that seems like it would work- it involves using linsolve to find the solutions to a system of equations that are all modulo p, where p is a non-prime integer.

但是,当我尝试从提供的答案或linsolve帮助页面运行命令时,出现一条错误消息,提示linsolve不支持'sym'类型的参数.是否只能在R2013b中将linsolve与sym变量一起使用?我还在我学校的副本R2012b中进行了尝试.这是我尝试执行的代码(来自以上链接的答案):

However, when I try to run the commands from the provided answer, or the linsolve help page, I get an error saying linsolve doesn't support arguments of type 'sym'. Is using linsolve with sym variables only possible in R2013b? I've also tried it with my school's copy, which is R2012b. Here is the code I'm attempting to execute (from the answer at the above link):

A = [0 5 4 1;1 7 0 2;8 1 0 2;10 5 1 0];
b = [2946321;5851213;2563617;10670279];
s = mod(linsolve(sym(A),sym(b)),8)

输出为:

??? Undefined function or method linsolve' for input arguments of type 'sym'.

我也尝试为此使用函数solve,但是,即使我构造了上面的矩阵Ab表示的方程,也遇到了问题.这是我要尝试的:

I've also tried to use the function solve for this, however even if I construct the equations represented by the matrices A and b above, I'm having issues. Here's what I'm attempting:

syms x y z q;
solve(5*y + 4*z + q == 2946321, x + 7*y + 2*q == 5851213, 8*x + y + 2*q == 2563617, 10*x + 5*y + z == 10670279,x,y,z,q)

输出为:

??? Error using ==> char
Conversion to char from logical is not possible.

Error in ==> solve>getEqns at 169
vc = char(v);

Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});

我使用solve是错误的吗?我应该只是尝试在R2013b中执行我的代码以将linsolve与符号数据类型一起使用吗?

Am I using solve wrong? Should I just try to execute my code in R2013b to use linsolve with symbolic data types?

推荐答案

这些年来,符号数学工具箱数学工具箱发生了很大的变化(更好).您可能没有 sym/linsolve ,但这行得通吗?:

The Symbolic Math toolbox math toolbox has changed a lot (for the better) over the years. You might not have sym/linsolve, but does this work?:

s = mod(sym(A)\sym(b),8)

基本上可以做同样的事情. sym/linsolve只是做了一些额外的输入检查和排名计算,以反映linsolve的功能.

That will basically do the same thing. sym/linsolve just does some extra input checking and and rank calculation to mirror the capabilities of linsolve.

对于当前版本,您正在正确使用 solve ,但是看起来R2010b可能无法理解==运算符( sym/eq )在这种情况下.您可以使用旧的字符串格式来指定方程式:

You're using solve correctly for current versions, but it looks like R2010b may not understand the == operator (sym/eq) in this context. You can use the old string format to specify your equations:

eqs = {'5*y + 4*z + q = 2946321',...
       'x + 7*y + 2*q = 5851213',...
       '8*x + y + 2*q = 2563617',...
       '10*x + 5*y + z = 10670279'};
vars = {'x','y','z','q'};
[x,y,z,q] = solve(eqs{:},vars{:})

这篇关于在R2010b中的符号工具箱中使用solve和/或linsolve的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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