필터 지우기
필터 지우기

Solve not working properly?

조회 수: 1 (최근 30일)
Alex
Alex 2012년 2월 21일
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?

답변 (1개)

Walter Roberson
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.
  댓글 수: 2
Alex
Alex 2012년 2월 21일
I thought that was the purpose of [n1] = solve?
Alex
Alex 2012년 2월 21일
That is how I understand the documentation.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by