MATLAB程序问题解一个方程组如下syms x y z t a b c d m s; f = x+z-a;g = (2
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 20:12:56
MATLAB程序问题
解一个方程组如下
syms x y z t a b c d m s;
f = x+z-a;
g = (2^(1/2)*m*x)/2 + (2^(1/2)*m*y)/2+(2^(1/2)*m*t)/2 - (2^(1/2)*m*z)/2-b;
h = m^2*(y- t)-m^2*c;
k = (2^(1/2)*m^3*(y-x+z+t))/2-m^2*d;
[x,y,z,t] = solve(f,g,h,k);
x = simplify(x),
y = simplify(y),
z = simplify(z),
t = simplify(t)
x =
(2^(1/2)*(b + d))/(4*m) - c/2
y =
a/2 + (2^(1/2)*(b - d))/(4*m)
z =
c/2 + (2^(1/2)*(b + d))/(4*m)
t =
a/2 - (2^(1/2)*(b - d))/(4*m)
将x,z带入f方程,明显不成立,运行给的这个答案把x,y 的值和z,t的对调了.求教原因?
解一个方程组如下
syms x y z t a b c d m s;
f = x+z-a;
g = (2^(1/2)*m*x)/2 + (2^(1/2)*m*y)/2+(2^(1/2)*m*t)/2 - (2^(1/2)*m*z)/2-b;
h = m^2*(y- t)-m^2*c;
k = (2^(1/2)*m^3*(y-x+z+t))/2-m^2*d;
[x,y,z,t] = solve(f,g,h,k);
x = simplify(x),
y = simplify(y),
z = simplify(z),
t = simplify(t)
x =
(2^(1/2)*(b + d))/(4*m) - c/2
y =
a/2 + (2^(1/2)*(b - d))/(4*m)
z =
c/2 + (2^(1/2)*(b + d))/(4*m)
t =
a/2 - (2^(1/2)*(b - d))/(4*m)
将x,z带入f方程,明显不成立,运行给的这个答案把x,y 的值和z,t的对调了.求教原因?
楼上的回答存在问题.
诚然,Mathematica在符号运算方面总体上优于MATLAB,推荐使用Mathematica没问题;但楼上关于MATLAB符号运算的说法却纯粹是想当然,像这样误导人的做法以后还是应该少一些.
其实,当solve返回多个输出参数的时候,其顺序是按照字母表顺序,而不是你通过输入参数指定的变量顺序,也不是楼上所说的【按照变量出现的先后顺序】.所以不小心很容易搞错(对于当前这个例子没问题).
从solve函数的说明中摘录一段:
>> help solve
SOLVE Symbolic solution of algebraic equations.
.
Three different types of output are possible. For one equation and one
output,the resulting solution is returned,with multiple solutions to
a nonlinear equation in a symbolic vector. For several equations and
an equal number of outputs,the results are sorted in lexicographic
order and assigned to the outputs. For several equations and a single
output,a structure containing the solutions is returned.
现在应该明白怎么做了吧?调用时应该是
[t,x,y,z] = solve(f,g,h,k);
再检验一下结果看看:
f=simple(subs(f))
g=simple(subs(g))
h=simple(subs(h))
k=simple(subs(k))
f =
0
g =
0
h =
0
k =
0
比 较好的做法是返回一个输出参数,该参数为结构体,然后再获得结构体的域即可:
s=solve(.);
fns = fieldnames(s);
for i=1:length(fns)
eval([fns{i} '=s.' fns{i}]);
end
在MATLAB中同样也可以用一个命令解决:
>> s=solve('x+z-a', '(2^(1/2)*m*x)/2 + (2^(1/2)*m*y)/2+(2^(1/2)*m*t)/2 - (2^(1/2)*m*z)/2-b', 'm^2*(y- t)-m^2*c', '(2^(1/2)*m^3*(y-x+z+t))/2-m^2*d')
s =
t: [1x1 sym]
x: [1x1 sym]
y: [1x1 sym]
z: [1x1 sym]
后面用s.t、s.x之类的符号就可以引用求得的结果了.
诚然,Mathematica在符号运算方面总体上优于MATLAB,推荐使用Mathematica没问题;但楼上关于MATLAB符号运算的说法却纯粹是想当然,像这样误导人的做法以后还是应该少一些.
其实,当solve返回多个输出参数的时候,其顺序是按照字母表顺序,而不是你通过输入参数指定的变量顺序,也不是楼上所说的【按照变量出现的先后顺序】.所以不小心很容易搞错(对于当前这个例子没问题).
从solve函数的说明中摘录一段:
>> help solve
SOLVE Symbolic solution of algebraic equations.
.
Three different types of output are possible. For one equation and one
output,the resulting solution is returned,with multiple solutions to
a nonlinear equation in a symbolic vector. For several equations and
an equal number of outputs,the results are sorted in lexicographic
order and assigned to the outputs. For several equations and a single
output,a structure containing the solutions is returned.
现在应该明白怎么做了吧?调用时应该是
[t,x,y,z] = solve(f,g,h,k);
再检验一下结果看看:
f=simple(subs(f))
g=simple(subs(g))
h=simple(subs(h))
k=simple(subs(k))
f =
0
g =
0
h =
0
k =
0
比 较好的做法是返回一个输出参数,该参数为结构体,然后再获得结构体的域即可:
s=solve(.);
fns = fieldnames(s);
for i=1:length(fns)
eval([fns{i} '=s.' fns{i}]);
end
在MATLAB中同样也可以用一个命令解决:
>> s=solve('x+z-a', '(2^(1/2)*m*x)/2 + (2^(1/2)*m*y)/2+(2^(1/2)*m*t)/2 - (2^(1/2)*m*z)/2-b', 'm^2*(y- t)-m^2*c', '(2^(1/2)*m^3*(y-x+z+t))/2-m^2*d')
s =
t: [1x1 sym]
x: [1x1 sym]
y: [1x1 sym]
z: [1x1 sym]
后面用s.t、s.x之类的符号就可以引用求得的结果了.
MATLAB程序问题解一个方程组如下syms x y z t a b c d m s; f = x+z-a;g = (2
解微分方程组,a*y'''-y'-z*(b*y+c*x+d)=0 e*z'-y''*(f*x+g)=0 a,b,c,d,
matlab >> syms x y z a b cy=16.7143*x^2-46.227*x+36.3129;z=0
Z Y B S C Q D W L.C Z F Z D X Q W G Z M B.A…A~变成一句话 .
matlab函数计算syms f o s z k D t m q T x;p=f-o-(s-o)*(1-erf(0.5*
Matlab积分报错 syms x y dx dy z t;global e a c;x=a*cos(t);y=a*e*
W A N ,B G N S W S M ,Z S W X Z C J Y J D
如何用Maple软件提取多项式 poly1 := A*x*z+B*x*r+C*y*z+D*y*r+E*x+F*y+G*z
matlab 求极值已知函数G=a*x^2+b*y^2+cx*y+d*(x^4+y^2)+e3*z^4+f(x^2+y^
英语翻译A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The
英语翻译1.A B C D E F G H I J K M N O P Q R S T V W X Y Z .Is I
a b c d e f g h i j k l m n o p q r s t u v w x y z是什么...