Why am I not able to find a solution using the bisection search i have implemented ?

7 visualizaciones (últimos 30 días)
Kavya
Kavya el 19 de Jul. de 2023
Respondida: Jaynik el 4 de Nov. de 2024 a las 6:24
i am trying to implement bisection search. the code is given below with all values. But i cannot find solution or the root for this. my phi, lambda values are precalculated. even if i change my phi, lambda values it still won't work. i want my bisection search to work, please guide me
% bisection search
clc;
clear;
phi=[0.0002 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i
0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i ];
lambda=[0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0602 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i ];% 1.0e-03 *lambda
power=316.2278; % in watts
mu_array=[];
a=0.0001; %mu1 % chosen arbitrary
b=10; %mu2 %chosen arbitrary
TOL=0.0001; %tolerance value
max_itr=100; %max iterations
itr=0; %iterations
c=(a+b)/2;
result3=muh_function(phi,lambda,c,power);
if result3==0
mu_array=[mu_array c];
else
while abs(result3)>TOL && itr<=max_itr
result3=muh_function(phi,lambda,c,power);
result1=muh_function(phi,lambda,a,power);
result2=muh_function(phi,lambda,b,power);
if sign(result3)==sign(result1)
a=c;
b=b;
else
b=c;
a=a;
end
c=(a+b)/2;
itr=itr+1;
end
end
function result=muh_function(phi,lambda,muh,power)
M=2;
sum=0;
for m=1:M
sum=sum+(phi(m,m)/(lambda(m,m)+muh)^2);
end
result=sum-power;
end

Respuestas (1)

Jaynik
Jaynik el 4 de Nov. de 2024 a las 6:24
Hi @Kavya,
The issue you are encountering with the bisection search implementation might be due to a few potential problems.
  • The phi and lambda matrices contain complex numbers. The bisection method is typically used for real-valued functions. If the function involves complex numbers, please ensure that it is well-defined for real inputs and returns real outputs. You might need to take the real part of the result if your function inherently deals with complex numbers.
Use real to ensure that the function returns real numbers. https://www.mathworks.com/help/matlab/ref/real.html
  • The muh_function should also return a real number that can be used to determine the sign changes necessary for the bisection method. If the function involves complex arithmetic, it might not behave as expected.
  • The interval [a, b] should be chosen such that the function values at a and b have opposite signs, indicating a root exists between them. Then adjust the loop logic to correctly update a and b based on the sign of the function at c.
Hope this helps!

Categorías

Más información sobre Wireless Communications en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by