Passing data to fsolve

2 views (last 30 days)
Alex on 28 Feb 2012
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.
  1 Comment
Alex on 28 Feb 2012
Could someone please help me learn this? I would really appreciate it.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!