Solving 5 very complicated equations with 5 unknowns

Hi, I'm trying to derive a zoom lens and this equation is what i came across. Currently, I'm trying to find 5 variables with 5 equations(feq1, feq2, feq3, feq4, feq5).The equations were generated as shown below.
syms f1 f2 f3 f4 fe p2 p3;
fl = @(f1, f2, d) 1/(1/f1 + 1/f2 - d/(f1 * f2)); %focal length formula
bfl = @(f1, f2, d) (f2 * (d - f1)) / (d - (f1 + f2)); %back focal length formula
f_34 = fl(f4, f3, p3);
bfl_34 = bfl(f4, f3, p3);
f_234 = fl(f_34, f2, bfl_34+p2-p3);
bfl_234 = bfl(f_34, f2, bfl_34 + (p2-p3));
f_1234 = fl(f_234, f1, bfl_234 + (80-p2));
bfl_1234 = bfl(f_1234, fe, bfl_234 + (80 - p2));
f_1234e = fl(f_1234, fe, bfl_1234 + (125 - 80)) % The equation of the lens system
f_1234e = 
%% substituting p2 and p3 in my equation
feq1 = subs(subs(f_1234e, p2, 63.8654),p3, 44.6468) == 179.0893;
feq2 = subs(subs(f_1234e, p2, 57.8781),p3, 43.4521) == 166.8919;
feq3 = subs(subs(f_1234e, p2, 52.4784),p3, 41.9933) == 151.9181;
feq4 = subs(subs(f_1234e, p2, 49.7862),p3, 40.6357) == 143.6190;
feq5 = subs(subs(f_1234e, p2, 44.6669),p3, 36.5343) == 122.4775;
Which is very complicated.
I've aleady tried solve() and vpasolve(), but their outputs were empty.
Attempt #1:
S = vpasolve([feq1, feq2, feq3, feq4, feq5],[f1 f2 f3 f4 fe]);
Attempt #2:
S = solve([feq1, feq2, feq3, feq4, feq5]);
Please tell me if i've got something wrong or other ways to solve this hard question.
Thanks!

 Accepted Answer

syms f1 f2 f3 f4 fe p2 p3
fl = @(f1, f2, d) 1/(1/f1 + 1/f2 - d/(f1 * f2)); %focal length formula
bfl = @(f1, f2, d) (f2 * (d - f1)) / (d - (f1 + f2)); %back focal length formula
f_34 = fl(f4, f3, p3);
bfl_34 = bfl(f4, f3, p3);
f_234 = fl(f_34, f2, bfl_34+p2-p3);
bfl_234 = bfl(f_34, f2, bfl_34 + (p2-p3));
f_1234 = fl(f_234, f1, bfl_234 + (80-p2));
bfl_1234 = bfl(f_1234, fe, bfl_234 + (80 - p2));
f_1234e = fl(f_1234, fe, bfl_1234 + (125 - 80)); % The equation of the lens system
%% substituting p2 and p3 in my equation
feq1 = subs(subs(f_1234e, p2, 63.8654),p3, 44.6468) == 179.0893;
feq2 = subs(subs(f_1234e, p2, 57.8781),p3, 43.4521) == 166.8919;
feq3 = subs(subs(f_1234e, p2, 52.4784),p3, 41.9933) == 151.9181;
feq4 = subs(subs(f_1234e, p2, 49.7862),p3, 40.6357) == 143.6190;
feq5 = subs(subs(f_1234e, p2, 44.6669),p3, 36.5343) == 122.4775;
f = [feq1;feq2;feq3;feq4;feq5];
f = lhs(f)-rhs(f);
f = matlabFunction(f);
F = @(x)f(x(1),x(2),x(3),x(4),x(5));
f0 = [68;35;-14;96;186];
sol = fsolve(F,f0)
Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective.
sol = 5×1
68.5354 35.7632 -14.0363 96.2849 186.3001

More Answers (1)

ohh! I got the answer! I have the problem solving on other's pc, but when i tried it on my laptop,
it worked!
It took a long time tho.
syms f1 f2 f3 f4 fe p2 p3;
fl = @(f1, f2, d) 1/(1/f1 + 1/f2 - d/(f1 * f2)); %focal length formula
bfl = @(f1, f2, d) (f2 * (d - f1)) / (d - (f1 + f2)); %back focal length formula
f_34 = fl(f4, f3, p3);
bfl_34 = bfl(f4, f3, p3);
f_234 = fl(f_34, f2, bfl_34+p2-p3);
bfl_234 = bfl(f_34, f2, bfl_34 + (p2-p3));
f_1234 = fl(f_234, f1, bfl_234 + (80-p2));
bfl_1234 = bfl(f_1234, fe, bfl_234 + (80 - p2));
f_1234e = fl(f_1234, fe, bfl_1234 + (125 - 80)) % The equation of the lens system
%% substituting p2 and p3 in my equation
feq1 = subs(subs(f_1234e, p2, 63.8654),p3, 44.6468) == 179.0893;
feq2 = subs(subs(f_1234e, p2, 57.8781),p3, 43.4521) == 166.8919;
feq3 = subs(subs(f_1234e, p2, 52.4784),p3, 41.9933) == 151.9181;
feq4 = subs(subs(f_1234e, p2, 49.7862),p3, 40.6357) == 143.6190;
feq5 = subs(subs(f_1234e, p2, 44.6669),p3, 36.5343) == 122.4775;
%% solving
S = solve([feq1, feq2, feq3, feq4, feq5]);
S is the answer.

2 Comments

I suspect there will be many more "answers" depending on the initial guesses for the unknowns. At least "fsolve" showed this behaviour when using it for your problem.
@Torsten, thanks a lot!
However, i'm not able to figure out how to use fsolve.
Would it be possible to show me your code?

Sign in to comment.

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!