Solve not working properly?
1 回表示 (過去 30 日間)
古いコメントを表示
Hey all, I'm running a bit of code to solve for a variable in an equation. Here are the specs:
theta = (2.*pi().*n1.*d1)./y;
a = n0.*n1 + n0.*n2 - n1.^2 - n1.*n2 + n0.*n1.*cos(theta) - n0.*n2.*cos(theta) + (n1.^2).*cos(theta) - n1.*n2.*cos(theta) + n0.*k2.*sin(theta) + n1.*k2.*sin(theta);
b = n1.*k2 - n0.*k2 + n0.*k2.*cos(theta) + n1.*k2.*cos(theta) - n0.*n1.*sin(theta) + n0.*n2.*sin(theta) - (n1.^2).*sin(theta) + n1.*n2.*sin(theta);
c = n0.*n1 + n0.*n2 + n1.^2 + n1.*n2 + n0.*n1.*cos(theta) - n0.*n2.*cos(theta) - (n1.^2).*cos(theta) + n1.*n2.*cos(theta) + n0.*k2.*sin(theta) - n1.*k2.*sin(theta);
d = n0.*k2.*cos(theta) - n1.*k2.*cos(theta) - n0.*k2 - n1.*k2 - n0.*n1.*sin(theta) + n0.*n2.*sin(theta) + (n1.^2).*sin(theta) - n1.*n2.*sin(theta);
[n1] = solve(sqrt((1./((c.^2+d.^2).^2)).*(((a.*c + b.*d).^2) + ((b.*c - a.*d).^2))) - R);
I have defined every variable as a symbolic variable. It is a pretty nasty piece of work, and when I run this, I ask for the solution, calling n1 in the command window. I get this back as a result:
(pi*d1*n1)/atan((n1*(- R^4*k2^4*n0^2 - 2*R^4*k2^2*n0^3*n2 - 2*R^4*k2^2*n0^2*n1^2 - 2*R^4*k2^2*n0^2*n2^2 - 2*R^4*k2^2*n0*n1^2*n2 - R^4*n0^4*n2^2 - 2*R^4*n0^3*n1^2*n2 - 2*R^4*n0^3*n2^3 - R^4*n0^2*n1^4 - 4*R^4*n0^2*n1^2*n2^2 - R^4*n0^2*n2^4 - 2*R^4*n0*n1^4*n2 - 2*R^4*n0*n1^2*n2^3 - R^4*n1^4*n2^2 + 2*R^2*k2^4*n0^2 + 4*R^2*k2^2*n0^2*n1^2 + 4*R^2*k2^2*n0^2*n2^2 + 2*R^2*n0^4*n2^2 + 2*R^2*n0^2*n1^4 - 8*R^2*n0^2*n1^2*n2^2 + 2*R^2*n0^2*n2^4 + 2*R^2*n1^4*n2^2 - k2^4*n0^2 + 2*k2^2*n0^3*n2 - 2*k2^2*n0^2*n1^2 - 2*k2^2*n0^2*n2^2 + 2*k2^2*n0*n1^2*n2 - n0^4*n2^2 + 2*n0^3*n1^2*n2 + 2*n0^3*n2^3 - n0^2*n1^4 - 4*n0^2*n1^2*n2^2 - n0^2*n2^4 + 2*n0*n1^4*n2 + 2*n0*n1^2*n2^3 - n1^4*n2^2)^(1/2) - k2*n1^3 + k2*n0^2*n1 + R^2*k2*n1^3 - R^2*k2*n0^2*n1)/(R^2*k2^2*n0^2 + R^2*n0^2*n2^2 + 2*R^2*n0*n1^2*n2 + R^2*n1^4 - k2^2*n0^2 - n0^2*n2^2 + 2*n0*n1^2*n2 - n1^4))
(pi*d1*n1)/atan((k2^2*n0*n1*i - k2*n0^2*n1 + k2*n1^3 + n0^2*n1*n2*i + n0*n1^3*i + n0*n1*n2^2*i + n1^3*n2*i)/(k2^2*n0^2 + n0^2*n2^2 + 2*n0*n1^2*n2 + n1^4))
and negative versions of the above as well, making 4 solutions. All of these solutions are dependent upon n1 itself. So, my question is this: Is n1 = f(n1), or did I do something wrong?
0 件のコメント
回答 (1 件)
Walter Roberson
2012 年 2 月 21 日
The variable named "y" is closer to "x" than the variable "n1" is to "x", so solve() is going to solve for "y", as you told it to.
S = solve(expr) solves the equation expr = 0 for the default variable determined by symvar.
The variables are sorted by the first letter in their names. The ordering is x y w z v u ... a X Y W Z V U ... A.
The way to solve for n1 would be to tell solve() that n1 is the variable you want to solve for. See the solve() documentation.
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!