Search code examples
matlabwolfram-mathematicaequation-solvingmathematical-expressionstranscendental-equation

Can you please tell me how to solve four transcendental equations of four unknowns?


I have tried solving 4 equations of 4 unknowns in MATLAB and Mathematica. I used vpasolve for finding the unknowns in MATLAB. Here is the MATLAB code.

Y1 = 0.02;
l1 = 0.0172;
syms Y2 Y3 l2 l3;
lambda = [0.0713  0.0688  0.0665];
b1 = 0.1170;
b3 = 0.1252;
t2_1 = (2*pi/lambda(1))*l2; 
t3_1 = (2*pi/lambda(1))*l3; 
t2_3 = (2*pi/lambda(3))*l2; 
t3_3 = (2*pi/lambda(3))*l3; 
t1_1 = (2*pi/lambda(1))*l1;
t1_3 = (2*pi/lambda(3))*l1;
eq1 = 2*Y1*tan(t1_1)+Y2*tan(t2_1)+Y3*tan(t3_1)==0;
eq2 = 2*Y1*tan(t1_3)+Y2*tan(t2_3)+Y3*tan(t3_3)==0;
eq3 = b1== (t1_1*Y1)+(t2_1*(Y2/2)*((sec(t2_1)^2)/(sec(t1_1)^2)))+(t3_1*(Y3/2)*((sec(t3_1)^2)/(sec(t1_1)^2)));
eq4 = b3== (t1_3*Y1)+(t2_3*(Y2/2)*((sec(t2_3)^2)/(sec(t1_3)^2)))+(t3_3*(Y3/2)*((sec(t3_3)^2)/(sec(t1_3)^2)));
E=[eq1 eq2 eq3 eq4];
S=vpasolve(E,[Y2,Y3,l2,l3]);

For the same equations, I wrote the below code in Mathematica.

eqns = {2*Y1*Tan[t11]+Y2*Tan[t21]+Y3*Tan[t31]==0,
2*Y1*Tan[t13]+Y2*Tan[t23]+Y3*Tan[t33]==0,  
t11*Y1 + t21*(Y2/2)*(Sec[t21]^2/Sec[t11]^2) + t31*(Y3/2)*(Sec[t31]^2/Sec[t11]^2)-b1==0, 
t13*Y1 + t23*(Y2/2)*(Sec[t23]^2/Sec[t13]^2) + t33*(Y3/2)*(Sec[t33]^2/Sec[t13]^2)-b3==0};
NMinimize[Norm[Map[First, eqns]], {Y2,Y3,l2,l3}]

But both are giving me different solutions and those are not the required solutions. I suppose I should use some other function for solving the equations. Can anyone help me finding out how to solve these equations? Your help is highly appreciated. Thank you.

EDIT

If I use the below code for finding the roots, I'm able to find the solutions but I just want positive roots. I tried the code which you have mentioned for getting positive roots but its not working for this and I don't know why. Can you please check this once?

    Y1=0.0125;l1=0.010563;lambda={0.0426,0.0401,0.0403,0.0423,0.0413}; b1 = 0.0804;
b3 = 0.0258;
t2_1 = (2*Pi/lambda[[1]])*l2; 
t3_1 = (2*Pi/lambda[[1]])*l3; 
t2_3 = (2*Pi/lambda[[5]])*l2; 
t3_3 = (2*Pi/lambda[[5]])*l3; 
t1_1 = (2*Pi/lambda[[1]])*l1;
t1_3 = (2*Pi/lambda[[5]])*l1;
eqns = {2*Y1*Tan[t11]+Y2*Tan[t21]+Y3*Tan[t31]==0,
2*Y1*Tan[t13]+Y2*Tan[t23]+Y3*Tan[t33]==0,  
t11*Y1 + t21*(Y2/2)*(Sec[t21]^2/Sec[t11]^2) + t31*(Y3/2)*(Sec[t31]^2/Sec[t11]^2)-b1==0, 
t13*Y1 + t23*(Y2/2)*(Sec[t23]^2/Sec[t13]^2) + t33*(Y3/2)*(Sec[t33]^2/Sec[t13]^2)-b3==0};

Solution

  • Try

    Y1=0.02;l1=0.0172;lambda={0.0713,0.0688,0.0665};b1=0.1170;b3=0.1252;
    t21=(2*Pi/lambda[[1]])*l2;t31=(2*Pi/lambda[[1]])*l3;t23=(2*Pi/lambda[[3]])*l2;
    t33=(2*Pi/lambda[[3]])*l3;t11=(2*Pi/lambda[[1]])*l1;t13=(2*Pi/lambda[[3]])*l1;
    eqns={2*Y1*Tan[t11]+Y2*Tan[t21]+Y3*Tan[t31]==0,
      2*Y1*Tan[t13]+Y2*Tan[t23]+Y3*Tan[t33]==0,
      t11*Y1+t21*(Y2/2)*(Sec[t21]^2/Sec[t11]^2)+t31*(Y3/2)*(Sec[t31]^2/Sec[t11]^2)-b1==0,
      t13*Y1+t23*(Y2/2)*(Sec[t23]^2/Sec[t13]^2)+t33*(Y3/2)*(Sec[t33]^2/Sec[t13]^2)-b3==0};
    tbl=Table[
      {y2i,y3i,l2i,l3i}=RandomReal[{0,.2},4];
      Quiet[root=Check[FindRoot[eqns,{{Y2,y2i,0,.2},{Y3,y3i,0,.2},{l2,l2i,0,.2},{l3,l3i,0,.2}}],False]];
      If[root===False,Nothing,root]
      ,{256}];
    roots=Sort[Map[{Y2,Y3,l2,l3}/.#&,tbl],Norm[#1]<Norm[#2]&]
    If[roots=={},"It found no roots in that range using those coefficients",
      Map[First,eqns]/.{Y2->roots[[1,1]],Y3->roots[[1,2]],l2->roots[[1,3]],l3->roots[[1,4]]}]
    

    That will look for roots starting at 256 different random locations greater than, but near 0. The way I have written FindRoot this time it will stop if the search is outside the range 0,.2 You can change that range if needed.

    Next your functions have many local minima that trap FindRoot. So it should discard all local minima found inside that range.

    And I have hidden the warning messages, usually not a good idea to do.

    Then it will Sort the roots to show those nearest 0 first.

    If you want it to sort to show the results nearest some given value then I can modify the Sort to show those first, I just need to know where you want the roots nearest to.

    And finally it substitutes the Y2,Y3,l2,l3 of the smallest root it found back into the four equations to demonstrate that the results are very very near zero and this is a real root instead of a local minima.

    After trying that a few times I found one root at {0.0203704,0.0225972,0.0163842,0.0181147} and that looks very close to your required values if I swap Y2 and Y3 and swap l2 and l3. Is that perhaps the root that you are looking for?

    If you need more then please tell me exactly what is needed.

    Please check ALL this VERY carefully to make certain I have made no mistakes.