How to implement otimization on function that depends on other functions

1 view (last 30 days)
I am trying to implement this equations, but cant figure out how, im thinking of using anonymous functions and fminsearch() to get the estimation of my paramater (equation 30), but not sure how i would actually do it.
As you can see, to implement equation 30 I need all of the other three eqs.
"p" is the only unkown variable in my program.
Im not sure how to implement equation 24 and 30, due to those sums and this " nesting of equations". Any ideas?
This is the code that i have right now ( i have a lot more code, relating to other coefficents present in the above mentioned equations, they are all stored in matrixes, i index refers to k):
bdpfunH = ...
@(p_,n,i) eta * sqrt(G_R)* f_n(n,2) / (4*pi*norm(p_- pk(i))) * exp(-j*2*pi*f_n(n,1)/3e8*norm(p_- pk(i)));
gdpfunH = ...
@(n,i) xi_k * (sqrt(G_T*G_R*TX_pwr_sub) * f_n(n,2))/(4*pi*norm(ptx-pk(i))) * exp(-j*2*pi*f_n(n,1)/3e8*normtxk(ptx-pk(i)) + j*2*pi*f_n(n,1)*t_0 + j*phi_0);
hdpfunH = ...
@(gdpfunH,bdpfunH) gdpfunH * bdpfunH;
phi_t = ...
@(hdpfunH)
p_est = ...
@(phi_t)
  7 Comments
Rafael
Rafael on 25 Sep 2022
Edited: Rafael on 25 Sep 2022
Hi again, i implemented the function and it compiles so thats good, but the value returned by fminsearch is always the initial value i give to fminsearch, im not sure why is that, do you think i messed something up coding my function is is there another reason to fminsearch do that?
In my main file:
pestimation = zeros(N,3);
x0 = [10 10 10];
for n = 1:N
p_ = fminsearch(@(p_)functionslibv3.objective(p_,n,K,T,y,gdp,G_R,f_n,p_k,BETAt_k,sig2,phi_0),x0);
pestimation(n,:) = p_(1,:);
end
In my function file:
function phat = objective(p_,n,K,T,y,gdp,G_R,f_n,p_k,BETAt_k,sig2,phi0) %in main, call this function n times.
eta = 1;
bnkdp = zeros(1,K);
gnkdp = zeros(1,K);
hnkdp = zeros(1,K);
phi_t = zeros(T,1);
for i = 1:K
bnkdp(1,i) = eta * sqrt(G_R)* f_n(n,2) / (4*pi*norm(p_- p_k(i,:))) * exp(-1i*2*pi*f_n(n,1)/3e8*norm(p_- p_k(i,:)));
end
for i = i:K
gnkdp(1,i) = gdp(n,i);
end
for i = 1:K
hnkdp(1,i) = gnkdp(1,i) * bnkdp(1,i);
end
for t = 1:T
sumbh = 0;
for i = 1:K
sumbh = sumbh + BETAt_k(t,i) * hnkdp(1,i);
end
phi_t(t) = angle(sumbh);
end
sump = 0;
for t= 1:T
sump = sump + abs(y(n,t)^2)/sig2^2 * sin(angle(y(n,t)) - phi_t(t) - phi0)^2;
end
phat = sump;
end
Do you think the sintax is correct? Im sorry for asking this many questions, its the first time using matlab.
EDIT : actually i messed up one for loop... thank you so much for your help!!!
Torsten
Torsten on 25 Sep 2022
Edited: Torsten on 25 Sep 2022
If the phat that you compute in "objective" is a real scalar value, you are on the right track.
Did you check what "objective" computes for phat ?

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!