필터 지우기
필터 지우기

How to find a variable in a function that mostly match a set of data points

조회 수: 4 (최근 30일)
I have a one-variable function and a set of data points. The variable of the function is x.
If I mannuly change the variable from 1.0 to 3.0, the function's result will be closer to the data points I have as shown in the pictures below.
I was wondering what kind of MATLAB function I can use to automatically find the best value of x to match the function to the data points the most?
  댓글 수: 1
Wilmer Alexander - Conferencista en Automatización y Robótica más influyente en Iberoamérica
Thanks for asking. If possible. I remain at your disposal for any questions.
Gracias por preguntar. Si es posible. Quedo a su disposición para cualquier consulta.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 7월 30일
First, I would experiment with fminsearch, since it uses a derivative-free approach. With one parameter, this should not be difficult.
For more difficult problems, I tend to favor the ga function. I have no idea how difficult your problem is.
With either of those, the function you would use would be something like this:
fcn = @(x) norm(ydata(:) - yourFunction(x,xdata(:));
This would be easier to respond to with the function and the data.
.
  댓글 수: 13
KEDI YAN
KEDI YAN 2020년 8월 2일
Sorry about the late response.
Could you sort of exlain how you feed Rp2 to fminsearch and how you used the output from the fminsearch?
Star Strider
Star Strider 2020년 8월 3일
편집: Star Strider 2020년 8월 3일
I did something like this:
function b = Rp2_fcn(Rp2)
wo = 2*pi*13.56*10^6;
Rsource = 50; Rload = 50;
Rp1 = 0.2; Rp4 = 0.2
L1 = 106e-9; L4 = 106e-9;
C1 = 1/(wo^2*L1); C4 = 1/(wo^2*L4);
% Rp2 = 1.6; % The only variable is Rp2
Rp3 = Rp2;
L2 = 1.84e-6; L3 = 1.84e-6;
C2 = 1/(wo^2*L2); C3 = 1/(wo^2*L3);
d23_array = []; S21_array = []; i = 0;
S21_real = [0.028 0.066 0.126 0.237 0.339 0.468 0.589 0.631 0.596 0.519 0.447 ...
0.367 0.305 0.249 0.209]; % The data points
for d23=10e-3:10e-3:150e-3
i = i+1;
Z11 = Rp1+Rsource+1i*wo*L1-1i/(wo*C1);
Z22 = Rp2+1i*wo*L2-1i/(wo*C2);
Z33 = Rp3+1i*wo*L3-1i/(wo*C3);
Z44 = Rp4+Rload+1i*wo*L4-1i/(wo*C4);
M12 = MI_loop_spiral_50mm_Ben();
M34 = MI_loop_spiral_50mm_Ben();
M23 = MI_Tx_Rx_Ben(d23);
Z12 = 1i*wo*M12;
Z34 = 1i*wo*M34;
Z23 = 1i*wo*M23;
% VL/VS
Numerator = Z12*Z23*Z34*Rload;
Denominator = -Z11*Z22*Z33*Z44-Z12^2*Z34^2+Z11*Z22*Z34^2+Z11*Z44*Z23^2+Z33*Z44*Z12^2;
VL_over_Vs = Numerator./Denominator;
S21 = 2*VL_over_Vs*(Rsource/Rload)^0.5; % The function
d23_array(i) = d23;
S21_array(i) = abs(S21);
end
b = norm(S21_array - S21_real);
end
I remember making other changes in the code to make it more efficient, however I do not remember what they were.
the fminsearch call was essentially:
Rp2 = fminsearch(Rp2_fcn, rand);
EDIT — (3 Aug 2020 at 19:08)
Corrected typographical errors.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by