matlab solve函数解一个方程组

syms x y z
r=sqrt(x^2+y^2+z^2)
eta=acos(z/sqrt(x^2+y^2+z^2))
sta=atan(y/x)
[x,y,z]=solve(r,eta,sta)
想用 solve函数求出x,y,z的表达式 我的程序却不对 为什么~还有solve(‘r’,’eta‘,‘sta’)跟上面什么区别 系统中单引号什么作用 谢谢请高手指教 matlab新手

你现在代码的意思是求解方程组:

sqrt(x^2+y^2+z^2) = 0
acos(z/sqrt(x^2+y^2+z^2)) = 0
atan(y/x) = 0

我想这应该不是你的本意吧,你是想求什么?

追问

我想用 r eta sta 表示 x y z 可能我本来的代码也不对 总之 已知三个表达式 想要反求 x y z

追答 syms x y z r eta sta
f1 = r^2-(x^2+y^2+z^2);
f2 = cos(eta)-z/r;
f3 = tan(sta)-y/x;
[x,y,z]=solve(f1,f2,f3,'x','y','z')
 
x =
 
  r*(-(cos(eta)^2 - 1)/(tan(sta)^2 + 1))^(1/2)
 -r*(-(cos(eta)^2 - 1)/(tan(sta)^2 + 1))^(1/2)
 
 
y =
 
  r*tan(sta)*(-(cos(eta)^2 - 1)/(tan(sta)^2 + 1))^(1/2)
 -r*tan(sta)*(-(cos(eta)^2 - 1)/(tan(sta)^2 + 1))^(1/2)
 
 
z =
 
 r*cos(eta)
 r*cos(eta)

追问

请问为什么你要处理一下这些基本公式并且 把将所由参数移到一边去 用f1 f2 f3 表示 我的那种方式不行呢

追答

solve求解的是f(x)=0的方程,举个例子,要求x^2+2x=-1,应该写成

solve('x^2+2*x+1')

 你要求r=sqrt(x^2+y^2+z^2),当然要写成r-sqrt(x^2+y^2+z^2)的形式

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答