Solving non-linear trigonometric equations with two unknowns.

We have two solve two non-linear equations as follows:
B1=1/(Z1*tan(x))
B2=1/(Z1*tan(r*x))
Here, 'B1', 'B2', and 'r' are known quantities (e.g. B1 = 0.002, B2 = 0.004 and r = 1.8)
We need to find out the value of Z1 and x.
Thanks in advance.

 採用された回答

John D'Errico
John D'Errico 2018 年 3 月 30 日
編集済み: John D'Errico 2018 年 3 月 30 日

2 投票

Too easy?
Eliminate Z1, by taking the ratio.
B1=1/(Z1*tan(x))
B2=1/(Z1*tan(r*x))
Therefore,
B2/B1 = tan(x)/tan(r*x)
The solve:
B1 = 0.002;
B2 = 0.004;
r = 1.8;
% First, plot things:
ezplot(@(x) tan(r*x)./tan(x))
grid on
H = refline(0,B2/B1);
H.Color = 'r';
So it looks like a root exists a little under 4. (These are radians of course!)
syms x
xs = vpasolve(B2/B1 == tan(x)/tan(r*x),x,4)
xs =
3.6373857978313951727197712680783
It is symmetric around zero of course, and there will be infinitely many roots, but the primary root seems to be roughly around 4. This would probably change for different values of r.
Solve for Z1 for the root.
Z1s = 1./(B1*tan(xs))
Z1s =
924.46628620202999172157648998132
I could have used fzero for this too.
As a test,
B2
B2 =
0.004
1/(Z1s*tan(r*xs))
ans =
0.004
If you wanted to do this without the graphic, that too can be accomplished, at the cost of slightly more effort. Not too much though.

4 件のコメント

Antra Saxena
Antra Saxena 2018 年 3 月 30 日
Thanks for the answer.
Antra Saxena
Antra Saxena 2018 年 3 月 30 日
Hello,
Graphical approach is very interesting, but our scenario is as follows.
We have to fabricate our design, so fabricable limits are:
Z1 should lie between 20 to 160.
x should lie between 10 to 150.
Now, there is little difference in the above equations as follows:
B1=tan(x)/(Z1)
B2=tan(r*x)/(Z1)
Also, value of r = 4.2.
So, can you please tell if its possible to get the values between defined limits.
Thanks in advance.
John D'Errico
John D'Errico 2018 年 3 月 30 日
編集済み: John D'Errico 2018 年 3 月 30 日
I would not call this a graphical approach. Merely a suggestion of how to learn if a solution exists at all.
I would also note that your equations have changed in a significant way. But the solution approach does not change that much. I'd just automate it to look for all solutions in that interval. Now we have the ratio of B2/B1 as...
% B2/B1 = tan(r*x)/tan(x)
So lets solve this.
B1 = 0.002;
B2 = 0.004;
r = 4.2;
ezplot(@(x) tan(r*x)./tan(x),[10 150])
H = refline(0,B2/B1);
set(H,'Color','r')
The larger value of r means there are literally hundreds of solutions between 10 and 150 in x.
To find them, you need to use an automatic scheme, instead of a graphical one where you can see the solution.
xmin = 10;
xmax = 150;
x0 = linspace(xmin,xmax,10001);
fun = @(x) tan(r*x)./tan(x) - B2/B1;
fsign = sign(fun(x0));
crossind = find(fsign(1:end-1).*fsign(2:end) <= 0);
xbrac = [x0(crossind);x0(crossind + 1)];
There are 338 candidate brackets for a solution.
size(xbrac)
ans =
2 338
Some of them are not truly brackets however. We can try to exclude those that are not by an extra test. If our function at the midpoint of the interval does not lie between the function values at the endpoints, then we will choose to ignore that bracket. You can get the idea of what I am saying from the first 10 brackets:
xbrac(:,1:10)
ans =
10.084 10.812 10.84 11.582 11.68 12.338 12.562 12.828 13.08 13.794
10.098 10.826 10.854 11.596 11.694 12.352 12.576 12.842 13.094 13.808
fun(xbrac(:,1:10))
ans =
19.96 -0.7077 4.249 -15.201 0.1593 -259.94 170.74 -0.10049 40.31 -0.087157
-12645 0.036114 -6.2269 78.427 -0.12048 106.98 -71.211 0.06843 -103.36 0.69965
fun(mean(xbrac(:,1:10)))
ans =
41.402 -0.43179 -36.756 -34.291 0.0096058 347.26 -271.95 -0.015843 137.83 0.23244
So brackets {1,3,4,6,7,9} will not actually contain a root. Instead, those brackets are locations where the function transitions from +inf to -inf, or -inf to +inf. How can we find them?
f1 = fun(xbrac(1,:));
f2 = fun(xbrac(2,:));
fm = fun(mean(xbrac,1));
keepbrac = ((f1 <= fm) & (f2 >= fm)) | ((f2 <= fm) & (f1 >= fm));
xbrac = xbrac(:,keepbrac);
size(xbrac)
ans =
2 124
Much better. There are now 124 possible brackets we have identified. Just throw them at fzero.
nb = size(xbrac,2);
xroot = zeros(1,nb);
fval = zeros(1,nb);
for i = 1:nb
[xroot(i),fval(i)] = fzero(fun,xbrac(:,i)');
end
xroot
xroot =
Columns 1 through 14
10.826 11.687 12.836 13.796 14.652 16.764 17.62 18.58 19.728 20.59 21.496 22.685 24.439 25.628
Columns 15 through 28
26.534 27.395 28.544 29.504 30.359 32.472 33.328 34.288 35.436 36.298 37.204 38.393 40.147 41.336
Columns 29 through 42
42.242 43.103 44.252 45.212 46.067 48.18 49.036 49.996 51.144 52.006 52.912 54.101 55.855 57.044
Columns 43 through 56
57.949 58.811 59.96 60.92 61.775 63.888 64.744 65.704 66.852 67.714 68.62 69.809 71.563 72.752
Columns 57 through 70
73.657 74.519 75.668 76.628 77.483 79.596 80.452 81.411 82.56 83.422 84.328 85.517 87.271 88.46
Columns 71 through 84
89.365 90.227 91.376 92.336 93.191 95.304 96.16 97.119 98.268 99.13 100.04 101.22 102.98 104.17
Columns 85 through 98
105.07 105.94 107.08 108.04 108.9 111.01 111.87 112.83 113.98 114.84 115.74 116.93 118.69 119.88
Columns 99 through 112
120.78 121.64 122.79 123.75 124.61 126.72 127.58 128.54 129.68 130.55 131.45 132.64 134.39 135.58
Columns 113 through 124
136.49 137.35 138.5 139.46 140.32 142.43 143.28 144.24 145.39 146.25 147.16 148.35
>> fval
fval =
Columns 1 through 14
7.816e-14 4.8406e-14 -1.199e-14 1.9096e-14 1.2879e-14 -2.0872e-14 -8.2823e-14 -3.6859e-14 -1.5543e-15 1.6298e-13 -2.4203e-14 -2.9088e-14 0 -3.3307e-15
Columns 15 through 28
-3.6859e-14 -2.5313e-14 -3.6415e-14 -3.6859e-14 3.9968e-14 1.7364e-13 -7.5273e-14 4.3965e-14 7.2387e-14 1.7542e-13 6.6169e-14 2.7534e-14 1.0747e-13 3.1086e-15
Columns 29 through 42
-2.9754e-13 -1.1413e-13 3.9524e-14 -2.1538e-14 1.3856e-13 2.0073e-13 -1.1324e-13 6.2172e-14 -6.5947e-14 1.0214e-13 -3.7748e-14 -7.9714e-14 -1.3767e-14 -8.7041e-14
Columns 43 through 56
2.7223e-13 2.4425e-14 2.176e-14 -3.1397e-13 1.4433e-13 -2.0672e-13 -1.5121e-13 -7.7049e-14 -4.3077e-14 1.1458e-13 1.3234e-13 1.4122e-13 -1.0614e-13 1.6875e-14
Columns 57 through 70
3.455e-13 1.6209e-13 -1.9984e-14 -6.0707e-13 -2.8355e-13 2.2116e-13 -1.4411e-13 -1.6942e-13 -4.9738e-14 1.2657e-13 1.4255e-13 -6.5947e-14 -2.9843e-13 7.1054e-15
Columns 71 through 84
3.3307e-13 1.6875e-13 -1.9629e-13 4.6629e-14 9.0594e-14 -1.5277e-13 4.3388e-13 6.6613e-15 -5.6399e-14 -3.1308e-14 -2.3537e-13 -2.7311e-13 2.5047e-13 -3.3307e-15
Columns 85 through 98
3.2063e-13 1.1724e-13 1.0125e-13 6.1018e-13 9.6811e-14 -1.5943e-13 4.4142e-13 -1.3278e-13 -4.885e-15 -1.9318e-14 9.4591e-14 -2.3315e-14 -3.4106e-13 5.4623e-14
Columns 99 through 112
4.7917e-13 1.239e-13 2.407e-13 -5.3846e-13 1.0347e-13 2.6912e-13 -7.8293e-13 2.0117e-13 1.9451e-13 1.1569e-12 -2.8311e-13 3.6904e-13 -1.3389e-13 -1.8319e-13
Columns 113 through 124
-6.9722e-13 -4.5475e-13 1.7319e-14 6.8612e-13 -6.9322e-13 -5.3979e-13 4.5564e-13 -9.6589e-14 3.0376e-13 1.1693e-12 4.6629e-14 -3.8192e-14
Now z1 is simple. z1 is just tan(xroot)/B1.
Z1 = tan(xroot)/B1
Z1 =
Columns 1 through 14
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 15 through 28
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 29 through 42
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 43 through 56
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 57 through 70
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 71 through 84
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 85 through 98
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 99 through 112
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01 -416.01 270.2
Columns 113 through 124
2913.1 -603.46 138.35 1408.9 -884.8 884.8 -1408.9 -138.35 603.46 -2913.1 -270.2 416.01
What are the roots of interest? You said that Z1 must lie between 20 and 160.
validind = find((Z1 >= 20) & (Z1 <= 160))
validind =
3 17 31 45 59 73 87 101 115
So there are infinitely many roots, as I suggested. All have the same value for Z1. They are effectively the same periodic root.
[xroot(validind);Z1(validind)]
ans =
12.836 28.544 44.252 59.96 75.668 91.376 107.08 122.79 138.5
138.35 138.35 138.35 138.35 138.35 138.35 138.35 138.35 138.35
diff(xroot(validind))
ans =
15.708 15.708 15.708 15.708 15.708 15.708 15.708 15.708
diff(xroot(validind))/pi
ans =
5 5 5 5 5 5 5 5
So the period is 5*pi.
Essentially, that means there is only one solution of interest. I'd call it the principal solution. It occurs at x=12.836, Z1 = 138.35.
format long g
xroot(3)
ans =
12.8363147171853
Z1(3)
ans =
138.348979092173
fun(xroot(3))
ans =
-1.19904086659517e-14
The general solution of interest to you is therefore
12.8363147171853 + n*5*pi
for integer n. As I said, you will only care about the first, i.e., principal solution.
Antra Saxena
Antra Saxena 2018 年 3 月 31 日
Thanks a lot. Its working for my design.

サインインしてコメントする。

その他の回答 (1 件)

Birdman
Birdman 2018 年 3 月 30 日

1 投票

syms Z1 x
B1 = 0.002;
B2 = 0.004;
r = 1.8;
eqns=[B1==1/(Z1*tan(x));
B2==1/(Z1*tan(r*x))];
sol=solve(eqns,[Z1,x])
Z1=double(sol.Z1)
x=double(sol.x)

6 件のコメント

Antra Saxena
Antra Saxena 2018 年 3 月 30 日
Hi Birdman,
Thanks for the answer, unfortunately it shows this error.
Snapshot is shared.
Please Comment.
Birdman
Birdman 2018 年 3 月 30 日
It worked well for me. What is your MATLAB version?
Antra Saxena
Antra Saxena 2018 年 3 月 30 日
Thanks for sharing the solution.
I am using MATLAB 2014.
Birdman
Birdman 2018 年 3 月 30 日
Try to use vpasolve instead of solve.
Antra Saxena
Antra Saxena 2018 年 3 月 30 日
Its working on 2015 version.
Thanks alot.
Antra Saxena
Antra Saxena 2018 年 3 月 30 日
We have to fabricate our design, so fabricable limits are:
Z1 should lie between 20 to 160.
x should lie between 10 to 150.
So, I guess this needs another solution.
Given answer not working for our design.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by