fsolve inputs
이전 댓글 표시
Hey all,
I'm trying to pass some equations to fsolve, but I'm getting nothing but errors. I have 3 complex equations, and to simplify input, I broke down the equations into component parts like so:
y_1 = 309;
n0_1 = 1;
n1_1 = x(1);
k1_1 = x(2);
n2_1 = 5.07;
k2_1 = 3.62;
d1_1 = x(3);
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;
b_1 = (2.*pi().*n1_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);
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 equations repeats itself two more times, with different values as constants. The problem I seem to be having is that Matlab doesn't like my definitions of the variables. I don't know how to express this information in a way that Matlab is able to understand, and despite all of the help I've had from the Mathworks community (thanks so much), I can't seem to get this to work. I've tried syms, I've troubleshot syms, I've tried setting up a seperate function file with no results, and I'm stuck at this point. How would you pass this through? I'm sure it would be easy enough to just create the entire system of equations without all of the substitution, and then pass that on to fsolve, but this is much user friendly, and I would like to learn how to make this work.
Thanks!
댓글 수: 2
Walter Roberson
2012년 2월 28일
"Matlab doesn't like my definitions of the variables" is not very specific, makes it difficult for us to help you.
Walter Roberson
2012년 2월 28일
Duplicate is at http://www.mathworks.com/matlabcentral/answers/30540-passing-data-to-fsolve
채택된 답변
추가 답변 (1개)
Walter Roberson
2012년 2월 28일
0 개 추천
Your line that starts g1_1.^2 is missing an opening '(', and has an extra ')' before the './'
댓글 수: 4
Alex
2012년 2월 28일
Walter Roberson
2012년 2월 28일
Perhaps, but it means we here cannot test the code ourselves, and as you have not indicated the specific errors you are seeing...
Alex
2012년 2월 28일
Walter Roberson
2012년 2월 28일
That still leaves the extra ')' before the './' .
When I put in the needed '(' and remove the unneeded ')', I have no problems with the code when I initialize x = rand(3,1)
Your code shown is not doing any substitution.
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!