fsolve with symbolics
显示 更早的评论
Hey all, I've been working on some code, and I have two questions:
1) If I'm using fsolve, and one of my guesses is zero, will matlab still use it as a guess?
2) My equations are really complicated, so I've created simplifications for them. The equations I put into fsolve are made up of variables that are defined in terms of other variables, and those other variables contain the values that fsolve is trying to solve. Unfortunately, when I run the code, Matlab doesn't recognize the undefined variables in the other terms, and "errors". Assigning these values as symbolics creates an error in fsolve. What should I do? Example below, where x, y, and z are the valued I want to solve for:
y_1 = 309;
n0_1 = 1;
%n1_1 = 1.580086;
n1_1 = x;
%k1_1 = 0;
k1_1 = y;
n2_1 = 5.07;
k2_1 = 3.62;
%d1_1 = 25;
d1_1 = z;
R_1 = .4335;
g1_1 = (n0_1.^2 - n1_1.^2 - k1_1.^2)./((n1_1 + n2_1).^2 + k1_1.^2);
g2_1 = (n1_1.^2 - n2_1.^2 + k1_1.^2 - k2_1.^2)./((n1_1 + n2_1).^2 + (k1_1 + k2_1).^2);
h1_1 = (2.*n0_1.*k1_1)./((n0_1 + n1_1).^2 + k1_1.^2);
h2_1 = (2.*(n1_1.*k2_1 - n2_1.*k1_1))./((n1_1 + n2_1).^2 + (k1_1 + k2_1).^2);
a_1 = (2.*pi().*k1_1.*d1_1)./y_1;
A_1 = 2.*(g1_1.*g2_1 + h1_1.*h2_1);
B_1 = 2.*(g1_1.*h2_1 - g2_1.*h1_1);
C_1 = 2.*(g1_1.*g2_1 - h1_1.*h2_1);
D_1 = 2.*(g1_1.*h2_1 + g2_1.*h1_1);
b_1 = (2.*pi().*n1_1.*d1_1)./y_1;
g1_1.^2 + h1_1.^2).*(exp(2.*a_1)) + (g2_1.^2 + h2_1.^2).*(exp(-2.*a_1)) + A_1.*(cos(2.*b_1)) + B_1.*(sin(2.*b_1)))./((exp(2.*a_1)) + (g1_1.^2 + h1_1.^2).*(g2_1.^2 + h2_1.^2).*(exp(-2.*a_1)) + C_1.*(cos(2.*b_1)) + D_1.*(sin(2.*b_1))) - R_1
This is just for one of the equations (you can see why I want to simplify. Suggestions?
--Thanks
1 个评论
Walter Roberson
2012-2-24
Cross reference: http://www.mathworks.com/matlabcentral/answers/30184-defining-variables-for-fsolve
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!