How to use solve function

Hi
I am trying to make a manual calculation of least square errors. This procedure involves a symbolic variable "n".
Here is my code:
syms n;
f = 0;
for i=1:length(distanceVal)
estimateCoeff = (meanVal(1,1) - 10*log10((distanceVal(1,i)+2)/2));
f = (f + sqrt((estimateCoeff*n - meanVal(1,i))^2));
end
f
dMSE = diff(f,n);
result = solve(dMSE,n)
Where meanVal is the mean of my measured values, distanceVal is the distance corresponding to each meanVal and estimateCoeff is the estimated coefficient for each estimated value (estimated value = n*estimatedCoeff = n*10*log(d/d_ref))
However the output of result = solve(dMSE,n) is: "Empty sym: 0-by-1" What does that mean? I expect result for n=[2,4] ...

4 件のコメント

Torsten
Torsten 2017 年 6 月 29 日
Are you sure the "sqrt" is at the right place ?
You want to do L1-minimization and not L2-minimization ?
Best wishes
Torsten.
Tompak
Tompak 2017 年 6 月 29 日
Thanks for the answer! I did not know there were two different methods. I am not sure what I did expect adding the L2 version in the code
syms n;
f = 0;
for i=1:length(distanceVal)
estimateCoeff = (meanVal(1,1) - 10*log10((distanceVal(1,i)+2)/2))
f = (f + (estimateCoeff*n - meanVal(1,i))^2);
y = (f + sqrt((estimateCoeff*n - meanVal(1,i))^2));
end
dMSE = diff(f,n);
result = solve((dMSE==0),n)
dMSE = diff(y,n);
result = solve((dMSE==0),n)
Both ways give similar result: n = 0.9446 and n = 0.9444
However none of them are really what I expected. Do you see any flaws in my code, or do you know any other way of estimating n?
Torsten
Torsten 2017 年 6 月 29 日
You can check the result of the L2 minimization since it has an analytical solution:
n = sum_{i=1}^{N} ((a_i)*(b_i)) / sum_{i=1}^{N} ((a_i)^2)
with
N = length(distanceVal)
a_i = meanVal(1,1) - 10*log10((distanceVal(1,i)+2)/2)
b_i = meanVal(1,i)
Best wishes
Torsten.
Richard Marveldoss
Richard Marveldoss 2017 年 7 月 7 日
Could you help me in understanding your code as it doesn't seem like the typical least square errors? Can you explain more about the different variables used and maybe give a sample input dataset for the above code.

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

回答 (0 件)

カテゴリ

タグ

質問済み:

2017 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by