Simulating methods for solving Nonlinear Equation
Example:
There is a 2kw and 3kw lamps installed on both sides of one 20m wide road, which
are 5m and 6m away from the ground respectively. When these two lamps open in a
dark night , where is the darkest and brightest point on the road?
Establish coordinate system as shown in the following figure, where the road is s
meters wide, one lamp is h 1 meters high with the power P 1 , another one is h
meters high with the power P
2
2
,setting Q is one point with coordinate (x,0) on the
road between the two lamps and 0xs,
Setting the two light sources as two points, respectively the distance between Q and the two light
sources is r1 and r2 ,the angle between the road and the light from the light sources to the point Q
is
1
and 2 2 ,the illumination of the two light sources on the point Q is I
1
and I
2
P
s
in
kP
in
2s
2
I
k1 2 1,I2
1
2
r
r
1
2
Where k is the proportion coefficient decided by dimension unit , and here we suppose k=1,
2
2 2 2
2
r
h
,r
h
sx
1
1 x
2
2
2
h
h
h
h
1
1
2
2
s
i
n
,
s
i
n
1
2
2
2
2
2
r
r
h
x
1
2
h
sx
1
2
We can get the illumination of the point Q
C (x)
p1h1
(h1 x 2 )3
2
p2 h2
(h2 ( s x) 2 )3
2
Then the question is translated to search the maximum and the minimun point of C(x) .To solve
this problem we have to find the stationary point first, setting C x 0 we deduce the non
,
linear equation:
p1h1
(h1 x 2 )5
2
-
p2 h2
(h2 ( s x) 2 )5
2
0
Solution:
To solve this problem we need solve the following equation:
-
10x
(5 x )
2
2 5
18(20 x)
(6 2 (20 x) 2 )5
0,
(1)It is better to use dichotomy than Newton Tangent method, here we use dichotomy method
Setting f(x) -
10 x
(52 x 2 )5
18(20 x)
(6 2 (20 x) 2 ) 5
,draw the graph of function f (x) :
>> x=-1:.01:21;
>>z=-10*x.*(25+x.*x).^(-5/2)+18*(20-x).*(436+x.*x-40*x).^(-5/2);
>> plot(x,z)
>> xlabel('x ');ylabel('f(x)');
>> grid on
f
(
0
)
0
,
f
(
1
)
0
,
f
(
9
)
0
,
f
(
10
)
0
,
f
(
19
)
0
,
f
(
20
)
0
As is shown on the graph, according to the monotonicity of function, the equation
exactly has 3 roots.
------------------------------------------------------------------function z=bisf(x)
z=-10*x*(25+x*x)^(-5/2)+18*(20-x)*(436+x*x-40*x)^(-5/2);
------------------------------------------------------------------bisect('bisf',[0 1],5e-5,5e-6,1)
Bisection iterations for bisf.m
k
x m
f m
1
5.0000e-001
1.4614e-003
2
2.5000e-001
7.0015e-004
3
1.2500e-001
3.0662e-004
4
6.2500e-002
1.0820e-004
5
3.1250e-002
8.7845e-006
6
1.5625e-002
-4.0951e-005
7
2.3438e-002
-1.6082e-005
8
2.7344e-002
-3.6483e-006
9
2.9297e-002
2.5682e-006
10
2.8320e-002
-5.4000e-007
11
2.8809e-002
1.0141e-006
12
2.8564e-002
2.3707e-007
13
2.8442e-002
-1.5146e-007
14
2.8503e-002
4.2802e-008
15
2.8473e-002
-5.4331e-008
16
2.8488e-002
-5.7648e-009
ans =
0.0285
>> bisect('bisf',[9 10],5e-5,5e-6,1)
Bisection iterations for bisf.m
k
xm
fm
1
9.5000e+000
-6.4446e-005
2
9.2500e+000
3.5422e-005
3
9.3750e+000
-1.4671e-005
4
9.3125e+000
1.0331e-005
5
9.3438e+000
-2.1807e-006
6
9.3281e+000
4.0722e-006
7
9.3359e+000
9.4503e-007
8
9.3398e+000
-6.1802e-007
9
9.3379e+000
1.6346e-007
10
9.3389e+000
-2.2729e-007
11
9.3384e+000
-3.1919e-008
12
9.3381e+000
6.5770e-008
13
9.3383e+000
1.6926e-008
14
9.3383e+000
-7.4964e-009
15
9.3383e+000
4.7147e-009
16
9.3383e+000
-1.3908e-009
ans =
9.3383
>> bisect('bisf',[19 20],5e-5,5e-6,1)
Bisection iterations for bisf.m
k
xm
fm
1
1.9500e+001
-1.0786e-003
2
1.9750e+001
-5.1993e-004
3
1.9875e+001
-2.3407e-004
4
1.9938e+001
-9.0300e-005
5
1.9969e+001
-1.8311e-005
6
1.9984e+001
1.7698e-005
7
1.9977e+001
-3.0721e-007
8
1.9980e+001
8.6951e-006
9
1.9979e+001
4.1939e-006
10
1.9978e+001
1.9433e-006
11
1.9977e+001
8.1806e-007
12
1.9977e+001
2.5542e-007
13
1.9977e+001
-2.5896e-008
14
1.9977e+001
1.1476e-007
15
1.9977e+001
4.4433e-008
16
1.9977e+001
9.2689e-009
ans =
19.9767
3 roots:0.0285 ,9.3383,19.977
(2)Another method : generic algorithm
Setting f(x) -
10 x
(52 x 2 )5
18(20 x)
(6 2 (20 x) 2 ) 5
Translate the problem to solve the limit to min f 2 ( x) , we should find the limit point in [0,20].
0 x 20
Firstly Construct the objective function(fitness.m)
-----------------------------------------------------------------function[sol,eval]=fitness(sol,options)
x=sol(1);
eval=-10*x*(25+x*x)^(-5/2)+18*(20-x)*(436+x*x-40*x)^(-5/2);
eval=-eval*eval;
------------------------------------------------------------------Build the following programe file according to the genetic algorithm toolbox in Matlab(named ga01.m)
To find the null point in [-0.1,1]
-----------------------------------------------------------------
initPop=initializega(10,[-0.1 1],'fitness');% generate initial population,size 10
x=ga([-0.1 1],'fitness',[],initPop,[1e-6 1 1],'maxGenTerm',25,'normGeomSelect',...
[0.08],['arithXover'],[2],'nonUnifMutation',[2 25 3]) %25 Iterated Genetic
-------------------------------------------------------------->>ga01
1 -0.000000
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 -0.000000
x =
0.0285
-0.0000
Null point is approximate 0.0285 in [-0.1,1] ,only 2 iterations can get accurate result.
Build the following program file(named ga02.m)to find the null point in [9,10].
--------------------------------------------------------------initPop=initializega(10,[9 10],'fitness');%generate initial population, size 10
x=ga([9 10],'fitness',[],initPop,[1e-6 1 1],'maxGenTerm',25,'normGeomSelect',...
[0.08],['arithXover'],[2],'nonUnifMutation',[2 25 3]) %25 Iterated Genetic
------------------------------------------------------------>>ga02
1 -0.000000
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 -0.000000
x =
9.3384
-0.0000
Null point is approximate 9.3384 in [0,1],also only 2 iterations can get accurate result.
Built the following program file(named ga03.m)to find the null point in [19,20.1].
----------------------------------------------------------initPop=initializega(10,[19
20.1],'fitness');% generate initial population, size 10
x=ga([19 201],'fitness',[],initPop,[1e-6 1 1],'maxGenTerm',25,'normGeomSelect',...
[0.08],['arithXover'],[2],'nonUnifMutation',[2 25 3]) %25 Iterated Genetic
----------------------------------------------------------------->>ga03
1 -0.000000
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 -0.000000
x =
19.9767
-0.0000
We find that after 2 iterations null point is approximate 19.9767 in [19, 20].
© Copyright 2026 Paperzz